fix(test): case if write off is calculated as negative amount
This commit is contained in:
parent
afc5c26d1c
commit
c2b83a0283
@ -95,7 +95,6 @@ class POSInvoiceMergeLog(Document):
|
|||||||
pos_invoice_grand_total = sum(d.grand_total for d in data)
|
pos_invoice_grand_total = sum(d.grand_total for d in data)
|
||||||
|
|
||||||
if abs(pos_invoice_grand_total - invoice.grand_total) < 1:
|
if abs(pos_invoice_grand_total - invoice.grand_total) < 1:
|
||||||
|
|
||||||
invoice.write_off_amount += -1 * (pos_invoice_grand_total - invoice.grand_total)
|
invoice.write_off_amount += -1 * (pos_invoice_grand_total - invoice.grand_total)
|
||||||
invoice.save()
|
invoice.save()
|
||||||
|
|
||||||
|
@ -154,10 +154,10 @@ class TestPOSInvoiceMergeLog(unittest.TestCase):
|
|||||||
|
|
||||||
def test_consolidation_round_off_error_1(self):
|
def test_consolidation_round_off_error_1(self):
|
||||||
'''
|
'''
|
||||||
Test case for bug:
|
Test round off error in consolidated invoice creation if POS Invoice has inclusive tax
|
||||||
Round off error in consolidated invoice creation if POS Invoice has inclusive tax
|
|
||||||
'''
|
'''
|
||||||
frappe.db.sql("delete from `tabPOS 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)
|
frappe.db.set_value('Stock Settings', None, 'allow_negative_stock', 1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -206,13 +206,14 @@ class TestPOSInvoiceMergeLog(unittest.TestCase):
|
|||||||
frappe.set_user("Administrator")
|
frappe.set_user("Administrator")
|
||||||
frappe.db.sql("delete from `tabPOS Profile`")
|
frappe.db.sql("delete from `tabPOS Profile`")
|
||||||
frappe.db.sql("delete from `tabPOS Invoice`")
|
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):
|
def test_consolidation_round_off_error_2(self):
|
||||||
'''
|
'''
|
||||||
Test the same case as above but with an Unpaid POS Invoice
|
Test the same case as above but with an Unpaid POS Invoice
|
||||||
'''
|
'''
|
||||||
frappe.db.sql("delete from `tabPOS 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)
|
frappe.db.set_value('Stock Settings', None, 'allow_negative_stock', 1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -262,10 +263,10 @@ class TestPOSInvoiceMergeLog(unittest.TestCase):
|
|||||||
inv.load_from_db()
|
inv.load_from_db()
|
||||||
consolidated_invoice = frappe.get_doc('Sales Invoice', inv.consolidated_invoice)
|
consolidated_invoice = frappe.get_doc('Sales Invoice', inv.consolidated_invoice)
|
||||||
self.assertEqual(consolidated_invoice.outstanding_amount, 800)
|
self.assertEqual(consolidated_invoice.outstanding_amount, 800)
|
||||||
self.assertEqual(consolidated_invoice.status, 'Unpaid')
|
self.assertNotEqual(consolidated_invoice.status, 'Paid')
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
frappe.set_user("Administrator")
|
frappe.set_user("Administrator")
|
||||||
frappe.db.sql("delete from `tabPOS Profile`")
|
frappe.db.sql("delete from `tabPOS Profile`")
|
||||||
frappe.db.sql("delete from `tabPOS Invoice`")
|
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)
|
||||||
|
@ -650,12 +650,12 @@ class calculate_taxes_and_totals(object):
|
|||||||
def calculate_change_amount(self):
|
def calculate_change_amount(self):
|
||||||
self.doc.change_amount = 0.0
|
self.doc.change_amount = 0.0
|
||||||
self.doc.base_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" \
|
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):
|
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.change_amount = flt(self.doc.paid_amount - grand_total +
|
||||||
self.doc.write_off_amount, self.doc.precision("change_amount"))
|
self.doc.write_off_amount, self.doc.precision("change_amount"))
|
||||||
|
Loading…
Reference in New Issue
Block a user