Merge pull request #16720 from gaurav-naik/italy-state-codes
fix(regional,italy): added state code on address, updated patch
This commit is contained in:
commit
06e6e87e3b
@ -210,7 +210,7 @@ doc_events = {
|
|||||||
"on_trash": "erpnext.regional.check_deletion_permission"
|
"on_trash": "erpnext.regional.check_deletion_permission"
|
||||||
},
|
},
|
||||||
'Address': {
|
'Address': {
|
||||||
'validate': 'erpnext.regional.india.utils.validate_gstin_for_india'
|
'validate': ['erpnext.regional.india.utils.validate_gstin_for_india', 'erpnext.regional.italy.utils.validate_address']
|
||||||
},
|
},
|
||||||
('Sales Invoice', 'Purchase Invoice', 'Delivery Note'): {
|
('Sales Invoice', 'Purchase Invoice', 'Delivery Note'): {
|
||||||
'validate': 'erpnext.regional.india.utils.set_place_of_supply'
|
'validate': 'erpnext.regional.india.utils.set_place_of_supply'
|
||||||
|
|||||||
@ -3,12 +3,26 @@
|
|||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
from erpnext.regional.italy.setup import make_custom_fields, setup_report
|
from erpnext.regional.italy.setup import make_custom_fields, setup_report
|
||||||
|
from erpnext.regional.italy import state_codes
|
||||||
import frappe
|
import frappe
|
||||||
|
|
||||||
|
|
||||||
def execute():
|
def execute():
|
||||||
|
|
||||||
company = frappe.get_all('Company', filters = {'country': 'Italy'})
|
company = frappe.get_all('Company', filters = {'country': 'Italy'})
|
||||||
if not company:
|
if not company:
|
||||||
return
|
return
|
||||||
|
|
||||||
make_custom_fields()
|
make_custom_fields()
|
||||||
setup_report()
|
setup_report()
|
||||||
|
|
||||||
|
# Set state codes
|
||||||
|
condition = ""
|
||||||
|
for state, code in state_codes.items():
|
||||||
|
condition += " when '{0}' then '{1}'".format(frappe.db.escape(state), frappe.db.escape(code))
|
||||||
|
|
||||||
|
if condition:
|
||||||
|
frappe.db.sql("""
|
||||||
|
UPDATE tabAddress set state_code = (case state {condition} end)
|
||||||
|
WHERE country in ('Italy', 'Italia', 'Italian Republic', 'Repubblica Italiana')
|
||||||
|
""".format(condition=condition))
|
||||||
|
|||||||
@ -61,3 +61,19 @@ vat_collectability_options = [
|
|||||||
"D-Differita",
|
"D-Differita",
|
||||||
"S-Scissione dei Pagamenti"
|
"S-Scissione dei Pagamenti"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
state_codes = {'Siracusa': 'SR', 'Bologna': 'BO', 'Grosseto': 'GR', 'Caserta': 'CE', 'Alessandria': 'AL', 'Ancona': 'AN', 'Pavia': 'PV',
|
||||||
|
'Benevento or Beneventum': 'BN', 'Modena': 'MO', 'Lodi': 'LO', 'Novara': 'NO', 'Avellino': 'AV', 'Verona': 'VR', 'Forli-Cesena': 'FC',
|
||||||
|
'Caltanissetta': 'CL', 'Brescia': 'BS', 'Rieti': 'RI', 'Treviso': 'TV', 'Ogliastra': 'OG', 'Olbia-Tempio': 'OT', 'Bergamo': 'BG',
|
||||||
|
'Napoli': 'NA', 'Campobasso': 'CB', 'Fermo': 'FM', 'Roma': 'RM', 'Lucca': 'LU', 'Rovigo': 'RO', 'Piacenza': 'PC', 'Monza and Brianza': 'MB',
|
||||||
|
'La Spezia': 'SP', 'Pescara': 'PE', 'Vercelli': 'VC', 'Enna': 'EN', 'Nuoro': 'NU', 'Medio Campidano': 'MD', 'Trieste': 'TS', 'Aosta': 'AO',
|
||||||
|
'Firenze': 'FI', 'Trapani': 'TP', 'Messina': 'ME', 'Teramo': 'TE', 'Udine': 'UD', 'Verbano-Cusio-Ossola': 'VB', 'Padua': 'PD',
|
||||||
|
'Reggio Emilia': 'RE', 'Frosinone': 'FR', 'Taranto': 'TA', 'Catanzaro': 'CZ', 'Belluno': 'BL', 'Pordenone': 'PN', 'Viterbo': 'VT',
|
||||||
|
'Gorizia': 'GO', 'Vatican City': 'SCV', 'Ferrara': 'FE', 'Chieti': 'CH', 'Crotone': 'KR', 'Foggia': 'FG', 'Perugia': 'PG', 'Bari': 'BA',
|
||||||
|
'Massa-Carrara': 'MS', 'Pisa': 'PI', 'Latina': 'LT', 'Salerno': 'SA', 'Turin': 'TO', 'Lecco': 'LC', 'Lecce': 'LE', 'Pistoia': 'PT', 'Como': 'CO',
|
||||||
|
'Barletta-Andria-Trani': 'BT', 'Mantua': 'MN', 'Ragusa': 'RG', 'Macerata': 'MC', 'Imperia': 'IM', 'Palermo': 'PA', 'Matera': 'MT', "L'Aquila": 'AQ',
|
||||||
|
'Milano': 'MI', 'Catania': 'CT', 'Pesaro e Urbino': 'PU', 'Potenza': 'PZ', 'Republic of San Marino': 'RSM', 'Genoa': 'GE', 'Brindisi': 'BR',
|
||||||
|
'Cagliari': 'CA', 'Siena': 'SI', 'Vibo Valentia': 'VV', 'Reggio Calabria': 'RC', 'Ascoli Piceno': 'AP', 'Carbonia-Iglesias': 'CI', 'Oristano': 'OR',
|
||||||
|
'Asti': 'AT', 'Ravenna': 'RA', 'Vicenza': 'VI', 'Savona': 'SV', 'Biella': 'BI', 'Rimini': 'RN', 'Agrigento': 'AG', 'Prato': 'PO', 'Cuneo': 'CN',
|
||||||
|
'Cosenza': 'CS', 'Livorno or Leghorn': 'LI', 'Sondrio': 'SO', 'Cremona': 'CR', 'Isernia': 'IS', 'Trento': 'TN', 'Terni': 'TR', 'Bolzano/Bozen': 'BZ',
|
||||||
|
'Parma': 'PR', 'Varese': 'VA', 'Venezia': 'VE', 'Sassari': 'SS', 'Arezzo': 'AR'}
|
||||||
@ -6,8 +6,8 @@
|
|||||||
<Indirizzo>{{ address.address_line1 }}</Indirizzo>
|
<Indirizzo>{{ address.address_line1 }}</Indirizzo>
|
||||||
<CAP>{{ address.pincode }}</CAP>
|
<CAP>{{ address.pincode }}</CAP>
|
||||||
<Comune>{{ address.city }}</Comune>
|
<Comune>{{ address.city }}</Comune>
|
||||||
{%- if address.state %}
|
{%- if address.state_code %}
|
||||||
<Provincia>{{ address.state }}</Provincia>
|
<Provincia>{{ address.state_code }}</Provincia>
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
<Nazione>{{ address.country_code|upper }}</Nazione>
|
<Nazione>{{ address.country_code|upper }}</Nazione>
|
||||||
{%- endmacro %}
|
{%- endmacro %}
|
||||||
|
|||||||
@ -133,7 +133,9 @@ def make_custom_fields(update=True):
|
|||||||
'Address': [
|
'Address': [
|
||||||
dict(fieldname='country_code', label='Country Code',
|
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=1,
|
||||||
fetch_from="country.code")
|
fetch_from="country.code"),
|
||||||
|
dict(fieldname='state_code', label='State Code',
|
||||||
|
fieldtype='Data', insert_after='state', print_hide=1)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,6 +6,7 @@ from erpnext.controllers.taxes_and_totals import get_itemised_tax
|
|||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.utils.file_manager import save_file, remove_file
|
from frappe.utils.file_manager import save_file, remove_file
|
||||||
from frappe.desk.form.load import get_attachments
|
from frappe.desk.form.load import get_attachments
|
||||||
|
from erpnext.regional.italy import state_codes
|
||||||
|
|
||||||
|
|
||||||
def update_itemised_tax_data(doc):
|
def update_itemised_tax_data(doc):
|
||||||
@ -283,3 +284,10 @@ def get_progressive_name_and_number(doc):
|
|||||||
progressive_number = progressive_name.split("_")[1]
|
progressive_number = progressive_name.split("_")[1]
|
||||||
|
|
||||||
return progressive_name, progressive_number
|
return progressive_name, progressive_number
|
||||||
|
|
||||||
|
def validate_address(doc, method):
|
||||||
|
if not (hasattr(doc, "state_code") and doc.country in ["Italy", "Italia", "Italian Republic", "Repubblica Italiana"]):
|
||||||
|
return
|
||||||
|
|
||||||
|
state_codes_lower = {key.lower():value for key,value in state_codes.items()}
|
||||||
|
doc.state_code = state_codes_lower.get(doc.get('state','').lower())
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user