2017-06-27 12:01:41 +00:00
|
|
|
import frappe
|
|
|
|
|
2021-09-02 11:14:59 +00:00
|
|
|
|
2017-06-27 12:01:41 +00:00
|
|
|
def get_context(context):
|
|
|
|
context.no_cache = 1
|
|
|
|
party = frappe.form_dict.party
|
2017-06-29 06:13:37 +00:00
|
|
|
context.party_name = party
|
2017-06-27 12:01:41 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
update_gstin(context)
|
|
|
|
except frappe.ValidationError:
|
|
|
|
context.invalid_gstin = 1
|
|
|
|
|
2022-03-28 13:22:46 +00:00
|
|
|
party_type = "Customer"
|
|
|
|
party_name = frappe.db.get_value("Customer", party)
|
2017-06-27 12:01:41 +00:00
|
|
|
|
2017-06-28 18:22:22 +00:00
|
|
|
if not party_name:
|
2022-03-28 13:22:46 +00:00
|
|
|
party_type = "Supplier"
|
|
|
|
party_name = frappe.db.get_value("Supplier", party)
|
2017-06-27 12:01:41 +00:00
|
|
|
|
2017-06-28 18:22:22 +00:00
|
|
|
if not party_name:
|
2017-06-29 06:13:37 +00:00
|
|
|
context.not_found = 1
|
|
|
|
return
|
2017-06-27 12:01:41 +00:00
|
|
|
|
2017-06-28 18:22:22 +00:00
|
|
|
context.party = frappe.get_doc(party_type, party_name)
|
2017-06-27 12:01:41 +00:00
|
|
|
context.party.onload()
|
|
|
|
|
|
|
|
|
|
|
|
def update_gstin(context):
|
|
|
|
dirty = False
|
2018-05-23 06:01:24 +00:00
|
|
|
for key, value in frappe.form_dict.items():
|
2022-03-28 13:22:46 +00:00
|
|
|
if key != "party":
|
|
|
|
address_name = frappe.get_value("Address", key)
|
2017-06-27 12:01:41 +00:00
|
|
|
if address_name:
|
2022-03-28 13:22:46 +00:00
|
|
|
address = frappe.get_doc("Address", address_name)
|
2017-06-28 18:22:22 +00:00
|
|
|
address.gstin = value.upper()
|
2017-06-27 12:01:41 +00:00
|
|
|
address.save(ignore_permissions=True)
|
|
|
|
dirty = True
|
|
|
|
|
|
|
|
if dirty:
|
|
|
|
frappe.db.commit()
|
|
|
|
context.updated = True
|