Merge pull request #21571 from surajshetty3416/fix-console

refactor: Folio no validation
This commit is contained in:
Deepesh Garg 2020-05-04 09:03:14 +05:30 committed by GitHub
commit c33c309da3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -168,18 +168,20 @@ class ShareTransfer(Document):
return 'Outside' return 'Outside'
def folio_no_validation(self): def folio_no_validation(self):
shareholders = ['from_shareholder', 'to_shareholder'] shareholder_fields = ['from_shareholder', 'to_shareholder']
shareholders = [shareholder for shareholder in shareholders if self.get(shareholder) is not ''] for shareholder_field in shareholder_fields:
for shareholder in shareholders: shareholder_name = self.get(shareholder_field)
doc = self.get_shareholder_doc(self.get(shareholder)) if not shareholder_name:
continue
doc = self.get_shareholder_doc(shareholder_name)
if doc.company != self.company: if doc.company != self.company:
frappe.throw(_('The shareholder does not belong to this company')) frappe.throw(_('The shareholder does not belong to this company'))
if not doc.folio_no: if not doc.folio_no:
doc.folio_no = self.from_folio_no \ doc.folio_no = self.from_folio_no \
if (shareholder == 'from_shareholder') else self.to_folio_no if (shareholder_field == 'from_shareholder') else self.to_folio_no
doc.save() doc.save()
else: else:
if doc.folio_no and doc.folio_no != (self.from_folio_no if (shareholder == 'from_shareholder') else self.to_folio_no): if doc.folio_no and doc.folio_no != (self.from_folio_no if (shareholder_field == 'from_shareholder') else self.to_folio_no):
frappe.throw(_('The folio numbers are not matching')) frappe.throw(_('The folio numbers are not matching'))
def autoname_folio(self, shareholder, is_company=False): def autoname_folio(self, shareholder, is_company=False):