Merge pull request #9348 from jibees/9315-add-boolean-to-set-enterprise-phone-number-mandatory-or-not

Add boolean to specify if enterprise  number (ABN, GST, SIRET, ...) is mandatory or not to generate invoices
This commit is contained in:
Filipe
2022-06-29 19:07:55 +01:00
committed by GitHub
7 changed files with 87 additions and 3 deletions

View File

@@ -19,6 +19,7 @@ module Admin
:enable_invoices?,
:invoice_style2?,
:enable_receipt_printing?,
:enterprise_number_required_on_invoices?,
)
end
end

View File

@@ -44,6 +44,14 @@ module Spree
end
end
def print_invoice_link
if @order.distributor.can_invoice?
print_invoice_link_with_url
else
notify_about_required_enterprise_number
end
end
def ticket_links
return [] unless Spree::Config[:enable_receipt_printing?]
@@ -78,13 +86,20 @@ module Spree
confirm: t(:must_have_valid_business_number, enterprise_name: @order.distributor.name) }
end
def print_invoice_link
def print_invoice_link_with_url
{ name: t(:print_invoice),
url: spree.print_admin_order_path(@order),
icon: 'icon-print',
target: "_blank" }
end
def notify_about_required_enterprise_number
{ name: t(:print_invoice),
url: "#",
icon: 'icon-print',
confirm: t(:must_have_valid_business_number, enterprise_name: @order.distributor.name) }
end
def print_ticket_link
{ name: t(:print_ticket),
url: print_ticket_admin_order_path(@order),

View File

@@ -408,6 +408,8 @@ class Enterprise < ApplicationRecord
end
def can_invoice?
return true unless Spree::Config.enterprise_number_required_on_invoices?
abn.present?
end

View File

@@ -129,6 +129,7 @@ module Spree
preference :enable_invoices?, :boolean, default: true
preference :invoice_style2?, :boolean, default: false
preference :enable_receipt_printing?, :boolean, default: false
preference :enterprise_number_required_on_invoices?, :boolean, default: true
# Stripe payments
preference :stripe_connect_enabled, :boolean, default: false

View File

@@ -20,5 +20,10 @@
= check_box_tag 'preferences[enable_receipt_printing?]', '1', Spree::Config[:enable_receipt_printing?]
= label_tag nil, t('.enable_receipt_printing?')
.field.align-center
= hidden_field_tag 'preferences[enterprise_number_required_on_invoices?]', '0'
= check_box_tag 'preferences[enterprise_number_required_on_invoices?]', '1', Spree::Config[:enterprise_number_required_on_invoices?]
= label_tag nil, t('.enterprise_number_required_on_invoices?')
.form-buttons{"data-hook" => "buttons"}
= button t(:update), 'icon-refresh'

View File

@@ -552,6 +552,7 @@ en:
enable_invoices?: "Enable Invoices?"
invoice_style2?: "Use the alternative invoice model that includes total tax breakdown per rate and tax rate info per item (not yet suitable for countries displaying prices excluding tax)"
enable_receipt_printing?: "Show options for printing receipts using thermal printers in order dropdown?"
enterprise_number_required_on_invoices?: "Require an ABN to generate an invoice?"
stripe_connect_settings:
edit:

View File

@@ -474,12 +474,71 @@ describe '
within "#links-dropdown" do
expect(page).to have_link "Resend Confirmation",
href: spree.resend_admin_order_path(order)
expect(page).to have_link "Send Invoice", href: spree.invoice_admin_order_path(order)
expect(page).to have_link "Print Invoice", href: spree.print_admin_order_path(order)
expect(page).to have_link "Cancel Order",
href: spree.fire_admin_order_path(order, e: 'cancel')
end
end
context "Check send/print invoice links" do
context "when abn number is not mandatory to send/print invoices" do
before do
Spree::Config[:enterprise_number_required_on_invoices?] = false
end
it "should display normal links" do
visit spree.edit_admin_order_path(order)
find("#links-dropdown .ofn-drop-down").click
expect(page).to have_link "Send Invoice", href: spree.invoice_admin_order_path(order)
expect(page).to have_link "Print Invoice", href: spree.print_admin_order_path(order)
end
end
context "when abn number is mandatory to send/print invoices" do
before do
Spree::Config[:enterprise_number_required_on_invoices?] = true
end
context "and a abn numer is set on the distributor" do
before do
distributor1.update_attribute(:abn, '12345678')
end
it "should display normal links" do
visit spree.edit_admin_order_path(order)
find("#links-dropdown .ofn-drop-down").click
expect(page).to have_link "Send Invoice", href: spree.invoice_admin_order_path(order)
expect(page).to have_link "Print Invoice", href: spree.print_admin_order_path(order)
end
end
context "and a abn number is not set on the distributor" do
before do
distributor1.update_attribute(:abn, "")
end
it "should not display links but a js alert" do
visit spree.edit_admin_order_path(order)
find("#links-dropdown .ofn-drop-down").click
expect(page).to have_link "Send Invoice", href: "#"
expect(page).to have_link "Print Invoice", href: "#"
message = accept_prompt do
click_link "Print Invoice"
end
expect(message).to eq "#{distributor1.name} must have a valid ABN before invoices can be sent."
find("#links-dropdown .ofn-drop-down").click
message = accept_prompt do
click_link "Send Invoice"
end
expect(message).to eq "#{distributor1.name} must have a valid ABN before invoices can be sent."
end
end
end
end
it "cannot split the order in different stock locations" do
# There's only 1 stock location in OFN,