Class: SpreeAvatax::ShortShipReturnInvoice
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- SpreeAvatax::ShortShipReturnInvoice
- Defined in:
- app/models/spree_avatax/short_ship_return_invoice.rb
Constant Summary collapse
- DOC_TYPE =
'ReturnInvoice'
- DESTINATION_CODE =
"1"
- TAX_OVERRIDE_TYPE =
'TaxAmount'
- TAX_OVERRIDE_REASON =
'Short ship'
Class Method Summary collapse
-
.generate(unit_cancels:) ⇒ Object
Calls the Avatax API to generate a return invoice for an item that has been short shipped.
Class Method Details
.generate(unit_cancels:) ⇒ Object
Calls the Avatax API to generate a return invoice for an item that has been short shipped. It tells Avatax how much tax was refunded rather than asking it how much should be refunded. It is generated in the “committed” state since there is no need for a two- step commit here.
On failure it will raise.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/models/spree_avatax/short_ship_return_invoice.rb', line 24 def generate(unit_cancels:) if !SpreeAvatax::Config.enabled logger.info("Avatax disabled. Skipping ShortShipReturnInvoice.generate for unit_cancels #{unit_cancels.map(&:id)}") return end inventory_units = unit_cancels.map(&:inventory_unit) order_ids = inventory_units.map(&:order_id).uniq if order_ids.size > 1 raise "unit cancels #{unit_cancels.map(&:id)} had more than one order: #{order_ids}" end success_result = get_tax(unit_cancels: unit_cancels) create!( inventory_units: inventory_units, committed: true, doc_id: success_result[:doc_id], doc_code: success_result[:doc_code], doc_date: success_result[:doc_date], ) end |