From 99052fa3a7fdf0afd3047cb96bcd69928fca4a3c Mon Sep 17 00:00:00 2001 From: Tom Carchrae Date: Tue, 26 Mar 2019 12:14:39 -0700 Subject: [PATCH] Don't allow changes to settled orders (PR #614) --- app/models/group_order_article.rb | 9 +++++++++ .../balancing/_edit_results_by_articles.html.haml | 2 +- .../finance/balancing/_group_order_articles.html.haml | 10 ++++++---- app/views/finance/balancing/_order_article.html.haml | 4 ++-- config/locales/de.yml | 2 ++ config/locales/en.yml | 2 ++ config/locales/nl.yml | 2 ++ 7 files changed, 24 insertions(+), 7 deletions(-) diff --git a/app/models/group_order_article.rb b/app/models/group_order_article.rb index b2ef05e6..af31fef0 100644 --- a/app/models/group_order_article.rb +++ b/app/models/group_order_article.rb @@ -9,6 +9,7 @@ class GroupOrderArticle < ApplicationRecord validates_presence_of :group_order, :order_article validates_uniqueness_of :order_article_id, :scope => :group_order_id # just once an article per group order + validate :check_order_not_closed # don't allow changes to closed (aka settled) orders scope :ordered, -> { includes(:group_order => :ordergroup).order('groups.name') } @@ -195,4 +196,12 @@ class GroupOrderArticle < ApplicationRecord def result_manually_changed? result != result_computed unless result.nil? end + + private + + def check_order_not_closed + if order_article.order.closed? + errors.add(:order_article, I18n.t('model.group_order_article.order_closed')) + end + end end diff --git a/app/views/finance/balancing/_edit_results_by_articles.html.haml b/app/views/finance/balancing/_edit_results_by_articles.html.haml index 05e06071..2cdf80b9 100644 --- a/app/views/finance/balancing/_edit_results_by_articles.html.haml +++ b/app/views/finance/balancing/_edit_results_by_articles.html.haml @@ -11,7 +11,7 @@ %th= heading_helper Article, :deposit %th{:colspan => "2"} = link_to t('.add_article'), new_order_order_article_path(@order), remote: true, - class: 'btn btn-small' + class: 'btn btn-small' unless @order.closed? %tbody#result_table - for order_article in @articles = render :partial => "order_article_result", :locals => {:order_article => order_article} diff --git a/app/views/finance/balancing/_group_order_articles.html.haml b/app/views/finance/balancing/_group_order_articles.html.haml index 5ab4a4d5..500b58da 100644 --- a/app/views/finance/balancing/_group_order_articles.html.haml +++ b/app/views/finance/balancing/_group_order_articles.html.haml @@ -9,8 +9,9 @@ %acronym{:title => t('shared.articles.received_desc')}= t 'shared.articles.received' %td= t('.total') %td{:colspan => "3",:style => "width:14em"} - = link_to t('.add_group'), new_group_order_article_path(order_article_id: order_article.id), - remote: true, class: 'btn btn-mini' + - unless order_article.order.closed? + = link_to t('.add_group'), new_group_order_article_path(order_article_id: order_article.id), + remote: true, class: 'btn btn-mini' %tbody - totals = {result: 0} - for group_order_article in order_article.group_order_articles.select { |goa| goa.result > 0 } @@ -21,8 +22,9 @@ %td.center= group_order_article_edit_result(group_order_article) %td.numeric= number_to_currency(group_order_article.order_article.price.fc_price * group_order_article.result) %td.actions{:style=>"width:1em"} - = link_to t('ui.delete'), group_order_article_path(group_order_article), method: :delete, - remote: true, class: 'btn btn-mini btn-danger' + - unless order_article.order.closed? + = link_to t('ui.delete'), group_order_article_path(group_order_article), + method: :delete, remote: true, class: 'btn btn-mini btn-danger' %td - totals[:result] += group_order_article.result %tfoot diff --git a/app/views/finance/balancing/_order_article.html.haml b/app/views/finance/balancing/_order_article.html.haml index 050939f1..d8637b3e 100644 --- a/app/views/finance/balancing/_order_article.html.haml +++ b/app/views/finance/balancing/_order_article.html.haml @@ -21,7 +21,7 @@ %td= order_article.price.deposit %td = link_to t('ui.edit'), edit_order_order_article_path(order_article.order, order_article), remote: true, - class: 'btn btn-mini' + class: 'btn btn-mini' unless order_article.order.closed? %td = link_to t('ui.delete'), order_order_article_path(order_article.order, order_article), method: :delete, - remote: true, data: {confirm: t('.confirm')}, class: 'btn btn-danger btn-mini' + remote: true, data: {confirm: t('.confirm')}, class: 'btn btn-danger btn-mini' unless order_article.order.closed? diff --git a/config/locales/de.yml b/config/locales/de.yml index 151a2018..5fdda9b9 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -1444,6 +1444,8 @@ de: redirect: Weiterleitung auf [[%{title}]]... user: no_ordergroup: keine Bestellgruppe + group_order_article: + order_closed: Bestellung ist geschlossen und kann nicht geƤndert werden navigation: admin: config: Einstellungen diff --git a/config/locales/en.yml b/config/locales/en.yml index d82d5ce8..5a75bb20 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1469,6 +1469,8 @@ en: redirect: Redirect to [[%{title}]]... user: no_ordergroup: no ordergroup + group_order_article: + order_closed: Order is closed and cannot be modified navigation: admin: config: Configuration diff --git a/config/locales/nl.yml b/config/locales/nl.yml index a31f00cd..1ff059e3 100644 --- a/config/locales/nl.yml +++ b/config/locales/nl.yml @@ -1399,6 +1399,8 @@ nl: redirect: Doorverwijzing naar [[%{title}]]... user: no_ordergroup: geen huishouden + group_order_article: + order_closed: Bestelling is gesloten en kan niet worden gewijzigd navigation: admin: config: Instellingen