mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Issues with updating orders are reported when saving standing orders
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
angular.module("admin.standingOrders").controller "OrderUpdateIssuesController", ($scope, OrderCycles) ->
|
||||
$scope.proxyOrders = $scope.options.proxyOrders
|
||||
|
||||
$scope.orderCycleName = (id) ->
|
||||
OrderCycles.byID[id].name
|
||||
|
||||
$scope.orderCycleCloses = (id) ->
|
||||
closes_at = moment(OrderCycles.byID[id].orders_close_at)
|
||||
text = if closes_at > moment() then t('closes') else t('closed')
|
||||
"#{text} #{closes_at.fromNow()}"
|
||||
@@ -29,6 +29,9 @@ angular.module("admin.standingOrders").factory 'StandingOrderPrototype', ($http,
|
||||
@$update().then (response) =>
|
||||
StatusMessage.display 'success', 'Saved'
|
||||
$injector.get('StandingOrders').afterUpdate(@id) if $injector.has('StandingOrders')
|
||||
orders_with_issues = @not_closed_proxy_orders.filter((po) -> po.update_issues.length > 0)
|
||||
if orders_with_issues.length > 0
|
||||
InfoDialog.open('error', null, 'admin/order_update_issues_dialog.html', { proxyOrders: orders_with_issues})
|
||||
, (response) =>
|
||||
StatusMessage.display 'failure', 'Oh no! I was unable to save your changes.'
|
||||
angular.extend(@errors, response.data.errors)
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
angular.module("admin.utils").factory 'InfoDialog', ($rootScope, $compile, $injector, $templateCache, DialogDefaults) ->
|
||||
new class InfoDialog
|
||||
open: (type, message) ->
|
||||
open: (type, message, templateUrl='admin/info_dialog.html', options={}) ->
|
||||
scope = $rootScope.$new()
|
||||
scope.message = message
|
||||
scope.dialog_class = type
|
||||
template = $compile($templateCache.get('admin/info_dialog.html'))(scope)
|
||||
scope.options = options
|
||||
template = $compile($templateCache.get(templateUrl))(scope)
|
||||
template.dialog(DialogDefaults)
|
||||
template.dialog('open')
|
||||
scope.close = ->
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
%script{ type: "text/ng-template", id: "admin/order_update_issues_dialog.html" }
|
||||
#order_update_issues_dialog
|
||||
.message.clearfix.margin-bottom-30
|
||||
.text=t("admin.standing_orders.order_update_issues_msg")
|
||||
%div{ ng: { controller: 'OrderUpdateIssuesController' } }
|
||||
%table
|
||||
%col{ style: 'width: 30%' }
|
||||
%col{ style: 'width: 30%' }
|
||||
%col{ style: 'width: 40%' }
|
||||
%thead
|
||||
%th= t('admin.standing_orders.number')
|
||||
%th= t('admin.order_cycle')
|
||||
%th= t('admin.standing_orders.issue')
|
||||
%tbody
|
||||
%tr.proxy_order{ :id => "ppo_{{proxyOrder.id}}", ng: { repeat: 'proxyOrder in options.proxyOrders' } }
|
||||
%td
|
||||
%a{ href: '{{::proxyOrder.edit_path}}', target: '_blank', ng: { bind: '::proxyOrder.number' } }
|
||||
%td
|
||||
%div{ ng: { bind: "::orderCycleName(proxyOrder.order_cycle_id)" } }
|
||||
%div{ ng: { bind: "::orderCycleCloses(proxyOrder.order_cycle_id)" } }
|
||||
%td.text-center{ ng: { bind: "proxyOrder.update_issues.join(', ')" } }
|
||||
|
||||
.action-buttons.text-center
|
||||
%button{ ng: { click: "close()" } }
|
||||
OK
|
||||
@@ -21,6 +21,6 @@
|
||||
%span.state{ ng: { class: "proxyOrder.state", bind: 'stateText(proxyOrder.state)' } }
|
||||
%td.text-center{ ng: { bind: 'proxyOrder.total | currency' } }
|
||||
%td.actions
|
||||
%a.edit-order.icon-edit.no-text{ href: '{{::proxyOrder.edit_path}}', 'ofn-with-tip' => t(:edit_order) }
|
||||
%a.edit-order.icon-edit.no-text{ href: '{{::proxyOrder.edit_path}}', target: '_blank', 'ofn-with-tip' => t(:edit_order) }
|
||||
%a.cancel-order.icon-remove.no-text{ href: 'javascript:void(0)', ng: { hide: "proxyOrder.state == 'canceled'", click: "cancelOrder(proxyOrder)" }, 'ofn-with-tip' => t(:cancel_order) }
|
||||
%a.resume-order.icon-resume.no-text{ href: 'javascript:void(0)', ng: { show: "proxyOrder.state == 'canceled'", click: "resumeOrder(proxyOrder)" }, 'ofn-with-tip' => t(:resume_order) }
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
%tr
|
||||
%th= t(:item_description)
|
||||
%th.price= t(:price)
|
||||
%th.qty= t(:qty)
|
||||
%th.quantity= t(:qty)
|
||||
%th.total
|
||||
%span= t(:total)
|
||||
%th.orders-actions.actions
|
||||
@@ -17,8 +17,8 @@
|
||||
%tr.item{ id: "sli_{{$index}}", ng: { repeat: "item in standingOrder.standing_line_items | filter:{ _destroy: '!true' }", class: { even: 'even', odd: 'odd' } } }
|
||||
%td.description {{ item.description }}
|
||||
%td.price.align-center {{ item.price_estimate | currency }}
|
||||
%td.qty
|
||||
%input.qty{ name: 'quantity', type: 'number', min: 0, ng: { model: 'item.quantity' } }
|
||||
%td.quantity
|
||||
%input{ name: 'quantity', type: 'number', min: 0, ng: { model: 'item.quantity' } }
|
||||
%td.total.align-center {{ (item.price_estimate * item.quantity) | currency }}
|
||||
%td.actions
|
||||
%a.delete-item.icon-trash.no-text{ ng: { click: 'removeStandingLineItem(item)'}, :href => "javascript:void(0)" }
|
||||
|
||||
@@ -6,4 +6,5 @@
|
||||
|
||||
%div{ ng: { app: 'admin.standingOrders', controller: 'StandingOrderController', cloak: true } }
|
||||
= render 'data'
|
||||
= render 'order_update_issues_dialog'
|
||||
= render 'form'
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
= admin_inject_column_preferences module: 'admin.standingOrders'
|
||||
= render 'data'
|
||||
= render 'order_update_issues_dialog'
|
||||
|
||||
%div{ ng: { controller: 'StandingOrdersController' } }
|
||||
= render 'filters'
|
||||
|
||||
@@ -9,4 +9,5 @@
|
||||
%div{ ng: { app: 'admin.standingOrders', controller: 'StandingOrderController', cloak: true } }
|
||||
= render 'data'
|
||||
= render 'wizard_progress'
|
||||
= render 'order_update_issues_dialog'
|
||||
= render 'form'
|
||||
|
||||
@@ -826,6 +826,7 @@ en:
|
||||
pause_failure_msg: 'Sorry, pausing failed!'
|
||||
confirm_unpause_msg: Are you sure you want to unpause this standing order?
|
||||
unpause_failure_msg: 'Sorry, unpausing failed!'
|
||||
order_update_issues_msg: Some orders could not be automatically updated, this is most likely because they have been manually edited. Please review the issues listed below and make any adjustments to individual orders if required.
|
||||
|
||||
stripe_connect_settings:
|
||||
edit:
|
||||
|
||||
@@ -246,7 +246,8 @@ feature 'Standing Orders' do
|
||||
schedule: schedule,
|
||||
payment_method: payment_method,
|
||||
shipping_method: shipping_method,
|
||||
standing_line_items: [create(:standing_line_item, variant: variant1, quantity: 2)]
|
||||
standing_line_items: [create(:standing_line_item, variant: variant1, quantity: 2)],
|
||||
with_proxy_orders: true
|
||||
) }
|
||||
|
||||
it "passes the smoke test" do
|
||||
@@ -294,6 +295,27 @@ feature 'Standing Orders' do
|
||||
expect(standing_order.reload.standing_line_items.length).to eq 1
|
||||
expect(standing_order.standing_line_items.first.variant).to eq variant2
|
||||
end
|
||||
|
||||
context "with initialised order that has been changed" do
|
||||
let(:proxy_order) { standing_order.proxy_orders.first }
|
||||
let(:order) { proxy_order.initialise_order! }
|
||||
let(:line_item) { order.line_items.first }
|
||||
|
||||
before { line_item.update_attributes(quantity: 3) }
|
||||
|
||||
it "reports issues encountered during the update" do
|
||||
visit edit_admin_standing_order_path(standing_order)
|
||||
|
||||
within "#sli_0" do
|
||||
fill_in 'quantity', with: "1"
|
||||
end
|
||||
|
||||
click_button 'Save Changes'
|
||||
expect(page).to have_content 'Saved'
|
||||
|
||||
expect(page).to have_selector "#order_update_issues_dialog .message", text: I18n.t("admin.standing_orders.order_update_issues_msg")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user