Class: Spree::UnitCancel
- Defined in:
- app/models/spree/unit_cancel.rb
Overview
This represents an inventory unit that has been canceled from an order after it has already been completed The reason specifies why it was canceled. This class should encapsulate logic related to canceling inventory after order complete
Constant Summary collapse
- SHORT_SHIP =
'Short Ship'
- DEFAULT_REASON =
'Cancel'
Instance Method Summary collapse
-
#adjust! ⇒ Object
Creates necessary cancel adjustments for the line item.
-
#compute_amount(line_item) ⇒ Object
This method is used by Adjustment#update to recalculate the cost.
Methods inherited from Base
Methods included from Core::Permalinks
#generate_permalink, #save_permalink
Instance Method Details
#adjust! ⇒ Object
Creates necessary cancel adjustments for the line item.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/models/spree/unit_cancel.rb', line 16 def adjust! raise "Adjustment is already created" if adjustment amount = compute_amount(inventory_unit.line_item) self.adjustment = inventory_unit.line_item.adjustments.create!( source: self, amount:, order: inventory_unit.order, label: "#{I18n.t('spree.cancellation')} - #{reason}", finalized: true ) inventory_unit.line_item.order.recalculate adjustment end |
#compute_amount(line_item) ⇒ Object
This method is used by Adjustment#update to recalculate the cost.
34 35 36 37 38 |
# File 'app/models/spree/unit_cancel.rb', line 34 def compute_amount(line_item) raise "Adjustable does not match line item" unless line_item == inventory_unit.line_item -weighted_line_item_amount(line_item) end |