2019-01-22 12:52:20 +00:00
|
|
|
from __future__ import unicode_literals
|
2017-06-27 12:01:41 +00:00
|
|
|
import frappe
|
|
|
|
from frappe import _
|
2018-05-23 06:01:24 +00:00
|
|
|
from six import iteritems
|
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
|
|
|
|
|
|
|
|
party_type = 'Customer'
|
2017-06-28 18:22:22 +00:00
|
|
|
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:
|
2017-06-27 12:01:41 +00:00
|
|
|
party_type = 'Supplier'
|
2017-06-28 18:22:22 +00:00
|
|
|
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 iteritems(frappe.form_dict):
|
2017-06-27 12:01:41 +00:00
|
|
|
if key != 'party':
|
|
|
|
address_name = frappe.get_value('Address', key)
|
|
|
|
if address_name:
|
|
|
|
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
|