From c18e925d6168dbdf74a40651aa596b296997f37e Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Wed, 20 Feb 2019 17:13:15 +0530 Subject: [PATCH] fix: Moved regional methods from controller to hooks (#16736) --- .../doctype/sales_invoice/sales_invoice.py | 5 ----- erpnext/controllers/accounts_controller.py | 8 -------- erpnext/hooks.py | 5 ++--- erpnext/regional/italy/utils.py | 15 +++++++++++++-- 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index abd201f5c70..895ca07da2f 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -24,7 +24,6 @@ from erpnext.accounts.general_ledger import get_round_off_account_and_cost_cente from erpnext.accounts.doctype.loyalty_program.loyalty_program import \ get_loyalty_program_details_with_points, get_loyalty_details, validate_loyalty_points from erpnext.accounts.deferred_revenue import validate_service_stop_date -from erpnext.controllers.accounts_controller import on_submit_regional, on_cancel_regional from erpnext.healthcare.utils import manage_invoice_submit_cancel @@ -199,8 +198,6 @@ class SalesInvoice(SellingController): if "Healthcare" in active_domains: manage_invoice_submit_cancel(self, "on_submit") - on_submit_regional(self) - def validate_pos_paid_amount(self): if len(self.payments) == 0 and self.is_pos: frappe.throw(_("At least one mode of payment is required for POS invoice.")) @@ -256,8 +253,6 @@ class SalesInvoice(SellingController): if "Healthcare" in active_domains: manage_invoice_submit_cancel(self, "on_cancel") - on_cancel_regional(self) - def update_status_updater_args(self): if cint(self.update_stock): self.status_updater.extend([{ diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 5a765aa273e..34bbe7b9994 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -1138,11 +1138,3 @@ def update_child_qty_rate(parent_doctype, trans_items, parent_doctype_name): @erpnext.allow_regional def validate_regional(doc): pass - -@erpnext.allow_regional -def on_submit_regional(doc): - pass - -@erpnext.allow_regional -def on_cancel_regional(doc): - pass diff --git a/erpnext/hooks.py b/erpnext/hooks.py index e98ca4b5976..ccdd412c181 100644 --- a/erpnext/hooks.py +++ b/erpnext/hooks.py @@ -202,7 +202,8 @@ doc_events = { "validate": "erpnext.portal.doctype.products_settings.products_settings.home_page_is_products" }, "Sales Invoice": { - "on_submit": "erpnext.regional.france.utils.create_transaction_log", + "on_submit": ["erpnext.regional.france.utils.create_transaction_log", "erpnext.regional.italy.utils.sales_invoice_on_submit"], + "on_cancel": "erpnext.regional.italy.utils.sales_invoice_on_cancel", "on_trash": "erpnext.regional.check_deletion_permission" }, "Payment Entry": { @@ -305,7 +306,5 @@ regional_overrides = { 'Italy': { 'erpnext.controllers.taxes_and_totals.update_itemised_tax_data': 'erpnext.regional.italy.utils.update_itemised_tax_data', 'erpnext.controllers.accounts_controller.validate_regional': 'erpnext.regional.italy.utils.sales_invoice_validate', - 'erpnext.controllers.accounts_controller.on_submit_regional': 'erpnext.regional.italy.utils.sales_invoice_on_submit', - 'erpnext.controllers.accounts_controller.on_cancel_regional': 'erpnext.regional.italy.utils.sales_invoice_on_cancel' } } diff --git a/erpnext/regional/italy/utils.py b/erpnext/regional/italy/utils.py index 7e0386a93b6..c86ad78cbc9 100644 --- a/erpnext/regional/italy/utils.py +++ b/erpnext/regional/italy/utils.py @@ -222,8 +222,12 @@ def sales_invoice_validate(doc): #Ensure payment details are valid for e-invoice. -def sales_invoice_on_submit(doc): +def sales_invoice_on_submit(doc, method): #Validate payment details + if get_company_country(doc.company) not in ['Italy', + 'Italia', 'Italian Republic', 'Repubblica Italiana']: + return + if not len(doc.payment_schedule): frappe.throw(_("Please set the Payment Schedule"), title=_("E-Invoicing Information Missing")) else: @@ -247,10 +251,17 @@ def prepare_and_attach_invoice(doc): save_file(xml_filename, invoice_xml, dt=doc.doctype, dn=doc.name, is_private=True) #Delete e-invoice attachment on cancel. -def sales_invoice_on_cancel(doc): +def sales_invoice_on_cancel(doc, method): + if get_company_country(doc.company) not in ['Italy', + 'Italia', 'Italian Republic', 'Repubblica Italiana']: + return + for attachment in get_e_invoice_attachments(doc): remove_file(attachment.name, attached_to_doctype=doc.doctype, attached_to_name=doc.name) +def get_company_country(company): + return frappe.get_cached_value('Company', company, 'country') + def get_e_invoice_attachments(invoice): out = [] attachments = get_attachments(invoice.doctype, invoice.name)