mirror of
https://github.com/frappe/erpnext.git
synced 2026-04-24 00:58:29 +00:00
fix: delink SABB from cancelled SLEs (#44691)
(cherry picked from commit 5f539619bc)
Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
This commit is contained in:
@@ -132,6 +132,7 @@ class POSInvoiceMergeLog(Document):
|
|||||||
self.update_pos_invoices(pos_invoice_docs)
|
self.update_pos_invoices(pos_invoice_docs)
|
||||||
self.serial_and_batch_bundle_reference_for_pos_invoice()
|
self.serial_and_batch_bundle_reference_for_pos_invoice()
|
||||||
self.cancel_linked_invoices()
|
self.cancel_linked_invoices()
|
||||||
|
self.delink_serial_and_batch_bundle()
|
||||||
|
|
||||||
def process_merging_into_sales_invoice(self, data):
|
def process_merging_into_sales_invoice(self, data):
|
||||||
sales_invoice = self.get_new_sales_invoice()
|
sales_invoice = self.get_new_sales_invoice()
|
||||||
@@ -319,6 +320,38 @@ class POSInvoiceMergeLog(Document):
|
|||||||
for table_name in ["items", "packed_items"]:
|
for table_name in ["items", "packed_items"]:
|
||||||
pos_invoice.set_serial_and_batch_bundle(table_name)
|
pos_invoice.set_serial_and_batch_bundle(table_name)
|
||||||
|
|
||||||
|
def delink_serial_and_batch_bundle(self):
|
||||||
|
bundles = self.get_serial_and_batch_bundles()
|
||||||
|
if not bundles:
|
||||||
|
return
|
||||||
|
|
||||||
|
sle_table = frappe.qb.DocType("Stock Ledger Entry")
|
||||||
|
query = (
|
||||||
|
frappe.qb.update(sle_table)
|
||||||
|
.set(sle_table.serial_and_batch_bundle, None)
|
||||||
|
.where(sle_table.serial_and_batch_bundle.isin(bundles) & sle_table.is_cancelled == 1)
|
||||||
|
)
|
||||||
|
|
||||||
|
query.run()
|
||||||
|
|
||||||
|
def get_serial_and_batch_bundles(self):
|
||||||
|
pos_invoices = []
|
||||||
|
for d in self.pos_invoices:
|
||||||
|
pos_invoices.append(d.pos_invoice)
|
||||||
|
|
||||||
|
if pos_invoices:
|
||||||
|
return frappe.get_all(
|
||||||
|
"POS Invoice Item",
|
||||||
|
filters={
|
||||||
|
"docstatus": 1,
|
||||||
|
"parent": ["in", pos_invoices],
|
||||||
|
"serial_and_batch_bundle": ["is", "set"],
|
||||||
|
},
|
||||||
|
pluck="serial_and_batch_bundle",
|
||||||
|
)
|
||||||
|
|
||||||
|
return []
|
||||||
|
|
||||||
def cancel_linked_invoices(self):
|
def cancel_linked_invoices(self):
|
||||||
for si_name in [self.consolidated_invoice, self.consolidated_credit_note]:
|
for si_name in [self.consolidated_invoice, self.consolidated_credit_note]:
|
||||||
if not si_name:
|
if not si_name:
|
||||||
@@ -503,6 +536,9 @@ def cancel_merge_logs(merge_logs, closing_entry=None):
|
|||||||
try:
|
try:
|
||||||
for log in merge_logs:
|
for log in merge_logs:
|
||||||
merge_log = frappe.get_doc("POS Invoice Merge Log", log)
|
merge_log = frappe.get_doc("POS Invoice Merge Log", log)
|
||||||
|
if merge_log.docstatus == 2:
|
||||||
|
continue
|
||||||
|
|
||||||
merge_log.flags.ignore_permissions = True
|
merge_log.flags.ignore_permissions = True
|
||||||
merge_log.cancel()
|
merge_log.cancel()
|
||||||
|
|
||||||
|
|||||||
@@ -519,6 +519,8 @@ class SerialandBatchBundle(Document):
|
|||||||
if not self.voucher_no or self.voucher_no != row.parent:
|
if not self.voucher_no or self.voucher_no != row.parent:
|
||||||
values_to_set["voucher_no"] = row.parent
|
values_to_set["voucher_no"] = row.parent
|
||||||
|
|
||||||
|
self.db_set("is_cancelled", 0)
|
||||||
|
|
||||||
if self.voucher_type != parent.doctype:
|
if self.voucher_type != parent.doctype:
|
||||||
values_to_set["voucher_type"] = parent.doctype
|
values_to_set["voucher_type"] = parent.doctype
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user