Merge pull request #62654 from aerele/fix/share-transfer-amount-precision

fix(accounts): respect share transfer amount precision
This commit is contained in:
mergify[bot]
2026-10-28 02:57:26 +00:00
committed by GitHub
2 changed files with 36 additions and 4 deletions
@@ -7,7 +7,7 @@ from frappe import _
from frappe.exceptions import ValidationError
from frappe.model.document import Document
from frappe.model.naming import make_autoname
from frappe.utils import nowdate
from frappe.utils import flt, nowdate
class ShareDontExists(ValidationError):
@@ -200,12 +200,12 @@ class ShareTransfer(Document):
frappe.throw(_("The seller and the buyer cannot be the same"))
if self.no_of_shares != self.to_no - self.from_no + 1:
frappe.throw(_("The number of shares and the share numbers are inconsistent"))
if not self.amount:
self.amount = self.rate * self.no_of_shares
if self.amount != self.rate * self.no_of_shares:
amount = flt(self.rate * self.no_of_shares, self.precision("amount"))
if self.amount and flt(self.amount, self.precision("amount")) != amount:
frappe.throw(
_("There are inconsistencies between the rate, no of shares and the amount calculated")
)
self.amount = amount
def share_exists(self, shareholder):
doc = self.get_shareholder_doc(shareholder)
@@ -85,6 +85,38 @@ class TestShareTransfer(ERPNextTestSuite):
st = frappe.get_doc(d)
st.submit()
def test_fractional_rate_submission_after_reload(self):
for rate, amount in ((10.1, 30.3), (0.1, 0.3), (10.25, 30.75)):
with self.subTest(rate=rate):
doc = frappe.get_doc(
{
"doctype": "Share Transfer",
"transfer_type": "Issue",
"date": "2018-01-06",
"to_shareholder": "SH-00001",
"share_type": "Equity",
"from_no": 501,
"to_no": 503,
"no_of_shares": 3,
"rate": rate,
"amount": rate * 3,
"company": "_Test Company",
"asset_account": "Cash - _TC",
"equity_or_liability_account": "Creditors - _TC",
}
).insert()
self.assertEqual(doc.amount, amount)
doc.reload()
self.assertEqual(doc.amount, amount)
doc.save()
doc.reload()
doc.submit()
doc.reload()
self.assertEqual(doc.docstatus, 1)
self.assertEqual(doc.amount, amount)
doc.cancel()
self.assertEqual(doc.docstatus, 2)
def test_shareholders_stay_protected_after_buyback(self):
from frappe.client import set_value