From 032246dc2bf772102a876cedd814b7616efd3b34 Mon Sep 17 00:00:00 2001 From: Saqib Ansari Date: Fri, 9 Apr 2021 12:08:24 +0530 Subject: [PATCH] feat(italy): add document type field for e-invoicing --- erpnext/patches.txt | 1 + ...document_type_field_for_italy_einvoicing.py | 18 ++++++++++++++++++ erpnext/regional/italy/setup.py | 3 +++ erpnext/regional/italy/utils.py | 11 ++++++----- 4 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 erpnext/patches/v12_0/add_document_type_field_for_italy_einvoicing.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 16863142bc..010963a868 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -764,3 +764,4 @@ erpnext.patches.v13_0.setup_uae_vat_fields execute:frappe.db.set_value('System Settings', None, 'app_name', 'ERPNext') erpnext.patches.v13_0.rename_discharge_date_in_ip_record erpnext.patches.v12_0.purchase_receipt_status +erpnext.patches.v12_0.add_document_type_field_for_italy_einvoicing \ No newline at end of file diff --git a/erpnext/patches/v12_0/add_document_type_field_for_italy_einvoicing.py b/erpnext/patches/v12_0/add_document_type_field_for_italy_einvoicing.py new file mode 100644 index 0000000000..4d649dd0f0 --- /dev/null +++ b/erpnext/patches/v12_0/add_document_type_field_for_italy_einvoicing.py @@ -0,0 +1,18 @@ +from __future__ import unicode_literals +from frappe.custom.doctype.custom_field.custom_field import create_custom_fields +import frappe + +def execute(): + company = frappe.get_all('Company', filters = {'country': 'Italy'}) + if not company: + return + + custom_fields = { + 'Sales Invoice': [ + dict(fieldname='type_of_document', label='Type of Document', + fieldtype='Select', insert_after='customer_fiscal_code', + options='\nTD01\nTD02\nTD03\nTD04\nTD05\nTD06\nTD16\nTD17\nTD18\nTD19\nTD20\nTD21\nTD22\nTD23\nTD24\nTD25\nTD26\nTD27'), + ] + } + + create_custom_fields(custom_fields, update=True) \ No newline at end of file diff --git a/erpnext/regional/italy/setup.py b/erpnext/regional/italy/setup.py index a1f5bb9836..7db2f6b0f8 100644 --- a/erpnext/regional/italy/setup.py +++ b/erpnext/regional/italy/setup.py @@ -139,6 +139,9 @@ def make_custom_fields(update=True): dict(fieldname='customer_fiscal_code', label='Customer Fiscal Code', fieldtype='Data', insert_after='cb_e_invoicing_reference', read_only=1, fetch_from="customer.fiscal_code"), + dict(fieldname='type_of_document', label='Type of Document', + fieldtype='Select', insert_after='customer_fiscal_code', + options='\nTD01\nTD02\nTD03\nTD04\nTD05\nTD06\nTD16\nTD17\nTD18\nTD19\nTD20\nTD21\nTD22\nTD23\nTD24\nTD25\nTD26\nTD27'), ], 'Purchase Invoice Item': invoice_item_fields, 'Sales Order Item': invoice_item_fields, diff --git a/erpnext/regional/italy/utils.py b/erpnext/regional/italy/utils.py index 08573cddcd..ba1aeafc3e 100644 --- a/erpnext/regional/italy/utils.py +++ b/erpnext/regional/italy/utils.py @@ -57,11 +57,12 @@ def prepare_invoice(invoice, progressive_number): invoice.company_address_data = company_address #Set invoice type - if invoice.is_return and invoice.return_against: - invoice.type_of_document = "TD04" #Credit Note (Nota di Credito) - invoice.return_against_unamended = get_unamended_name(frappe.get_doc("Sales Invoice", invoice.return_against)) - else: - invoice.type_of_document = "TD01" #Sales Invoice (Fattura) + if not invoice.type_of_document: + if invoice.is_return and invoice.return_against: + invoice.type_of_document = "TD04" #Credit Note (Nota di Credito) + invoice.return_against_unamended = get_unamended_name(frappe.get_doc("Sales Invoice", invoice.return_against)) + else: + invoice.type_of_document = "TD01" #Sales Invoice (Fattura) #set customer information invoice.customer_data = frappe.get_doc("Customer", invoice.customer)