Check for enterprise_number_required_on_invoices boolean

if true, then can edit invoice ;

if false, then print a confirm alert popup to specify that a enterprise number must be set for this enterprise
This commit is contained in:
Jean-Baptiste Bellet
2022-06-23 11:21:43 +02:00
parent 3a1fde40c5
commit bb6298d06d
2 changed files with 18 additions and 1 deletions

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