fix: Share existing condition logic
This commit is contained in:
parent
9c1c4ef3dd
commit
0debcf9f2f
@ -109,12 +109,12 @@ class ShareTransfer(Document):
|
||||
if self.transfer_type == 'Issue':
|
||||
# validate share doesn't exist in company
|
||||
ret_val = self.share_exists(self.get_company_shareholder().name)
|
||||
if ret_val:
|
||||
if ret_val in ('Complete', 'Partial'):
|
||||
frappe.throw(_('The shares already exist'), frappe.DuplicateEntryError)
|
||||
else:
|
||||
# validate share exists with from_shareholder
|
||||
ret_val = self.share_exists(self.from_shareholder)
|
||||
if not ret_val:
|
||||
if ret_val in ('Outside', 'Partial'):
|
||||
frappe.throw(_("The shares don't exist with the {0}")
|
||||
.format(self.from_shareholder), ShareDontExists)
|
||||
|
||||
@ -159,11 +159,13 @@ class ShareTransfer(Document):
|
||||
entry.to_no < self.from_no:
|
||||
continue # since query lies outside bounds
|
||||
elif entry.from_no <= self.from_no and entry.to_no >= self.to_no: #both inside
|
||||
return True # absolute truth!
|
||||
elif (entry.from_no <= self.from_no <= self.to_no) or entry.from_no <= self.to_no and entry.to_no:
|
||||
return True
|
||||
return 'Complete' # absolute truth!
|
||||
elif entry.from_no <= self.from_no <= self.to_no:
|
||||
return 'Partial'
|
||||
elif entry.from_no <= self.to_no <= entry.to_no:
|
||||
return 'Partial'
|
||||
|
||||
return False
|
||||
return 'Outside'
|
||||
|
||||
def folio_no_validation(self):
|
||||
shareholders = ['from_shareholder', 'to_shareholder']
|
||||
|
@ -15,73 +15,73 @@ class TestShareTransfer(unittest.TestCase):
|
||||
frappe.db.sql("delete from `tabShare Balance`")
|
||||
share_transfers = [
|
||||
{
|
||||
"doctype" : "Share Transfer",
|
||||
"transfer_type" : "Issue",
|
||||
"date" : "2018-01-01",
|
||||
"to_shareholder" : "SH-00001",
|
||||
"share_type" : "Equity",
|
||||
"from_no" : 1,
|
||||
"to_no" : 500,
|
||||
"no_of_shares" : 500,
|
||||
"rate" : 10,
|
||||
"company" : "_Test Company",
|
||||
"asset_account" : "Cash - _TC",
|
||||
"doctype": "Share Transfer",
|
||||
"transfer_type": "Issue",
|
||||
"date": "2018-01-01",
|
||||
"to_shareholder": "SH-00001",
|
||||
"share_type": "Equity",
|
||||
"from_no": 1,
|
||||
"to_no": 500,
|
||||
"no_of_shares": 500,
|
||||
"rate": 10,
|
||||
"company": "_Test Company",
|
||||
"asset_account": "Cash - _TC",
|
||||
"equity_or_liability_account": "Creditors - _TC"
|
||||
},
|
||||
{
|
||||
"doctype" : "Share Transfer",
|
||||
"transfer_type" : "Transfer",
|
||||
"date" : "2018-01-02",
|
||||
"from_shareholder" : "SH-00001",
|
||||
"to_shareholder" : "SH-00002",
|
||||
"share_type" : "Equity",
|
||||
"from_no" : 101,
|
||||
"to_no" : 200,
|
||||
"no_of_shares" : 100,
|
||||
"rate" : 15,
|
||||
"company" : "_Test Company",
|
||||
"doctype": "Share Transfer",
|
||||
"transfer_type": "Transfer",
|
||||
"date": "2018-01-02",
|
||||
"from_shareholder": "SH-00001",
|
||||
"to_shareholder": "SH-00002",
|
||||
"share_type": "Equity",
|
||||
"from_no": 101,
|
||||
"to_no": 200,
|
||||
"no_of_shares": 100,
|
||||
"rate": 15,
|
||||
"company": "_Test Company",
|
||||
"equity_or_liability_account": "Creditors - _TC"
|
||||
},
|
||||
{
|
||||
"doctype" : "Share Transfer",
|
||||
"transfer_type" : "Transfer",
|
||||
"date" : "2018-01-03",
|
||||
"from_shareholder" : "SH-00001",
|
||||
"to_shareholder" : "SH-00003",
|
||||
"share_type" : "Equity",
|
||||
"from_no" : 201,
|
||||
"to_no" : 500,
|
||||
"no_of_shares" : 300,
|
||||
"rate" : 20,
|
||||
"company" : "_Test Company",
|
||||
"doctype": "Share Transfer",
|
||||
"transfer_type": "Transfer",
|
||||
"date": "2018-01-03",
|
||||
"from_shareholder": "SH-00001",
|
||||
"to_shareholder": "SH-00003",
|
||||
"share_type": "Equity",
|
||||
"from_no": 201,
|
||||
"to_no": 500,
|
||||
"no_of_shares": 300,
|
||||
"rate": 20,
|
||||
"company": "_Test Company",
|
||||
"equity_or_liability_account": "Creditors - _TC"
|
||||
},
|
||||
{
|
||||
"doctype" : "Share Transfer",
|
||||
"transfer_type" : "Transfer",
|
||||
"date" : "2018-01-04",
|
||||
"from_shareholder" : "SH-00003",
|
||||
"to_shareholder" : "SH-00002",
|
||||
"share_type" : "Equity",
|
||||
"from_no" : 201,
|
||||
"to_no" : 400,
|
||||
"no_of_shares" : 200,
|
||||
"rate" : 15,
|
||||
"company" : "_Test Company",
|
||||
"doctype": "Share Transfer",
|
||||
"transfer_type": "Transfer",
|
||||
"date": "2018-01-04",
|
||||
"from_shareholder": "SH-00003",
|
||||
"to_shareholder": "SH-00002",
|
||||
"share_type": "Equity",
|
||||
"from_no": 201,
|
||||
"to_no": 400,
|
||||
"no_of_shares": 200,
|
||||
"rate": 15,
|
||||
"company": "_Test Company",
|
||||
"equity_or_liability_account": "Creditors - _TC"
|
||||
},
|
||||
{
|
||||
"doctype" : "Share Transfer",
|
||||
"transfer_type" : "Purchase",
|
||||
"date" : "2018-01-05",
|
||||
"from_shareholder" : "SH-00003",
|
||||
"share_type" : "Equity",
|
||||
"from_no" : 401,
|
||||
"to_no" : 500,
|
||||
"no_of_shares" : 100,
|
||||
"rate" : 25,
|
||||
"company" : "_Test Company",
|
||||
"asset_account" : "Cash - _TC",
|
||||
"doctype": "Share Transfer",
|
||||
"transfer_type": "Purchase",
|
||||
"date": "2018-01-05",
|
||||
"from_shareholder": "SH-00003",
|
||||
"share_type": "Equity",
|
||||
"from_no": 401,
|
||||
"to_no": 500,
|
||||
"no_of_shares": 100,
|
||||
"rate": 25,
|
||||
"company": "_Test Company",
|
||||
"asset_account": "Cash - _TC",
|
||||
"equity_or_liability_account": "Creditors - _TC"
|
||||
}
|
||||
]
|
||||
@ -91,33 +91,33 @@ class TestShareTransfer(unittest.TestCase):
|
||||
|
||||
def test_invalid_share_transfer(self):
|
||||
doc = frappe.get_doc({
|
||||
"doctype" : "Share Transfer",
|
||||
"transfer_type" : "Transfer",
|
||||
"date" : "2018-01-05",
|
||||
"from_shareholder" : "SH-00003",
|
||||
"to_shareholder" : "SH-00002",
|
||||
"share_type" : "Equity",
|
||||
"from_no" : 1,
|
||||
"to_no" : 100,
|
||||
"no_of_shares" : 100,
|
||||
"rate" : 15,
|
||||
"company" : "_Test Company",
|
||||
"doctype": "Share Transfer",
|
||||
"transfer_type": "Transfer",
|
||||
"date": "2018-01-05",
|
||||
"from_shareholder": "SH-00003",
|
||||
"to_shareholder": "SH-00002",
|
||||
"share_type": "Equity",
|
||||
"from_no": 1,
|
||||
"to_no": 100,
|
||||
"no_of_shares": 100,
|
||||
"rate": 15,
|
||||
"company": "_Test Company",
|
||||
"equity_or_liability_account": "Creditors - _TC"
|
||||
})
|
||||
self.assertRaises(ShareDontExists, doc.insert)
|
||||
|
||||
doc = frappe.get_doc({
|
||||
"doctype" : "Share Transfer",
|
||||
"transfer_type" : "Purchase",
|
||||
"date" : "2018-01-02",
|
||||
"from_shareholder" : "SH-00001",
|
||||
"share_type" : "Equity",
|
||||
"from_no" : 1,
|
||||
"to_no" : 200,
|
||||
"no_of_shares" : 200,
|
||||
"rate" : 15,
|
||||
"company" : "_Test Company",
|
||||
"asset_account" : "Cash - _TC",
|
||||
"doctype": "Share Transfer",
|
||||
"transfer_type": "Purchase",
|
||||
"date": "2018-01-02",
|
||||
"from_shareholder": "SH-00001",
|
||||
"share_type": "Equity",
|
||||
"from_no": 1,
|
||||
"to_no": 200,
|
||||
"no_of_shares": 200,
|
||||
"rate": 15,
|
||||
"company": "_Test Company",
|
||||
"asset_account": "Cash - _TC",
|
||||
"equity_or_liability_account": "Creditors - _TC"
|
||||
})
|
||||
self.assertRaises(ShareDontExists, doc.insert)
|
||||
|
Loading…
x
Reference in New Issue
Block a user