2019-02-13 11:16:24 +00:00
|
|
|
# Copyright (c) 2017, Frappe and Contributors
|
|
|
|
# License: GNU General Public License v3. See license.txt
|
|
|
|
|
2021-09-02 11:14:59 +00:00
|
|
|
|
2019-02-13 11:16:24 +00:00
|
|
|
import frappe
|
|
|
|
|
2019-02-19 10:58:22 +00:00
|
|
|
from erpnext.regional.italy import state_codes
|
2019-02-13 11:16:24 +00:00
|
|
|
from erpnext.regional.italy.setup import make_custom_fields, setup_report
|
2021-09-02 11:14:59 +00:00
|
|
|
|
|
|
|
|
2019-02-13 11:16:24 +00:00
|
|
|
def execute():
|
2019-02-20 07:33:50 +00:00
|
|
|
company = frappe.get_all('Company', filters = {'country': 'Italy'})
|
|
|
|
if not company:
|
|
|
|
return
|
2019-02-19 10:58:22 +00:00
|
|
|
|
2019-02-20 07:33:50 +00:00
|
|
|
frappe.reload_doc('regional', 'report', 'electronic_invoice_register')
|
|
|
|
make_custom_fields()
|
|
|
|
setup_report()
|
2019-02-13 11:16:24 +00:00
|
|
|
|
2019-02-20 07:33:50 +00:00
|
|
|
# Set state codes
|
|
|
|
condition = ""
|
|
|
|
for state, code in state_codes.items():
|
2019-03-18 12:34:34 +00:00
|
|
|
condition += " when {0} then {1}".format(frappe.db.escape(state), frappe.db.escape(code))
|
2019-02-19 10:58:22 +00:00
|
|
|
|
2019-02-20 07:33:50 +00:00
|
|
|
if condition:
|
2019-02-26 14:38:26 +00:00
|
|
|
condition = "state_code = (case state {0} end),".format(condition)
|
|
|
|
|
|
|
|
frappe.db.sql("""
|
|
|
|
UPDATE tabAddress set {condition} country_code = UPPER(ifnull((select code
|
|
|
|
from `tabCountry` where name = `tabAddress`.country), ''))
|
2019-03-07 09:48:49 +00:00
|
|
|
where country_code is null and state_code is null
|
2019-02-26 14:38:26 +00:00
|
|
|
""".format(condition=condition))
|
2019-03-12 12:14:29 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
""")
|