Class: InvoiceTest::InvoicePlugin
- Inherits:
-
Killbill::Plugin::Invoice
- Object
- Killbill::Plugin::Invoice
- InvoiceTest::InvoicePlugin
- Defined in:
- lib/invoice_test/api.rb
Instance Method Summary collapse
-
#get_additional_invoice_items(new_invoice, dry_run, properties, context) ⇒ Object
This implementation is idempotent, will apply tax on old invoices if needed and automatically handle adjustments.
Instance Method Details
#get_additional_invoice_items(new_invoice, dry_run, properties, context) ⇒ Object
This implementation is idempotent, will apply tax on old invoices if needed and automatically handle adjustments
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/invoice_test/api.rb', line 7 def get_additional_invoice_items(new_invoice, dry_run, properties, context) all_invoices = @kb_apis.invoice_user_api.get_invoices_by_account(new_invoice.account_id, context) # Workaround for https://github.com/killbill/killbill/issues/265 all_invoices << new_invoice unless all_invoices.find { |inv| inv.id == new_invoice.id } existing_taxable_items = [] existing_tax_items = {} existing_adjustment_items = {} all_invoices.each do |invoice| invoice.invoice_items.each do |invoice_item| existing_taxable_items << invoice_item if is_taxable_item(invoice_item) (existing_tax_items[invoice_item.linked_item_id] ||= []) << invoice_item if is_tax_item(invoice_item) (existing_adjustment_items[invoice_item.linked_item_id] ||= []) << invoice_item if is_adjustment_item(invoice_item) end end compute_tax_for_items(new_invoice, existing_taxable_items, existing_tax_items, existing_adjustment_items) end |