From cdcff6c26d56abead76e609a119a52b286c5cc24 Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Mon, 9 Sep 2019 10:15:01 +0530 Subject: [PATCH] Multiple port from v11 hotfix (#18954) * fix: circular dependency during asset cancellation * fix: ImponibileImporto for On Previous Row Total * fix: PrezzoUnitario decimal issue --- erpnext/assets/doctype/asset/asset.py | 6 ------ erpnext/regional/italy/e-invoice.xml | 14 +++++++------- erpnext/regional/italy/utils.py | 9 +++++++-- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/erpnext/assets/doctype/asset/asset.py b/erpnext/assets/doctype/asset/asset.py index ab37e91538..8f208e2cdb 100644 --- a/erpnext/assets/doctype/asset/asset.py +++ b/erpnext/assets/doctype/asset/asset.py @@ -292,12 +292,6 @@ class Asset(AccountsController): if self.status not in ("Submitted", "Partially Depreciated", "Fully Depreciated"): frappe.throw(_("Asset cannot be cancelled, as it is already {0}").format(self.status)) - if self.purchase_invoice: - frappe.throw(_("Please cancel Purchase Invoice {0} first").format(self.purchase_invoice)) - - if self.purchase_receipt: - frappe.throw(_("Please cancel Purchase Receipt {0} first").format(self.purchase_receipt)) - def delete_depreciation_entries(self): for d in self.get("schedules"): if d.journal_entry: diff --git a/erpnext/regional/italy/e-invoice.xml b/erpnext/regional/italy/e-invoice.xml index 9a588d1666..9978dc0da2 100644 --- a/erpnext/regional/italy/e-invoice.xml +++ b/erpnext/regional/italy/e-invoice.xml @@ -1,5 +1,5 @@ -{%- macro format_float(value) -%} -{{ "%.2f" % value|abs }} +{%- macro format_float(value, precision=2) -%} +{{ value|round(frappe.utils.cint(precision)) }} {%- endmacro -%} {%- macro render_address(address) %} @@ -182,10 +182,10 @@ {{ html2text(item.description or '') or item.item_name }} {{ format_float(item.qty) }} {{ item.stock_uom }} - {{ format_float(item.price_list_rate or item.rate) }} + {{ format_float(item.price_list_rate or item.rate, item_meta.get_field("rate").precision) }} {{ render_discount_or_margin(item) }} - {{ format_float(item.amount) }} - {{ format_float(item.tax_rate) }} + {{ format_float(item.amount, item_meta.get_field("amount").precision) }} + {{ format_float(item.tax_rate, item_meta.get_field("tax_rate").precision) }} {%- if item.tax_exemption_reason %} {{ item.tax_exemption_reason.split("-")[0] }} {%- endif %} @@ -197,8 +197,8 @@ {%- if data.tax_exemption_reason %} {{ data.tax_exemption_reason.split("-")[0] }} {%- endif %} - {{ format_float(data.taxable_amount) }} - {{ format_float(data.tax_amount) }} + {{ format_float(data.taxable_amount, item_meta.get_field("tax_amount").precision) }} + {{ format_float(data.tax_amount, item_meta.get_field("tax_amount").precision) }} {{ doc.vat_collectability.split("-")[0] }} {%- if data.tax_exemption_law %} {{ data.tax_exemption_law }} diff --git a/erpnext/regional/italy/utils.py b/erpnext/regional/italy/utils.py index 407677f976..12f5762f44 100644 --- a/erpnext/regional/italy/utils.py +++ b/erpnext/regional/italy/utils.py @@ -151,7 +151,8 @@ def get_invoice_summary(items, taxes): tax_rate=tax.rate, tax_amount=(reference_row.tax_amount * tax.rate) / 100, net_amount=reference_row.tax_amount, - taxable_amount=reference_row.tax_amount, + taxable_amount=(reference_row.tax_amount if tax.charge_type == 'On Previous Row Amount' + else reference_row.total), item_tax_rate={tax.account_head: tax.rate}, charges=True ) @@ -278,7 +279,11 @@ def prepare_and_attach_invoice(doc, replace=False): progressive_name, progressive_number = get_progressive_name_and_number(doc, replace) invoice = prepare_invoice(doc, progressive_number) - invoice_xml = frappe.render_template('erpnext/regional/italy/e-invoice.xml', context={"doc": invoice}, is_path=True) + item_meta = frappe.get_meta("Sales Invoice Item") + + invoice_xml = frappe.render_template('erpnext/regional/italy/e-invoice.xml', + context={"doc": invoice, "item_meta": item_meta}, is_path=True) + invoice_xml = invoice_xml.replace("&", "&") xml_filename = progressive_name + ".xml"