mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-29 18:04:46 +00:00
fix: e-invoicing patch, patch to set country code in the address
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
{%- if address.state_code %}
|
||||
<Provincia>{{ address.state_code }}</Provincia>
|
||||
{%- endif %}
|
||||
<Nazione>{{ address.country_code|upper }}</Nazione>
|
||||
<Nazione>{{ address.country_code }}</Nazione>
|
||||
{%- endmacro %}
|
||||
|
||||
{%- macro render_discount_or_margin(item) -%}
|
||||
@@ -40,7 +40,7 @@
|
||||
<FatturaElettronicaHeader>
|
||||
<DatiTrasmissione>
|
||||
<IdTrasmittente>
|
||||
<IdPaese>{{ doc.company_address_data.country_code|upper or "IT" }}</IdPaese>
|
||||
<IdPaese>{{ doc.company_address_data.country_code }}</IdPaese>
|
||||
<IdCodice>{{ doc.company_fiscal_code or doc.company_tax_id | replace("IT","") }}</IdCodice>
|
||||
</IdTrasmittente>
|
||||
<ProgressivoInvio>{{ doc.progressive_number }}</ProgressivoInvio>
|
||||
@@ -56,7 +56,7 @@
|
||||
<CedentePrestatore>
|
||||
<DatiAnagrafici>
|
||||
<IdFiscaleIVA>
|
||||
<IdPaese>{{ doc.company_address_data.country_code|upper or "IT"}}</IdPaese>
|
||||
<IdPaese>{{ doc.company_address_data.country_code }}</IdPaese>
|
||||
<IdCodice>{{ doc.company_tax_id | replace("IT","") }}</IdCodice>
|
||||
</IdFiscaleIVA>
|
||||
{%- if doc.company_fiscal_code %}
|
||||
@@ -99,7 +99,7 @@
|
||||
<CodiceFiscale>{{ doc.customer_data.fiscal_code }}</CodiceFiscale>
|
||||
{%- else %}
|
||||
<IdFiscaleIVA>
|
||||
<IdPaese>{{ doc.customer_address_data.country_code|upper or "IT" }}</IdPaese>
|
||||
<IdPaese>{{ doc.customer_address_data.country_code }}</IdPaese>
|
||||
<IdCodice>{{ doc.tax_id | replace("IT","") }}</IdCodice>
|
||||
</IdFiscaleIVA>
|
||||
{%- endif %}
|
||||
@@ -160,7 +160,7 @@
|
||||
<CodiceTipo>CODICE</CodiceTipo>
|
||||
<CodiceValore>{{ item.item_code }}</CodiceValore>
|
||||
</CodiceArticolo>
|
||||
<Descrizione>{{ html2text(item.description) or item.item_name }}</Descrizione>
|
||||
<Descrizione>{{ html2text(item.description or '') or item.item_name }}</Descrizione>
|
||||
<Quantita>{{ format_float(item.qty) }}</Quantita>
|
||||
<UnitaMisura>{{ item.stock_uom }}</UnitaMisura>
|
||||
<PrezzoUnitario>{{ format_float(item.price_list_rate or item.rate) }}</PrezzoUnitario>
|
||||
|
||||
@@ -132,7 +132,7 @@ def make_custom_fields(update=True):
|
||||
'Supplier Quotation Item': invoice_item_fields,
|
||||
'Address': [
|
||||
dict(fieldname='country_code', label='Country Code',
|
||||
fieldtype='Data', insert_after='country', print_hide=1, read_only=1,
|
||||
fieldtype='Data', insert_after='country', print_hide=1, read_only=0,
|
||||
fetch_from="country.code"),
|
||||
dict(fieldname='state_code', label='State Code',
|
||||
fieldtype='Data', insert_after='state', print_hide=1)
|
||||
|
||||
@@ -189,7 +189,7 @@ def sales_invoice_validate(doc):
|
||||
if not doc.company_address:
|
||||
frappe.throw(_("Please set an Address on the Company '%s'" % doc.company), title=_("E-Invoicing Information Missing"))
|
||||
else:
|
||||
validate_address(doc.company_address, "Company")
|
||||
validate_address(doc.company_address)
|
||||
|
||||
company_fiscal_regime = frappe.get_cached_value("Company", doc.company, 'fiscal_regime')
|
||||
if not company_fiscal_regime:
|
||||
@@ -217,7 +217,7 @@ def sales_invoice_validate(doc):
|
||||
if not doc.customer_address:
|
||||
frappe.throw(_("Please set the Customer Address"), title=_("E-Invoicing Information Missing"))
|
||||
else:
|
||||
validate_address(doc.customer_address, "Customer")
|
||||
validate_address(doc.customer_address)
|
||||
|
||||
if not len(doc.taxes):
|
||||
frappe.throw(_("Please set at least one row in the Taxes and Charges Table"), title=_("E-Invoicing Information Missing"))
|
||||
@@ -285,13 +285,14 @@ def get_e_invoice_attachments(invoice):
|
||||
|
||||
return out
|
||||
|
||||
def validate_address(address_name, address_context):
|
||||
pincode, city = frappe.db.get_value("Address", address_name, ["pincode", "city"])
|
||||
if not pincode:
|
||||
frappe.throw(_("Please set pin code on %s Address" % address_context), title=_("E-Invoicing Information Missing"))
|
||||
if not city:
|
||||
frappe.throw(_("Please set city on %s Address" % address_context), title=_("E-Invoicing Information Missing"))
|
||||
def validate_address(address_name):
|
||||
fields = ["pincode", "city", "country_code"]
|
||||
data = frappe.get_cached_value("Address", address_name, fields, as_dict=1) or {}
|
||||
|
||||
for field in fields:
|
||||
if not data.get(field):
|
||||
frappe.throw(_("Please set {0} for address {1}".format(field.replace('-',''), address_name)),
|
||||
title=_("E-Invoicing Information Missing"))
|
||||
|
||||
def get_unamended_name(doc):
|
||||
attributes = ["naming_series", "amended_from"]
|
||||
@@ -312,6 +313,9 @@ def get_progressive_name_and_number(doc):
|
||||
return progressive_name, progressive_number
|
||||
|
||||
def set_state_code(doc, method):
|
||||
if doc.get('country_code'):
|
||||
doc.country_code = doc.country_code.upper()
|
||||
|
||||
if not doc.get('state'):
|
||||
return
|
||||
|
||||
|
||||
Reference in New Issue
Block a user