mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-17 00:07:24 +00:00
Include order cycle status in new order form
This commit is contained in:
@@ -2,6 +2,8 @@ angular.module("admin.orders").controller "ordersCtrl", ($scope, $compile, $attr
|
||||
$scope.$compile = $compile
|
||||
$scope.shops = shops
|
||||
$scope.orderCycles = orderCycles
|
||||
for oc in $scope.orderCycles
|
||||
oc.name_and_status = "#{oc.name} (#{oc.status})"
|
||||
|
||||
$scope.distributor_id = $attrs.ofnDistributorId
|
||||
$scope.order_cycle_id = $attrs.ofnOrderCycleId
|
||||
|
||||
@@ -26,4 +26,4 @@
|
||||
.field{"ng-show" => "distributor_id"}
|
||||
%label{for: "order_order_cycle_id"} Order Cycle
|
||||
%select.select2.fullwidth{id: "order_order_cycle_id", name: "order[order_cycle_id]", 'ng-model' => 'order_cycle_id'}
|
||||
%option{"ng-repeat" => "oc in orderCycles | filter:validOrderCycle", "ng-value" => "oc.id", "ng-selected" => "order_cycle_id == oc.id", "ng-bind" => "oc.name"}
|
||||
%option{"ng-repeat" => "oc in orderCycles | filter:validOrderCycle", "ng-value" => "oc.id", "ng-selected" => "order_cycle_id == oc.id", "ng-bind" => "oc.name_and_status"}
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
class Api::Admin::BasicOrderCycleSerializer < ActiveModel::Serializer
|
||||
attributes :id, :name, :first_order, :last_order
|
||||
include OrderCyclesHelper
|
||||
|
||||
attributes :id, :name, :status, :first_order, :last_order
|
||||
|
||||
has_many :suppliers, serializer: Api::Admin::IdNameSerializer
|
||||
has_many :distributors, serializer: Api::Admin::IdNameSerializer
|
||||
|
||||
def status
|
||||
order_cycle_status_class object
|
||||
end
|
||||
|
||||
def first_order
|
||||
object.orders_open_at.andand.strftime("%F")
|
||||
end
|
||||
|
||||
@@ -36,7 +36,7 @@ feature %q{
|
||||
# When we select a distributor, it should limit order cycle selection to those for that distributor
|
||||
page.should_not have_select2 'order_order_cycle_id'
|
||||
select @distributor.name, from: 'order_distributor_id'
|
||||
page.should have_select2 'order_order_cycle_id', options: ['', 'One']
|
||||
page.should have_select2 'order_order_cycle_id', options: ['', 'One (open)']
|
||||
select2_select @order_cycle.name, from: 'order_order_cycle_id'
|
||||
|
||||
page.should have_content 'ADD PRODUCT'
|
||||
@@ -172,8 +172,8 @@ feature %q{
|
||||
expect(page).to have_select 'order_distributor_id', with_options: [distributor1.name]
|
||||
expect(page).to_not have_select 'order_distributor_id', with_options: [distributor2.name]
|
||||
|
||||
expect(page).to have_select2 'order_order_cycle_id', with_options: [order_cycle1.name]
|
||||
expect(page).to_not have_select2 'order_order_cycle_id', with_options: [order_cycle2.name]
|
||||
expect(page).to have_select2 'order_order_cycle_id', with_options: ["#{order_cycle1.name} (open)"]
|
||||
expect(page).to_not have_select2 'order_order_cycle_id', with_options: ["#{order_cycle2.name} (open)"]
|
||||
|
||||
click_button 'Update'
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ describe "ordersCtrl", ->
|
||||
attrs = {}
|
||||
shops = []
|
||||
orderCycles = [
|
||||
{id: 10, distributors: [{id: 1, name: 'One'}]}
|
||||
{id: 20, distributors: [{id: 2, name: 'Two'}]}
|
||||
{id: 10, name: 'Ten', status: 'open', distributors: [{id: 1, name: 'One'}]}
|
||||
{id: 20, name: 'Twenty', status: 'closed', distributors: [{id: 2, name: 'Two', status: 'closed'}]}
|
||||
]
|
||||
|
||||
beforeEach ->
|
||||
@@ -15,6 +15,9 @@ describe "ordersCtrl", ->
|
||||
inject ($controller) ->
|
||||
ctrl = $controller 'ordersCtrl', {$scope: scope, $attrs: attrs, shops: shops, orderCycles: orderCycles}
|
||||
|
||||
it "initialises name_and_status", ->
|
||||
expect(scope.orderCycles[0].name_and_status).toEqual "Ten (open)"
|
||||
expect(scope.orderCycles[1].name_and_status).toEqual "Twenty (closed)"
|
||||
|
||||
describe "finding valid order cycles for a distributor", ->
|
||||
order_cycle = {id: 10, distributors: [{id: 1, name: 'One'}]}
|
||||
|
||||
Reference in New Issue
Block a user