Updated

app/models / stage.rb

A
41 lines of codes
2 methods
8.3 complexity/method
32 churn
16.62 complexity
0 duplications
# == Schema Information # # Table name: stages # # id :bigint not null, primary key # name :string default(""), not null # position :integer # created_at :datetime not null # updated_at :datetime not null # pipeline_id :bigint not null # # Indexes # # index_stages_on_pipeline_id (pipeline_id) # # Foreign Keys # # fk_rails_... (pipeline_id => pipelines.id) # class Stage < ApplicationRecord include Stage::Decorators belongs_to :pipeline, touch: true acts_as_list scope: :pipeline has_many :deals, dependent: :destroy scope :ordered_by_pipeline_and_position, lambda { joins(:pipeline).order('pipelines.name ASC, stages.position ASC') } def total_amount_deals(filter_status_deal) return deals.sum(&:total_amount_in_cents) if filter_status_deal == 'all' deals.where(status: filter_status_deal).sum(&:total_amount_in_cents) end def total_quantity_deals(filter_status_deal) return deals.count if filter_status_deal == 'all' deals.where(status: filter_status_deal).count end end