From 22ebaf1b11a52fcbe9c4c3d7dacf101c9038fa58 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Thu, 7 Mar 2019 15:18:49 +0530 Subject: [PATCH 1/2] fix: added tags for discount amount, multiple customer po no, delivery notes --- erpnext/patches.txt | 4 +- .../v11_0/make_italian_localization_fields.py | 2 +- erpnext/regional/italy/e-invoice.xml | 44 +++++++++++++++---- erpnext/regional/italy/setup.py | 18 +++++++- 4 files changed, 55 insertions(+), 13 deletions(-) diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 7d49ad5fe3..e4a43df781 100755 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -587,5 +587,5 @@ erpnext.patches.v11_1.setup_guardian_role execute:frappe.delete_doc('DocType', 'Notification Control') erpnext.patches.v11_0.remove_barcodes_field_from_copy_fields_to_variants erpnext.patches.v10_0.item_barcode_childtable_migrate # 16-02-2019 -erpnext.patches.v11_0.make_italian_localization_fields # 01-03-2019 -erpnext.patches.v11_1.make_job_card_time_logs \ No newline at end of file +erpnext.patches.v11_0.make_italian_localization_fields # 07-03-2019 +erpnext.patches.v11_1.make_job_card_time_logs diff --git a/erpnext/patches/v11_0/make_italian_localization_fields.py b/erpnext/patches/v11_0/make_italian_localization_fields.py index 44a281f86f..8fb2e5446b 100644 --- a/erpnext/patches/v11_0/make_italian_localization_fields.py +++ b/erpnext/patches/v11_0/make_italian_localization_fields.py @@ -6,7 +6,6 @@ from erpnext.regional.italy.setup import make_custom_fields, setup_report from erpnext.regional.italy import state_codes import frappe - def execute(): company = frappe.get_all('Company', filters = {'country': 'Italy'}) if not company: @@ -27,4 +26,5 @@ def execute(): frappe.db.sql(""" UPDATE tabAddress set {condition} country_code = UPPER(ifnull((select code from `tabCountry` where name = `tabAddress`.country), '')) + where country_code is null and state_code is null """.format(condition=condition)) diff --git a/erpnext/regional/italy/e-invoice.xml b/erpnext/regional/italy/e-invoice.xml index 912b7899d6..4bff45f49b 100644 --- a/erpnext/regional/italy/e-invoice.xml +++ b/erpnext/regional/italy/e-invoice.xml @@ -127,22 +127,46 @@ {{ format_float(doc.stamp_duty) }} {%- endif %} - {{ format_float(doc.grand_total) }} + {%- if doc.discount_amount %} + + {%- if doc.discount_amount > 0.0 %} + SC + {%- else %} + MG + {%- endif %} + {%- if doc.additional_discount_percentage > 0.0 %} + {{ format_float(doc.additional_discount_percentage) }} + {%- endif %} + {{ format_float(doc.discount_amount) }} + + {%- endif %} + {{ format_float(doc.rounded_total or doc.grand_total) }} VENDITA - {%- if doc.po_no %} - - {{ doc.po_no }} - {%- if doc.po_date %} - {{ doc.po_date }} + {%- for row in doc.e_invoice_items %} + {%- if row.customer_po_no %} + + {{ row.customer_po_no }} + {%- if row.customer_po_date %} + {{ row.customer_po_date }} + {%- endif %} + {%- endif %} - - {%- endif %} + {%- endfor %} {%- if doc.is_return and doc.return_against_unamended %} {{ doc.return_against_unamended }} {%- endif %} + {%- for row in doc.e_invoice_items %} + {%- if row.delivery_note %} + + {{ row.delivery_note }} + {{ frappe.db.get_value('Delivery Note', row.delivery_note, 'posting_date') }} + {{ row.idx }} + + {%- endif %} + {%- endfor %} {%- if doc.shipping_address_data %} @@ -198,7 +222,9 @@ {{ payment_term.mode_of_payment_code.split("-")[0] }} {{ payment_term.due_date }} {{ format_float(payment_term.payment_amount) }} - {{ payment_term.bank_account_name }} + {%- if payment_term.bank_account_name %} + {{ payment_term.bank_account_name }} + {%- endif %} {%- if payment_term.bank_account_iban %} {{ payment_term.bank_account_iban }} {{ payment_term.bank_account_iban[5:10] }} diff --git a/erpnext/regional/italy/setup.py b/erpnext/regional/italy/setup.py index 2b6e3af52a..b34f5e464b 100644 --- a/erpnext/regional/italy/setup.py +++ b/erpnext/regional/italy/setup.py @@ -26,6 +26,22 @@ def make_custom_fields(update=True): print_hide=1, hidden=1, read_only=1, options="currency") ] + customer_po_fields = [ + dict(fieldname='customer_po_details', label='Customer PO', + fieldtype='Section Break', insert_after='image'), + dict(fieldname='customer_po_no', label='Customer PO No', + fieldtype='Data', insert_after='customer_po_details', + fetch_from = 'sales_order.po_no', + print_hide=1, allow_on_submit=1, fetch_if_empty= 1, read_only=1), + dict(fieldname='customer_po_clm_brk', label='', + fieldtype='Column Break', insert_after='customer_po_no', + print_hide=1, read_only=1), + dict(fieldname='customer_po_date', label='Customer PO Date', + fieldtype='Date', insert_after='customer_po_clm_brk', + fetch_from = 'sales_order.po_date', + print_hide=1, allow_on_submit=1, fetch_if_empty= 1, read_only=1) + ] + custom_fields = { 'Company': [ dict(fieldname='sb_e_invoicing', label='E-Invoicing', @@ -128,7 +144,7 @@ def make_custom_fields(update=True): 'Purchase Invoice Item': invoice_item_fields, 'Sales Order Item': invoice_item_fields, 'Delivery Note Item': invoice_item_fields, - 'Sales Invoice Item': invoice_item_fields, + 'Sales Invoice Item': invoice_item_fields + customer_po_fields, 'Quotation Item': invoice_item_fields, 'Purchase Order Item': invoice_item_fields, 'Purchase Receipt Item': invoice_item_fields, From 1b7059b867c998f7fa94b852ca80c064df9a25a3 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Tue, 12 Mar 2019 17:44:29 +0530 Subject: [PATCH 2/2] fix: ImponibileImporto calculation --- erpnext/patches.txt | 2 +- .../v11_0/make_italian_localization_fields.py | 7 +++++ erpnext/regional/italy/e-invoice.xml | 20 ++++++------- erpnext/regional/italy/sales_invoice.js | 29 +++++++++++++------ erpnext/regional/italy/setup.py | 4 +-- erpnext/regional/italy/utils.py | 17 +++++++++-- 6 files changed, 55 insertions(+), 24 deletions(-) diff --git a/erpnext/patches.txt b/erpnext/patches.txt index e4a43df781..9d1e7b1453 100755 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -587,5 +587,5 @@ erpnext.patches.v11_1.setup_guardian_role execute:frappe.delete_doc('DocType', 'Notification Control') erpnext.patches.v11_0.remove_barcodes_field_from_copy_fields_to_variants erpnext.patches.v10_0.item_barcode_childtable_migrate # 16-02-2019 -erpnext.patches.v11_0.make_italian_localization_fields # 07-03-2019 +erpnext.patches.v11_0.make_italian_localization_fields # 26-03-2019 erpnext.patches.v11_1.make_job_card_time_logs diff --git a/erpnext/patches/v11_0/make_italian_localization_fields.py b/erpnext/patches/v11_0/make_italian_localization_fields.py index 8fb2e5446b..79958b9189 100644 --- a/erpnext/patches/v11_0/make_italian_localization_fields.py +++ b/erpnext/patches/v11_0/make_italian_localization_fields.py @@ -28,3 +28,10 @@ def execute(): from `tabCountry` where name = `tabAddress`.country), '')) where country_code is null and state_code is null """.format(condition=condition)) + + frappe.db.sql(""" + UPDATE `tabSales Invoice Item` si, `tabSales Order` so + set si.customer_po_no = so.po_no, si.customer_po_date = so.po_date + WHERE + si.sales_order = so.name and so.po_no is not null + """) diff --git a/erpnext/regional/italy/e-invoice.xml b/erpnext/regional/italy/e-invoice.xml index 4bff45f49b..935077b7be 100644 --- a/erpnext/regional/italy/e-invoice.xml +++ b/erpnext/regional/italy/e-invoice.xml @@ -143,15 +143,11 @@ {{ format_float(doc.rounded_total or doc.grand_total) }} VENDITA - {%- for row in doc.e_invoice_items %} - {%- if row.customer_po_no %} - - {{ row.customer_po_no }} - {%- if row.customer_po_date %} - {{ row.customer_po_date }} - {%- endif %} - - {%- endif %} + {%- for po_no, po_date in doc.customer_po_data.items() %} + + {{ po_no }} + {{ po_date }} + {%- endfor %} {%- if doc.is_return and doc.return_against_unamended %} @@ -188,7 +184,11 @@ {{ item.stock_uom }} {{ format_float(item.price_list_rate or item.rate) }} {{ render_discount_or_margin(item) }} - {{ format_float(item.amount) }} + {%- if (item.discount_amount or item.rate_with_margin) %} + {{ format_float(item.net_amount) }} + {%- else %} + {{ format_float(item.amount) }} + {%- endif %} {{ format_float(item.tax_rate) }} {%- if item.tax_exemption_reason %} {{ item.tax_exemption_reason.split("-")[0] }} diff --git a/erpnext/regional/italy/sales_invoice.js b/erpnext/regional/italy/sales_invoice.js index 3457f7161e..586a52937b 100644 --- a/erpnext/regional/italy/sales_invoice.js +++ b/erpnext/regional/italy/sales_invoice.js @@ -3,15 +3,26 @@ erpnext.setup_e_invoice_button = (doctype) => { refresh: (frm) => { if(frm.doc.docstatus == 1) { frm.add_custom_button('Generate E-Invoice', () => { - var w = window.open( - frappe.urllib.get_full_url( - "/api/method/erpnext.regional.italy.utils.generate_single_invoice?" - + "docname=" + frm.doc.name - ) - ) - if (!w) { - frappe.msgprint(__("Please enable pop-ups")); return; - } + frm.call({ + method: "erpnext.regional.italy.utils.generate_single_invoice", + args: { + docname: frm.doc.name + }, + callback: function(r) { + frm.reload_doc(); + if(r.message) { + var w = window.open( + frappe.urllib.get_full_url( + "/api/method/erpnext.regional.italy.utils.download_e_invoice_file?" + + "file_name=" + r.message + ) + ) + if (!w) { + frappe.msgprint(__("Please enable pop-ups")); return; + } + } + } + }); }); } } diff --git a/erpnext/regional/italy/setup.py b/erpnext/regional/italy/setup.py index b34f5e464b..1526d6f62f 100644 --- a/erpnext/regional/italy/setup.py +++ b/erpnext/regional/italy/setup.py @@ -32,14 +32,14 @@ def make_custom_fields(update=True): dict(fieldname='customer_po_no', label='Customer PO No', fieldtype='Data', insert_after='customer_po_details', fetch_from = 'sales_order.po_no', - print_hide=1, allow_on_submit=1, fetch_if_empty= 1, read_only=1), + print_hide=1, allow_on_submit=1, fetch_if_empty= 1, read_only=1, no_copy=1), dict(fieldname='customer_po_clm_brk', label='', fieldtype='Column Break', insert_after='customer_po_no', print_hide=1, read_only=1), dict(fieldname='customer_po_date', label='Customer PO Date', fieldtype='Date', insert_after='customer_po_clm_brk', fetch_from = 'sales_order.po_date', - print_hide=1, allow_on_submit=1, fetch_if_empty= 1, read_only=1) + print_hide=1, allow_on_submit=1, fetch_if_empty= 1, read_only=1, no_copy=1) ] custom_fields = { diff --git a/erpnext/regional/italy/utils.py b/erpnext/regional/italy/utils.py index e56c98b271..b299a6fa48 100644 --- a/erpnext/regional/italy/utils.py +++ b/erpnext/regional/italy/utils.py @@ -82,6 +82,14 @@ def prepare_invoice(invoice, progressive_number): if item.tax_rate == 0.0 and item.tax_amount == 0.0: item.tax_exemption_reason = tax_data["0.0"]["tax_exemption_reason"] + customer_po_data = {} + for d in invoice.e_invoice_items: + if (d.customer_po_no and d.customer_po_date + and d.customer_po_no not in customer_po_data): + customer_po_data[d.customer_po_no] = d.customer_po_date + + invoice.customer_po_data = customer_po_data + return invoice def get_conditions(filters): @@ -267,13 +275,18 @@ def prepare_and_attach_invoice(doc, replace=False): def generate_single_invoice(docname): doc = frappe.get_doc("Sales Invoice", docname) + e_invoice = prepare_and_attach_invoice(doc, True) + return e_invoice.file_name + +@frappe.whitelist() +def download_e_invoice_file(file_name): content = None - with open(frappe.get_site_path('private', 'files', e_invoice.file_name), "r") as f: + with open(frappe.get_site_path('private', 'files', file_name), "r") as f: content = f.read() - frappe.local.response.filename = e_invoice.file_name + frappe.local.response.filename = file_name frappe.local.response.filecontent = content frappe.local.response.type = "download"