StandingLineItems can be removed when creating a StandingOrder

This commit is contained in:
Rob Harrington
2016-10-20 08:12:27 +11:00
parent 1b711bcd46
commit 594bec1b37
4 changed files with 37 additions and 12 deletions

View File

@@ -21,8 +21,13 @@ angular.module("admin.standingOrders").controller "StandingOrderController", ($s
$scope.stepTitleFor = (step) -> t("admin.standing_orders.steps.#{step}")
$scope.addStandingLineItem = ->
$scope.standing_order_form.$setDirty()
StandingOrder.buildItem($scope.newItem)
$scope.removeStandingLineItem = (item) ->
$scope.standing_order_form.$setDirty()
StandingOrder.removeItem(item)
$scope.estimatedSubtotal = ->
$scope.standingOrder.standing_line_items.reduce (subtotal, item) ->
subtotal += item.price_estimate * item.quantity

View File

@@ -16,6 +16,10 @@ angular.module("admin.standingOrders").factory "StandingOrder", ($injector, $htt
, (response) =>
InfoDialog.open 'error', response.data.errors[0]
removeItem: (item) ->
index = @standingOrder.standing_line_items.indexOf(item)
@standingOrder.standing_line_items.splice(index,1)
create: ->
StatusMessage.display 'progress', 'Saving...'
delete @errors[k] for k, v of @errors

View File

@@ -21,7 +21,7 @@
%input.qty{ name: 'quantity', type: 'number', min: 0, ng: { model: 'item.quantity' } }
%td.total.align-center {{ (item.price_estimate * item.quantity) | currency }}
%td.actions
%a.delete-resource.icon_link.with-tip.icon-trash.no-text{ data: { confirm: "Are you sure?" }, :href => "javascript:void(0)" }
%a.delete-item.icon-trash.no-text{ ng: { click: 'removeStandingLineItem(item)'}, data: { confirm: "Are you sure?" }, :href => "javascript:void(0)" }
%tbody#subtotal.no-border-top{"data-hook" => "admin_order_form_subtotal"}
%tr#subtotal-row
%td{:colspan => "3"}

View File

@@ -62,11 +62,13 @@ feature 'Standing Orders' do
context 'creating a new standing order' do
let!(:customer) { create(:customer, enterprise: shop) }
let!(:product) { create(:product, supplier: shop) }
let!(:variant) { create(:variant, product: product, unit_value: '100', price: 12.00, option_values: []) }
let!(:product1) { create(:product, supplier: shop) }
let!(:product2) { create(:product, supplier: shop) }
let!(:variant1) { create(:variant, product: product1, unit_value: '100', price: 12.00, option_values: []) }
let!(:variant2) { create(:variant, product: product2, unit_value: '1000', price: 6.00, option_values: []) }
let!(:enterprise_fee) { create(:enterprise_fee, amount: 1.75) }
let!(:order_cycle) { create(:simple_order_cycle, coordinator: shop, orders_open_at: 2.days.from_now, orders_close_at: 7.days.from_now) }
let!(:outgoing_exchange) { order_cycle.exchanges.create(sender: shop, receiver: shop, variants: [variant], enterprise_fees: [enterprise_fee]) }
let!(:outgoing_exchange) { order_cycle.exchanges.create(sender: shop, receiver: shop, variants: [variant1, variant2], enterprise_fees: [enterprise_fee]) }
let!(:schedule) { create(:schedule, order_cycles: [order_cycle]) }
let!(:payment_method) { create(:payment_method, distributors: [shop]) }
let!(:shipping_method) { create(:shipping_method, distributors: [shop]) }
@@ -108,11 +110,11 @@ feature 'Standing Orders' do
expect(page).to have_content 'Please add at least one product'
# Adding a product and getting a price estimate
targetted_select2_search product.name, from: '#add_variant_id', dropdown_css: '.select2-drop'
targetted_select2_search product1.name, from: '#add_variant_id', dropdown_css: '.select2-drop'
fill_in 'add_quantity', with: 2
click_link 'Add'
within 'table#standing-line-items tr.item', match: :first do
expect(page).to have_selector 'td.description', text: "#{product.name} - #{variant.full_name}"
expect(page).to have_selector 'td.description', text: "#{product1.name} - #{variant1.full_name}"
expect(page).to have_selector 'td.price', text: "$13.75"
expect(page).to have_input 'quantity', with: "2"
expect(page).to have_selector 'td.total', text: "$27.50"
@@ -120,6 +122,20 @@ feature 'Standing Orders' do
click_button('Next')
# Deleting the existing product and adding a new product
within 'table#standing-line-items tr.item', match: :first do
accept_alert "Are you sure?" do find("a.delete-item").click end
end
targetted_select2_search product2.name, from: '#add_variant_id', dropdown_css: '.select2-drop'
fill_in 'add_quantity', with: 3
click_link 'Add'
within 'table#standing-line-items tr.item', match: :first do
expect(page).to have_selector 'td.description', text: "#{product2.name} - #{variant2.full_name}"
expect(page).to have_selector 'td.price', text: "$7.75"
expect(page).to have_input 'quantity', with: "3"
expect(page).to have_selector 'td.total', text: "$23.25"
end
expect{
click_button('Create Standing Order')
expect(page).to have_content 'Saved'
@@ -127,10 +143,10 @@ feature 'Standing Orders' do
# Prices are shown
within 'table#standing-line-items tr.item', match: :first do
expect(page).to have_selector 'td.description', text: "#{product.name} - #{variant.full_name}"
expect(page).to have_selector 'td.price', text: "$13.75"
expect(page).to have_input 'quantity', with: "2"
expect(page).to have_selector 'td.total', text: "$27.50"
expect(page).to have_selector 'td.description', text: "#{product2.name} - #{variant2.full_name}"
expect(page).to have_selector 'td.price', text: "$7.75"
expect(page).to have_input 'quantity', with: "3"
expect(page).to have_selector 'td.total', text: "$23.25"
end
# Basic properties of standing order are set
@@ -145,8 +161,8 @@ feature 'Standing Orders' do
# Standing Line Items are created
expect(standing_order.standing_line_items.count).to eq 1
standing_line_item = standing_order.standing_line_items.first
expect(standing_line_item.variant).to eq variant
expect(standing_line_item.quantity).to eq 2
expect(standing_line_item.variant).to eq variant2
expect(standing_line_item.quantity).to eq 3
end
context 'editing an existing standing order' do