fix(test): case if write off is calculated as negative amount

This commit is contained in:
Saqib Ansari 2022-02-08 17:07:51 +05:30
parent afc5c26d1c
commit c2b83a0283
3 changed files with 9 additions and 9 deletions

View File

@ -95,7 +95,6 @@ class POSInvoiceMergeLog(Document):
pos_invoice_grand_total = sum(d.grand_total for d in data)
if abs(pos_invoice_grand_total - invoice.grand_total) < 1:
invoice.write_off_amount += -1 * (pos_invoice_grand_total - invoice.grand_total)
invoice.save()

View File

@ -154,10 +154,10 @@ class TestPOSInvoiceMergeLog(unittest.TestCase):
def test_consolidation_round_off_error_1(self):
'''
Test case for bug:
Round off error in consolidated invoice creation if POS Invoice has inclusive tax
Test round off error in consolidated invoice creation if POS Invoice has inclusive tax
'''
frappe.db.sql("delete from `tabPOS Invoice`")
allow_negative_stock = frappe.db.get_value('Stock Settings', None, 'allow_negative_stock')
frappe.db.set_value('Stock Settings', None, 'allow_negative_stock', 1)
try:
@ -206,13 +206,14 @@ class TestPOSInvoiceMergeLog(unittest.TestCase):
frappe.set_user("Administrator")
frappe.db.sql("delete from `tabPOS Profile`")
frappe.db.sql("delete from `tabPOS Invoice`")
frappe.db.set_value('Stock Settings', None, 'allow_negative_stock', 0)
frappe.db.set_value('Stock Settings', None, 'allow_negative_stock', allow_negative_stock)
def test_consolidation_round_off_error_2(self):
'''
Test the same case as above but with an Unpaid POS Invoice
'''
frappe.db.sql("delete from `tabPOS Invoice`")
allow_negative_stock = frappe.db.get_value('Stock Settings', None, 'allow_negative_stock')
frappe.db.set_value('Stock Settings', None, 'allow_negative_stock', 1)
try:
@ -262,10 +263,10 @@ class TestPOSInvoiceMergeLog(unittest.TestCase):
inv.load_from_db()
consolidated_invoice = frappe.get_doc('Sales Invoice', inv.consolidated_invoice)
self.assertEqual(consolidated_invoice.outstanding_amount, 800)
self.assertEqual(consolidated_invoice.status, 'Unpaid')
self.assertNotEqual(consolidated_invoice.status, 'Paid')
finally:
frappe.set_user("Administrator")
frappe.db.sql("delete from `tabPOS Profile`")
frappe.db.sql("delete from `tabPOS Invoice`")
frappe.db.set_value('Stock Settings', None, 'allow_negative_stock', 0)
frappe.db.set_value('Stock Settings', None, 'allow_negative_stock', allow_negative_stock)

View File

@ -650,12 +650,12 @@ class calculate_taxes_and_totals(object):
def calculate_change_amount(self):
self.doc.change_amount = 0.0
self.doc.base_change_amount = 0.0
grand_total = self.doc.rounded_total or self.doc.grand_total
base_grand_total = self.doc.base_rounded_total or self.doc.base_grand_total
if self.doc.doctype == "Sales Invoice" \
and self.doc.paid_amount > self.doc.grand_total and not self.doc.is_return \
and self.doc.paid_amount > grand_total and not self.doc.is_return \
and any(d.type == "Cash" for d in self.doc.payments):
grand_total = self.doc.rounded_total or self.doc.grand_total
base_grand_total = self.doc.base_rounded_total or self.doc.base_grand_total
self.doc.change_amount = flt(self.doc.paid_amount - grand_total +
self.doc.write_off_amount, self.doc.precision("change_amount"))