refactor: clear unallocated payments from POS Invoice

This commit is contained in:
ruthra kumar
2024-11-25 15:56:41 +05:30
parent efc22d5615
commit eebd058891
3 changed files with 25 additions and 2 deletions

View File

@@ -218,11 +218,25 @@ class TestPOSClosingEntry(IntegrationTestCase):
opening_entry = create_opening_entry(pos_profile, test_user.name)
pos_inv = create_pos_invoice(
item_code=item_code, qty=5, rate=300, use_serial_batch_fields=1, batch_no=batch_no
item_code=item_code,
qty=5,
rate=300,
use_serial_batch_fields=1,
batch_no=batch_no,
do_not_submit=True,
)
pos_inv.payments[0].amount = pos_inv.grand_total
pos_inv.submit()
pos_inv2 = create_pos_invoice(
item_code=item_code, qty=5, rate=300, use_serial_batch_fields=1, batch_no=batch_no
item_code=item_code,
qty=5,
rate=300,
use_serial_batch_fields=1,
batch_no=batch_no,
do_not_submit=True,
)
pos_inv2.payments[0].amount = pos_inv2.grand_total
pos_inv2.submit()
batch_qty = frappe.db.get_value("Batch", batch_no, "batch_qty")
self.assertEqual(batch_qty, 10)

View File

@@ -240,6 +240,7 @@ class POSInvoice(SalesInvoice):
from erpnext.accounts.doctype.pricing_rule.utils import update_coupon_code_count
update_coupon_code_count(self.coupon_code, "used")
self.clear_unallocated_mode_of_payments()
def before_cancel(self):
if (
@@ -278,6 +279,12 @@ class POSInvoice(SalesInvoice):
self.delink_serial_and_batch_bundle()
def clear_unallocated_mode_of_payments(self):
self.set("payments", self.get("payments", {"amount": ["not in", [0, None, ""]]}))
sip = frappe.qb.DocType("Sales Invoice Payment")
frappe.qb.from_(sip).delete().where(sip.parent == self.name).where(sip.amount == 0).run()
def delink_serial_and_batch_bundle(self):
for row in self.items:
if row.serial_and_batch_bundle:

View File

@@ -134,6 +134,7 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase):
},
)
inv.insert()
inv.payments[0].amount = inv.grand_total
inv.submit()
inv2 = create_pos_invoice(qty=1, rate=100, do_not_save=True)
@@ -150,6 +151,7 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase):
},
)
inv2.insert()
inv2.payments[0].amount = inv.grand_total
inv2.submit()
consolidate_pos_invoices()