Skip to content

Commit

Permalink
fix: POS Closing entry issue (backport #44772) (#44781)
Browse files Browse the repository at this point in the history
fix: POS Closing entry issue (#44772)

(cherry picked from commit 779dd2d)

Co-authored-by: rohitwaghchaure <[email protected]>
  • Loading branch information
mergify[bot] and rohitwaghchaure authored Dec 18, 2024
1 parent 418ef81 commit 2032422
Showing 1 changed file with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,13 @@ def on_submit(self):
sales = [d for d in pos_invoice_docs if d.get("is_return") == 0]

sales_invoice, credit_note = "", ""
sales_invoice_doc = None
if sales:
sales_invoice = self.process_merging_into_sales_invoice(sales)
sales_invoice_doc = self.process_merging_into_sales_invoice(sales)
sales_invoice = sales_invoice_doc.name

if returns:
credit_note = self.process_merging_into_credit_note(returns, sales_invoice)
credit_note = self.process_merging_into_credit_note(returns, sales_invoice_doc)

self.save() # save consolidated_sales_invoice & consolidated_credit_note ref in merge log
self.update_pos_invoices(pos_invoice_docs, sales_invoice, credit_note)
Expand Down Expand Up @@ -152,15 +154,23 @@ def process_merging_into_sales_invoice(self, data):

self.consolidated_invoice = sales_invoice.name

return sales_invoice.name
return sales_invoice

def process_merging_into_credit_note(self, data, sales_invoice):
def process_merging_into_credit_note(self, data, sales_invoice_doc=None):
credit_note = self.get_new_sales_invoice()
credit_note.is_return = 1

credit_note = self.merge_pos_invoice_into(credit_note, data)
referenes = {}

if sales_invoice_doc:
credit_note.return_against = sales_invoice_doc.name

for d in sales_invoice_doc.items:
referenes[d.item_code] = d.name

credit_note.return_against = sales_invoice
for d in credit_note.items:
d.sales_invoice_item = referenes.get(d.item_code)

credit_note.is_consolidated = 1
credit_note.set_posting_time = 1
Expand Down Expand Up @@ -366,7 +376,12 @@ def get_serial_and_batch_bundles(self):
return []

def cancel_linked_invoices(self):
for si_name in [self.consolidated_invoice, self.consolidated_credit_note]:
invoices = [self.consolidated_invoice, self.consolidated_credit_note]
if not invoices:
return

invoices.reverse()
for si_name in invoices:
if not si_name:
continue
si = frappe.get_doc("Sales Invoice", si_name)
Expand Down

0 comments on commit 2032422

Please sign in to comment.