From d794981ecfb66616cd5de799e2a80999148a30bc Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 4 Nov 2015 10:44:33 +1100 Subject: [PATCH] Add form field to set tax when creating adjustment on order. Display tax included in adjustments on order interface. --- app/models/spree/adjustment_decorator.rb | 4 ++++ .../add_tax_to_body.html.haml.deface | 9 +++++++++ .../add_tax_to_head.html.haml.deface | 8 ++++++++ .../_form/add_tax_rate.html.haml.deface | 6 ++++++ .../spree/admin/adjustments/_new_form.html.haml | 17 +++++++++++++++++ config/locales/en.yml | 1 + 6 files changed, 45 insertions(+) create mode 100644 app/overrides/spree/admin/adjustments/_adjustments_table/add_tax_to_body.html.haml.deface create mode 100644 app/overrides/spree/admin/adjustments/_adjustments_table/add_tax_to_head.html.haml.deface create mode 100644 app/overrides/spree/admin/adjustments/_form/add_tax_rate.html.haml.deface create mode 100644 app/views/spree/admin/adjustments/_new_form.html.haml diff --git a/app/models/spree/adjustment_decorator.rb b/app/models/spree/adjustment_decorator.rb index 5f3847e218..b179fe3036 100644 --- a/app/models/spree/adjustment_decorator.rb +++ b/app/models/spree/adjustment_decorator.rb @@ -24,6 +24,10 @@ module Spree update_attributes! included_tax: tax.round(2) end + def display_included_tax + Spree::Money.new(included_tax, { :currency => currency }) + end + def has_tax? included_tax > 0 end diff --git a/app/overrides/spree/admin/adjustments/_adjustments_table/add_tax_to_body.html.haml.deface b/app/overrides/spree/admin/adjustments/_adjustments_table/add_tax_to_body.html.haml.deface new file mode 100644 index 0000000000..398d99eaf6 --- /dev/null +++ b/app/overrides/spree/admin/adjustments/_adjustments_table/add_tax_to_body.html.haml.deface @@ -0,0 +1,9 @@ +/ replace_contents "[data-hook='adjustment_row']" + +%td.align-center.created_at= pretty_time(adjustment.created_at) +%td.align-center.label= adjustment.label +%td.align-center.amount= adjustment.display_amount.to_html +%td.align-center.included-tax= adjustment.display_included_tax.to_html +%td.actions + = link_to_edit adjustment, no_text: true + = link_to_delete adjustment, no_text: true \ No newline at end of file diff --git a/app/overrides/spree/admin/adjustments/_adjustments_table/add_tax_to_head.html.haml.deface b/app/overrides/spree/admin/adjustments/_adjustments_table/add_tax_to_head.html.haml.deface new file mode 100644 index 0000000000..6da264865a --- /dev/null +++ b/app/overrides/spree/admin/adjustments/_adjustments_table/add_tax_to_head.html.haml.deface @@ -0,0 +1,8 @@ +/ replace_contents "[data-hook='adjustmment_head']" + +%tr + %th= "#{t('spree.date')}/#{t('spree.time')}" + %th= t(:description) + %th= t(:amount) + %th= t(:included_tax) + %th.actions diff --git a/app/overrides/spree/admin/adjustments/_form/add_tax_rate.html.haml.deface b/app/overrides/spree/admin/adjustments/_form/add_tax_rate.html.haml.deface new file mode 100644 index 0000000000..a37acc1030 --- /dev/null +++ b/app/overrides/spree/admin/adjustments/_form/add_tax_rate.html.haml.deface @@ -0,0 +1,6 @@ +/ replace_contents "[data-hook='admin_adjustment_form_fields']" + +- if @adjustment.new_record? + = render 'new_form', f: f +- else + = render 'edit_form', f: f diff --git a/app/views/spree/admin/adjustments/_new_form.html.haml b/app/views/spree/admin/adjustments/_new_form.html.haml new file mode 100644 index 0000000000..a3981fca8a --- /dev/null +++ b/app/views/spree/admin/adjustments/_new_form.html.haml @@ -0,0 +1,17 @@ +.row + .alpha.three.columns + = f.field_container :amount do + = f.label :amount, raw(t(:amount) + content_tag(:span, " *", :class => "required")) + = text_field :adjustment, :amount, :class => 'fullwidth' + = f.error_message_on :amount + .omega.three.columns + = f.field_container :tax_rate_id do + = f.label :tax_rate_id, t(:tax) + = select_tag :tax_rate_id, options_from_collection_for_select(Spree::TaxRate.all, :id, :name), prompt: t(:none), class: 'fullwidth' + = f.error_message_on :tax_rate_id +.row + .alpha.omega.twelve.columns + = f.field_container :label do + = f.label :label, raw(t(:description) + content_tag(:span, " *", :class => "required")) + = text_field :adjustment, :label, :class => 'fullwidth' + = f.error_message_on :label diff --git a/config/locales/en.yml b/config/locales/en.yml index e6ede20009..600b21321f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -38,3 +38,4 @@ en: footer_about_url: "About URL" footer_tos_url: "Terms of Service URL" invoice: "Invoice" + included_tax: "Included tax" \ No newline at end of file