fix: share transfer validations for journal entry (#19018)

* fix share transfer validations for journal entry

* fix: share transfer test

* fix: tests
This commit is contained in:
Rucha Mahabal 2019-09-13 11:05:40 +05:30 committed by Nabin Hait
parent e4f8bda1ea
commit 72949e7f73
2 changed files with 90 additions and 74 deletions

View File

@ -86,17 +86,23 @@ class ShareTransfer(Document):
frappe.throw(_('The field From Shareholder cannot be blank'))
if self.from_folio_no is None or self.from_folio_no is '':
self.to_folio_no = self.autoname_folio(self.to_shareholder)
if self.asset_account is None:
frappe.throw(_('The field Asset Account cannot be blank'))
elif (self.transfer_type == 'Issue'):
self.from_shareholder = ''
if self.to_shareholder is None or self.to_shareholder == '':
frappe.throw(_('The field To Shareholder cannot be blank'))
if self.to_folio_no is None or self.to_folio_no is '':
self.to_folio_no = self.autoname_folio(self.to_shareholder)
if self.asset_account is None:
frappe.throw(_('The field Asset Account cannot be blank'))
else:
if self.from_shareholder is None or self.to_shareholder is None:
frappe.throw(_('The fields From Shareholder and To Shareholder cannot be blank'))
if self.to_folio_no is None or self.to_folio_no is '':
self.to_folio_no = self.autoname_folio(self.to_shareholder)
if self.equity_or_liability_account is None:
frappe.throw(_('The field Equity/Liability Account cannot be blank'))
if self.from_shareholder == self.to_shareholder:
frappe.throw(_('The seller and the buyer cannot be the same'))
if self.no_of_shares != self.to_no - self.from_no + 1:

View File

@ -24,7 +24,9 @@ class TestShareTransfer(unittest.TestCase):
"to_no" : 500,
"no_of_shares" : 500,
"rate" : 10,
"company" : "_Test Company"
"company" : "_Test Company",
"asset_account" : "Cash - _TC",
"equity_or_liability_account": "Creditors - _TC"
},
{
"doctype" : "Share Transfer",
@ -37,7 +39,8 @@ class TestShareTransfer(unittest.TestCase):
"to_no" : 200,
"no_of_shares" : 100,
"rate" : 15,
"company" : "_Test Company"
"company" : "_Test Company",
"equity_or_liability_account": "Creditors - _TC"
},
{
"doctype" : "Share Transfer",
@ -50,7 +53,8 @@ class TestShareTransfer(unittest.TestCase):
"to_no" : 500,
"no_of_shares" : 300,
"rate" : 20,
"company" : "_Test Company"
"company" : "_Test Company",
"equity_or_liability_account": "Creditors - _TC"
},
{
"doctype" : "Share Transfer",
@ -63,7 +67,8 @@ class TestShareTransfer(unittest.TestCase):
"to_no" : 400,
"no_of_shares" : 200,
"rate" : 15,
"company" : "_Test Company"
"company" : "_Test Company",
"equity_or_liability_account": "Creditors - _TC"
},
{
"doctype" : "Share Transfer",
@ -75,7 +80,9 @@ class TestShareTransfer(unittest.TestCase):
"to_no" : 500,
"no_of_shares" : 100,
"rate" : 25,
"company" : "_Test Company"
"company" : "_Test Company",
"asset_account" : "Cash - _TC",
"equity_or_liability_account": "Creditors - _TC"
}
]
for d in share_transfers:
@ -94,7 +101,8 @@ class TestShareTransfer(unittest.TestCase):
"to_no" : 100,
"no_of_shares" : 100,
"rate" : 15,
"company" : "_Test Company"
"company" : "_Test Company",
"equity_or_liability_account": "Creditors - _TC"
})
self.assertRaises(ShareDontExists, doc.insert)
@ -108,6 +116,8 @@ class TestShareTransfer(unittest.TestCase):
"to_no" : 200,
"no_of_shares" : 200,
"rate" : 15,
"company" : "_Test Company"
"company" : "_Test Company",
"asset_account" : "Cash - _TC",
"equity_or_liability_account": "Creditors - _TC"
})
self.assertRaises(ShareDontExists, doc.insert)