Skip to content

Commit

Permalink
fix: pos invoice return reference missing (backport #44720) (#44729)
Browse files Browse the repository at this point in the history
fix: pos invoice return reference missing (#44720)

(cherry picked from commit 852596d)

Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
  • Loading branch information
mergify[bot] and rohitwaghchaure authored Dec 17, 2024
1 parent 6176411 commit 8aec131
Showing 1 changed file with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ def on_submit(self):
sales = [d for d in pos_invoice_docs if d.get("is_return") == 0]

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

if sales:
sales_invoice = self.process_merging_into_sales_invoice(sales)

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

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 All @@ -140,21 +140,28 @@ def process_merging_into_sales_invoice(self, data):

sales_invoice.is_consolidated = 1
sales_invoice.set_posting_time = 1
sales_invoice.posting_date = getdate(self.posting_date)
sales_invoice.posting_time = get_time(self.posting_time)

if not sales_invoice.posting_date:
sales_invoice.posting_date = getdate(self.posting_date)

if not sales_invoice.posting_time:
sales_invoice.posting_time = get_time(self.posting_time)

sales_invoice.save()
sales_invoice.submit()

self.consolidated_invoice = sales_invoice.name

return sales_invoice.name

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

credit_note = self.merge_pos_invoice_into(credit_note, data)

credit_note.return_against = sales_invoice

credit_note.is_consolidated = 1
credit_note.set_posting_time = 1
credit_note.posting_date = getdate(self.posting_date)
Expand All @@ -181,6 +188,10 @@ def merge_pos_invoice_into(self, invoice, data):
for doc in data:
map_doc(doc, invoice, table_map={"doctype": invoice.doctype})

if doc.get("posting_date"):
invoice.posting_date = getdate(doc.posting_date)
invoice.posting_time = get_time(doc.posting_time)

if doc.redeem_loyalty_points:
invoice.loyalty_redemption_account = doc.loyalty_redemption_account
invoice.loyalty_redemption_cost_center = doc.loyalty_redemption_cost_center
Expand Down Expand Up @@ -298,6 +309,8 @@ def get_new_sales_invoice(self):
sales_invoice = frappe.new_doc("Sales Invoice")
sales_invoice.customer = self.customer
sales_invoice.is_pos = 1
sales_invoice.posting_date = None
sales_invoice.posting_time = None

return sales_invoice

Expand Down

0 comments on commit 8aec131

Please sign in to comment.