Module: Vpago::LineItemDecorator
- Defined in:
- app/models/vpago/line_item_decorator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #commission_amount ⇒ Object
- #commission_rate ⇒ Object
- #latest_private_metadata ⇒ Object
-
#pre_commission_amount ⇒ Object
amount expected to receive by vendor.
-
#required_payway_payout? ⇒ Boolean
considred required when there are any required profiles.
-
#update_total_metadata ⇒ Object
generate metadata for financial reports.
- #vendor_adjustments_total_excluding_tax ⇒ Object
- #vendor_pre_tax_amount ⇒ Object
- #vendor_tax_total ⇒ Object
Class Method Details
.prepended(base) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'app/models/vpago/line_item_decorator.rb', line 3 def self.prepended(base) base.include ::Vpago::Payoutable base.has_many :payout_profiles, class_name: 'Spree::PayoutProfile', through: :product base.has_many :active_payout_profiles, class_name: 'Spree::PayoutProfile', through: :product base.has_many :active_payway_payout_profiles, class_name: 'Spree::PayoutProfile', through: :product base.has_many :required_active_payout_profiles, class_name: 'Spree::PayoutProfile', through: :product base.has_one :vendor, through: :variant base.has_many :vendor_payment_methods, class_name: 'Spree::PaymentMethod', through: :variant end |
Instance Method Details
#commission_amount ⇒ Object
26 27 28 |
# File 'app/models/vpago/line_item_decorator.rb', line 26 def commission_amount vendor_pre_tax_amount * commission_rate / 100.0 end |
#commission_rate ⇒ Object
21 22 23 24 |
# File 'app/models/vpago/line_item_decorator.rb', line 21 def commission_rate product_commission_rate = product.respond_to?(:commission_rate) ? product.commission_rate : nil product_commission_rate || vendor&.commission_rate || 0 end |
#latest_private_metadata ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/models/vpago/line_item_decorator.rb', line 54 def # Preserve existing metadata and merge with new financial data = ( || {}).dup [:subtotal] = subtotal.to_f [:commission_rate] = commission_rate.to_f [:commission_amount] = commission_amount.to_f [:vendor_pre_tax_amount] = vendor_pre_tax_amount.to_f [:pre_commission_amount] = pre_commission_amount.to_f [:vendor_tax_total] = vendor_tax_total.to_f [:vendor_adjustments_total_excluding_tax] = vendor_adjustments_total_excluding_tax.to_f end |
#pre_commission_amount ⇒ Object
amount expected to receive by vendor
31 32 33 |
# File 'app/models/vpago/line_item_decorator.rb', line 31 def pre_commission_amount vendor_pre_tax_amount - commission_amount + vendor_tax_total end |
#required_payway_payout? ⇒ Boolean
considred required when there are any required profiles.
17 18 19 |
# File 'app/models/vpago/line_item_decorator.rb', line 17 def required_payway_payout? required_active_payout_profiles.payway.exists? end |
#update_total_metadata ⇒ Object
generate metadata for financial reports.
70 71 72 |
# File 'app/models/vpago/line_item_decorator.rb', line 70 def update_column(:private_metadata, ) end |
#vendor_adjustments_total_excluding_tax ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'app/models/vpago/line_item_decorator.rb', line 43 def vendor_adjustments_total_excluding_tax vendor_adjustment = adjustments.non_tax.handle_by_vendor.total order_vendor_adjustment = if order.line_items_count.positive? order.adjustments.non_tax.handle_by_vendor.total / order.line_items_count else 0 end order_vendor_adjustment + vendor_adjustment end |
#vendor_pre_tax_amount ⇒ Object
35 36 37 |
# File 'app/models/vpago/line_item_decorator.rb', line 35 def vendor_pre_tax_amount subtotal + vendor_adjustments_total_excluding_tax end |
#vendor_tax_total ⇒ Object
39 40 41 |
# File 'app/models/vpago/line_item_decorator.rb', line 39 def vendor_tax_total adjustments.tax.handle_by_vendor.total end |