Run rubocop --fix-layout and remove encoding comments

This commit is contained in:
Patrick Gansterer 2021-03-01 15:27:26 +01:00
parent fa63e6e81d
commit ea2862fdef
283 changed files with 1164 additions and 1969 deletions

View file

@ -2,13 +2,12 @@
# The chronologically order of the Ordergroup - activity are stored in GroupOrderArticleQuantity
#
class GroupOrderArticle < ApplicationRecord
belongs_to :group_order
belongs_to :order_article
has_many :group_order_article_quantities, dependent: :destroy
validates_presence_of :group_order, :order_article
validates_uniqueness_of :order_article_id, :scope => :group_order_id # just once an article per group order
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
validates :quantity, :tolerance, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
@ -83,10 +82,10 @@ class GroupOrderArticle < ApplicationRecord
if (quantity > self.quantity || tolerance > self.tolerance)
logger.debug("Inserting a new GroupOrderArticleQuantity")
quantities.insert(0, GroupOrderArticleQuantity.new(
:group_order_article => self,
:quantity => (quantity > self.quantity ? quantity - self.quantity : 0),
:tolerance => (tolerance > self.tolerance ? tolerance - self.tolerance : 0)
))
:group_order_article => self,
:quantity => (quantity > self.quantity ? quantity - self.quantity : 0),
:tolerance => (tolerance > self.tolerance ? tolerance - self.tolerance : 0)
))
# Recalc totals:
self.quantity += quantities[0].quantity
self.tolerance += quantities[0].tolerance
@ -99,11 +98,11 @@ class GroupOrderArticle < ApplicationRecord
end
# Remove zero-only items.
quantities = quantities.reject { | q | q.quantity == 0 && q.tolerance == 0}
quantities = quantities.reject { |q| q.quantity == 0 && q.tolerance == 0 }
# Save
transaction do
quantities.each { | i | i.save! }
quantities.each { |i| i.save! }
self.group_order_article_quantities = quantities
save!
end
@ -169,7 +168,7 @@ class GroupOrderArticle < ApplicationRecord
end
# memoize result unless a total is given
r = {:quantity => quantity, :tolerance => tolerance, :total => quantity + tolerance}
r = { :quantity => quantity, :tolerance => tolerance, :total => quantity + tolerance }
@calculate_result = r if total.nil?
r
end