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

@ -1,4 +1,3 @@
# encoding: utf-8
class Article < ApplicationRecord
include PriceCalculation
@ -66,8 +65,8 @@ class Article < ApplicationRecord
validates_numericality_of :price, :greater_than_or_equal_to => 0
validates_numericality_of :unit_quantity, :greater_than => 0
validates_numericality_of :deposit, :tax
#validates_uniqueness_of :name, :scope => [:supplier_id, :deleted_at, :type], if: Proc.new {|a| a.supplier.shared_sync_method.blank? or a.supplier.shared_sync_method == 'import' }
#validates_uniqueness_of :name, :scope => [:supplier_id, :deleted_at, :type, :unit, :unit_quantity]
# validates_uniqueness_of :name, :scope => [:supplier_id, :deleted_at, :type], if: Proc.new {|a| a.supplier.shared_sync_method.blank? or a.supplier.shared_sync_method == 'import' }
# validates_uniqueness_of :name, :scope => [:supplier_id, :deleted_at, :type, :unit, :unit_quantity]
validate :uniqueness_of_name
# Callbacks
@ -91,7 +90,7 @@ class Article < ApplicationRecord
def in_open_order
@in_open_order ||= begin
order_articles = OrderArticle.where(order_id: Order.open.collect(&:id))
order_article = order_articles.detect {|oa| oa.article_id == id }
order_article = order_articles.detect { |oa| oa.article_id == id }
order_article ? order_article.order : nil
end
end
@ -124,7 +123,7 @@ class Article < ApplicationRecord
# @param new_article [Article] New article to update self
# @option options [Boolean] :convert_units Omit or set to +true+ to keep current unit and recompute unit quantity and price.
# @return [Hash<Symbol, Object>] Attributes with new values
def unequal_attributes(new_article, options={})
def unequal_attributes(new_article, options = {})
# try to convert different units when desired
if options[:convert_units] == false
new_price, new_unit_quantity = nil, nil
@ -162,7 +161,7 @@ class Article < ApplicationRecord
# @return [Hash<Symbol, Object>] Changed attributes with new values
def self.compare_attributes(attributes)
unequal_attributes = attributes.select { |name, values| values[0] != values[1] && !(values[0].blank? && values[1].blank?) }
Hash[unequal_attributes.to_a.map {|a| [a[0], a[1].last]}]
Hash[unequal_attributes.to_a.map { |a| [a[0], a[1].last] }]
end
# to get the correspondent shared article
@ -183,7 +182,7 @@ class Article < ApplicationRecord
# try to match the size out of its name, e.g. "banana 10-12 St" => 10
new_unit_quantity = /[0-9\-\s]+(St)/.match(new_article.name).to_s.to_i
if new_unit_quantity && new_unit_quantity > 0
new_price = (new_article.price/new_unit_quantity.to_f).round(2)
new_price = (new_article.price / new_unit_quantity.to_f).round(2)
[new_price, new_unit_quantity]
else
false
@ -250,5 +249,4 @@ class Article < ApplicationRecord
errors.add :name, :taken_with_unit if matches.where(unit: unit, unit_quantity: unit_quantity).any?
end
end
end