chore: rubocop
chore: fix api test conventions chore: rubocop -A spec/ chore: more rubocop -A fix failing test rubocop fixes removes helper methods that are in my opinion dead code more rubocop fixes rubocop -a --auto-gen-config
This commit is contained in:
parent
f6fb804bbe
commit
fb2b4d8a8a
331 changed files with 4263 additions and 4507 deletions
|
|
@ -6,14 +6,14 @@ class GroupOrder < ApplicationRecord
|
|||
|
||||
belongs_to :order
|
||||
belongs_to :ordergroup, optional: true
|
||||
has_many :group_order_articles, :dependent => :destroy
|
||||
has_many :order_articles, :through => :group_order_articles
|
||||
has_many :group_order_articles, dependent: :destroy
|
||||
has_many :order_articles, through: :group_order_articles
|
||||
has_one :financial_transaction
|
||||
belongs_to :updated_by, optional: true, class_name: 'User', foreign_key: 'updated_by_user_id'
|
||||
|
||||
validates_presence_of :order_id
|
||||
validates_numericality_of :price
|
||||
validates_uniqueness_of :ordergroup_id, :scope => :order_id # order groups can only order once per order
|
||||
validates :order_id, presence: true
|
||||
validates :price, numericality: true
|
||||
validates :ordergroup_id, uniqueness: { scope: :order_id } # order groups can only order once per order
|
||||
|
||||
scope :in_open_orders, -> { joins(:order).merge(Order.open) }
|
||||
scope :in_finished_orders, -> { joins(:order).merge(Order.finished_not_closed) }
|
||||
|
|
@ -21,12 +21,12 @@ class GroupOrder < ApplicationRecord
|
|||
|
||||
scope :ordered, -> { includes(:ordergroup).order('groups.name') }
|
||||
|
||||
def self.ransackable_attributes(auth_object = nil)
|
||||
%w(id price)
|
||||
def self.ransackable_attributes(_auth_object = nil)
|
||||
%w[id price]
|
||||
end
|
||||
|
||||
def self.ransackable_associations(auth_object = nil)
|
||||
%w(order group_order_articles)
|
||||
def self.ransackable_associations(_auth_object = nil)
|
||||
%w[order group_order_articles]
|
||||
end
|
||||
|
||||
# Generate some data for the javascript methods in ordering view
|
||||
|
|
@ -37,24 +37,24 @@ class GroupOrder < ApplicationRecord
|
|||
|
||||
# load prices and other stuff....
|
||||
data[:order_articles] = {}
|
||||
order.articles_grouped_by_category.each do |article_category, order_articles|
|
||||
order.articles_grouped_by_category.each do |_article_category, order_articles|
|
||||
order_articles.each do |order_article|
|
||||
# Get the result of last time ordering, if possible
|
||||
goa = group_order_articles.detect { |goa| goa.order_article_id == order_article.id }
|
||||
|
||||
# Build hash with relevant data
|
||||
data[:order_articles][order_article.id] = {
|
||||
:price => order_article.article.fc_price,
|
||||
:unit => order_article.article.unit_quantity,
|
||||
:quantity => (goa ? goa.quantity : 0),
|
||||
:others_quantity => order_article.quantity - (goa ? goa.quantity : 0),
|
||||
:used_quantity => (goa ? goa.result(:quantity) : 0),
|
||||
:tolerance => (goa ? goa.tolerance : 0),
|
||||
:others_tolerance => order_article.tolerance - (goa ? goa.tolerance : 0),
|
||||
:used_tolerance => (goa ? goa.result(:tolerance) : 0),
|
||||
:total_price => (goa ? goa.total_price : 0),
|
||||
:missing_units => order_article.missing_units,
|
||||
:quantity_available => (order.stockit? ? order_article.article.quantity_available : 0)
|
||||
price: order_article.article.fc_price,
|
||||
unit: order_article.article.unit_quantity,
|
||||
quantity: (goa ? goa.quantity : 0),
|
||||
others_quantity: order_article.quantity - (goa ? goa.quantity : 0),
|
||||
used_quantity: (goa ? goa.result(:quantity) : 0),
|
||||
tolerance: (goa ? goa.tolerance : 0),
|
||||
others_tolerance: order_article.tolerance - (goa ? goa.tolerance : 0),
|
||||
used_tolerance: (goa ? goa.result(:tolerance) : 0),
|
||||
total_price: (goa ? goa.total_price : 0),
|
||||
missing_units: order_article.missing_units,
|
||||
quantity_available: (order.stockit? ? order_article.article.quantity_available : 0)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
@ -69,12 +69,12 @@ class GroupOrder < ApplicationRecord
|
|||
|
||||
# Get ordered quantities and update group_order_articles/_quantities...
|
||||
if group_order_articles_attributes
|
||||
quantities = group_order_articles_attributes.fetch(order_article.id.to_s, { :quantity => 0, :tolerance => 0 })
|
||||
quantities = group_order_articles_attributes.fetch(order_article.id.to_s, { quantity: 0, tolerance: 0 })
|
||||
group_order_article.update_quantities(quantities[:quantity].to_i, quantities[:tolerance].to_i)
|
||||
end
|
||||
|
||||
# Also update results for the order_article
|
||||
logger.debug "[save_group_order_articles] update order_article.results!"
|
||||
logger.debug '[save_group_order_articles] update order_article.results!'
|
||||
order_article.update_results!
|
||||
end
|
||||
|
||||
|
|
@ -83,7 +83,7 @@ class GroupOrder < ApplicationRecord
|
|||
|
||||
# Updates the "price" attribute.
|
||||
def update_price!
|
||||
total = group_order_articles.includes(:order_article => [:article, :article_price]).to_a.sum(&:total_price)
|
||||
total = group_order_articles.includes(order_article: %i[article article_price]).to_a.sum(&:total_price)
|
||||
update_attribute(:price, total)
|
||||
end
|
||||
|
||||
|
|
@ -97,7 +97,12 @@ class GroupOrder < ApplicationRecord
|
|||
end
|
||||
|
||||
def ordergroup_name
|
||||
ordergroup ? ordergroup.name : I18n.t('model.group_order.stock_ordergroup_name', :user => updated_by.try(:name) || '?')
|
||||
if ordergroup
|
||||
ordergroup.name
|
||||
else
|
||||
I18n.t('model.group_order.stock_ordergroup_name',
|
||||
user: updated_by.try(:name) || '?')
|
||||
end
|
||||
end
|
||||
|
||||
def total
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue