2019-02-13 11:16:24 +00:00
|
|
|
# Copyright (c) 2017, Frappe and Contributors
|
|
|
|
# License: GNU General Public License v3. See license.txt
|
|
|
|
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
from erpnext.regional.italy.setup import make_custom_fields, setup_report
|
2019-02-19 10:58:22 +00:00
|
|
|
from erpnext.regional.italy import state_codes
|
2019-02-13 11:16:24 +00:00
|
|
|
import frappe
|
|
|
|
|
2019-02-19 10:58:22 +00:00
|
|
|
|
2019-02-13 11:16:24 +00:00
|
|
|
def execute():
|
2019-02-19 10:58:22 +00:00
|
|
|
|
2019-02-13 11:16:24 +00:00
|
|
|
company = frappe.get_all('Company', filters = {'country': 'Italy'})
|
|
|
|
if not company:
|
|
|
|
return
|
|
|
|
|
|
|
|
make_custom_fields()
|
|
|
|
setup_report()
|
2019-02-19 10:58:22 +00:00
|
|
|
|
|
|
|
# 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))
|