mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
add adjustables to the list of objects to serialize when creating an invoice
This commit is contained in:
21
app/models/invoice/data_presenter/adjustable.rb
Normal file
21
app/models/invoice/data_presenter/adjustable.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
# frozen_string_literal: false
|
||||
|
||||
class Invoice
|
||||
class DataPresenter
|
||||
class Adjustable < Invoice::DataPresenter::Base
|
||||
attributes :id, :type, :currency, :included_tax_total, :additional_tax_total, :amount
|
||||
|
||||
def display_taxes(display_zero: false)
|
||||
if included_tax_total.positive?
|
||||
amount = Spree::Money.new(included_tax_total, currency: currency)
|
||||
I18n.t(:tax_amount_included, amount: amount)
|
||||
elsif additional_tax_total.positive?
|
||||
Spree::Money.new(additional_tax_total, currency: currency)
|
||||
elsif display_zero
|
||||
Spree::Money.new(0.00, currency: currency)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -7,7 +7,8 @@ class Invoice
|
||||
attributes :additional_tax_total, :adjustable_type, :amount, :currency, :included_tax_total,
|
||||
:label
|
||||
array_attribute :tax_rates, class_name: 'TaxRate'
|
||||
attributes_with_presenter :originator, class_name: :AdjustmentOriginator
|
||||
attributes_with_presenter :originator, class_name: 'AdjustmentOriginator'
|
||||
attributes_with_presenter :adjustable
|
||||
invoice_generation_attributes :additional_tax_total, :adjustable_type, :amount,
|
||||
:included_tax_total
|
||||
invoice_update_attributes :label
|
||||
|
||||
18
app/serializers/invoice/adjustable_serializer.rb
Normal file
18
app/serializers/invoice/adjustable_serializer.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
# frozen_string_literal: false
|
||||
|
||||
class Invoice
|
||||
class AdjustableSerializer < ActiveModel::Serializer
|
||||
attributes :id, :type, :currency, :included_tax_total, :additional_tax_total, :amount
|
||||
def type
|
||||
object.class.name
|
||||
end
|
||||
|
||||
[:currency, :included_tax_total, :additional_tax_total, :amount].each do |method|
|
||||
define_method method do
|
||||
return nil unless object.respond_to?(method)
|
||||
|
||||
object.public_send(method).to_f
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -5,6 +5,7 @@ class Invoice
|
||||
attributes :adjustable_type, :label, :included_tax_total, :additional_tax_total, :amount,
|
||||
:currency
|
||||
has_one :originator, serializer: Invoice::AdjustmentOriginatorSerializer
|
||||
has_one :adjustable, serializer: Invoice::AdjustableSerializer
|
||||
has_many :tax_rates, serializer: Invoice::TaxRateSerializer
|
||||
|
||||
def tax_rates
|
||||
|
||||
@@ -25,14 +25,14 @@
|
||||
= item.display_amount_with_adjustments
|
||||
|
||||
- @order.checkout_adjustments(exclude: [:line_item]).reverse_each do |adjustment|
|
||||
- taxable = adjustment#.adjustable_type == "Spree::Shipment" ? adjustment.adjustable : adjustment
|
||||
- taxable = adjustment.adjustable_type == "Spree::Shipment" ? adjustment.adjustable : adjustment
|
||||
%tr
|
||||
%td
|
||||
%strong= "#{raw(adjustment.label)}"
|
||||
%td{:align => "right"}
|
||||
1
|
||||
%td{:align => "right"}
|
||||
= adjustment.display_taxes
|
||||
= taxable.display_taxes
|
||||
%td{:align => "right"}
|
||||
= adjustment.display_amount
|
||||
%tfoot
|
||||
|
||||
Reference in New Issue
Block a user