refactor: suggested changes

This commit is contained in:
Noah Jacob 2021-07-12 09:18:19 +05:30
parent 34a5cb9106
commit 0be6583083
2 changed files with 16 additions and 19 deletions

View File

@ -57,16 +57,16 @@ class Supplier(TransactionBase):
self.payment_terms = "" self.payment_terms = ""
self.accounts = [] self.accounts = []
if not self.accounts and doc.accounts: if doc.accounts:
for account in doc.accounts: for account in doc.accounts:
child = self.append('accounts') child = self.append('accounts')
child.company = account.company child.company = account.company
child.account = account.account child.account = account.account
self.save()
if not self.payment_terms and doc.payment_terms: if doc.payment_terms:
self.payment_terms = doc.payment_terms self.payment_terms = doc.payment_terms
self.save()
def validate_internal_supplier(self): def validate_internal_supplier(self):
internal_supplier = frappe.db.get_value("Supplier", internal_supplier = frappe.db.get_value("Supplier",

View File

@ -84,25 +84,22 @@ class Customer(TransactionBase):
self.accounts = self.credit_limits = [] self.accounts = self.credit_limits = []
self.payment_terms = self.default_price_list = "" self.payment_terms = self.default_price_list = ""
if not self.accounts and doc.accounts: tables = [["accounts", "account"], ["credit_limits", "credit_limit"]]
for account in doc.accounts: fields = ["payment_terms", "default_price_list"]
child = self.append('accounts')
child.company = account.company
child.account = account.account
self.save()
if not self.credit_limits and doc.credit_limits: for row in tables:
for credit in doc.credit_limits: table, field = row[0], row[1]
child = self.append('credit_limits') if not doc.get(table): continue
child.company = credit.company
child.credit_limit = credit.credit_limit
self.save()
if not self.payment_terms and doc.payment_terms: for entry in doc.get(table):
self.payment_terms = doc.payment_terms child = self.append(table)
child.update({"company": entry.company, field: entry.get(field)})
if not self.default_price_list and doc.default_price_list: for field in fields:
self.default_price_list = doc.default_price_list if not doc.get(field): continue
self.update({field: doc.get(field)})
self.save()
def check_customer_group_change(self): def check_customer_group_change(self):
frappe.flags.customer_group_changed = False frappe.flags.customer_group_changed = False