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