Skip to content

Commit

Permalink
fix: delink SABB from cancelled SLEs
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitwaghchaure committed Dec 16, 2024
1 parent 9ebdd4d commit 39f545c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ def on_cancel(self):
self.update_pos_invoices(pos_invoice_docs)
self.serial_and_batch_bundle_reference_for_pos_invoice()
self.cancel_linked_invoices()
self.delink_serial_and_batch_bundle()

def process_merging_into_sales_invoice(self, data):
sales_invoice = self.get_new_sales_invoice()
Expand Down Expand Up @@ -320,6 +321,38 @@ def serial_and_batch_bundle_reference_for_pos_invoice(self):
for table_name in ["items", "packed_items"]:
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):
for si_name in [self.consolidated_invoice, self.consolidated_credit_note]:
if not si_name:
Expand Down Expand Up @@ -503,6 +536,9 @@ def cancel_merge_logs(merge_logs, closing_entry=None):
try:
for log in merge_logs:
merge_log = frappe.get_doc("POS Invoice Merge Log", log)
if merge_log.docstatus == 2:
continue

merge_log.flags.ignore_permissions = True
merge_log.cancel()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,8 @@ def set_serial_and_batch_values(self, parent, row, qty_field=None):
if not self.voucher_no or self.voucher_no != row.parent:
values_to_set["voucher_no"] = row.parent

self.db_set("is_cancelled", 0)

if self.voucher_type != parent.doctype:
values_to_set["voucher_type"] = parent.doctype

Expand Down

0 comments on commit 39f545c

Please sign in to comment.