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