fix: Moved regional methods from controller to hooks (#16736)

This commit is contained in:
rohitwaghchaure
2019-02-20 17:13:15 +05:30
committed by Sagar Vora
parent ef3f864123
commit c18e925d61
4 changed files with 15 additions and 18 deletions

View File

@@ -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)