fix: batched items method giving wrong quantity, so changed it back to previous way
diff --git a/erpnext/accounts/doctype/pos_invoice/pos_invoice.py b/erpnext/accounts/doctype/pos_invoice/pos_invoice.py
index ac39877..89a9611 100644
--- a/erpnext/accounts/doctype/pos_invoice/pos_invoice.py
+++ b/erpnext/accounts/doctype/pos_invoice/pos_invoice.py
@@ -276,10 +276,10 @@
if self.is_return and entry.amount > 0:
frappe.throw(_("Row #{0} (Payment Table): Amount must be negative").format(entry.idx))
- # if self.is_return:
- # invoice_total = self.rounded_total or self.grand_total
- # if total_amount_in_payments and total_amount_in_payments < invoice_total:
- # frappe.throw(_("Total payments amount can't be greater than {}").format(-invoice_total))
+ if self.is_return:
+ invoice_total = self.rounded_total or self.grand_total
+ if total_amount_in_payments and total_amount_in_payments < invoice_total:
+ frappe.throw(_("Total payments amount can't be greater than {}").format(-invoice_total))
def validate_loyalty_transaction(self):
if self.redeem_loyalty_points and (
diff --git a/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py b/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py
index 78a20e8..4f46aa1 100644
--- a/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py
+++ b/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py
@@ -83,17 +83,19 @@
pos_invoice_docs = [
frappe.get_cached_doc("POS Invoice", d.pos_invoice) for d in self.pos_invoices
]
- batched_invoices = self.get_batched_invoices(pos_invoice_docs)
- for invoice in batched_invoices:
- sales_invoice, credit_note = "", ""
- if not invoice[0].get("is_return"):
- sales_invoice = self.process_merging_into_sales_invoice(invoice)
- else:
- credit_note = self.process_merging_into_credit_note(invoice)
+ returns = [d for d in pos_invoice_docs if d.get("is_return") == 1]
+ sales = [d for d in pos_invoice_docs if d.get("is_return") == 0]
- self.save() # save consolidated_sales_invoice & consolidated_credit_note ref in merge log
- self.update_pos_invoices(pos_invoice_docs, sales_invoice, credit_note)
+ 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)
+
+ self.save() # save consolidated_sales_invoice & consolidated_credit_note ref in merge log
+ self.update_pos_invoices(pos_invoice_docs, sales_invoice, credit_note)
def on_cancel(self):
pos_invoice_docs = [
@@ -395,8 +397,7 @@
for d in invoices
if d.is_return and d.return_against
]
- print(pos_return_docs, invoices, _invoices, sep="-")
- # breakpoint()
+
for pos_invoice in pos_return_docs:
for item in pos_invoice.items:
if not item.serial_no and not item.serial_and_batch_bundle:
diff --git a/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py b/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py
index fcf2bce..1f90c5b 100644
--- a/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py
+++ b/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py
@@ -1215,7 +1215,6 @@
for d in get_serial_batch_ledgers(kwargs.item_code, docstatus=1, name=ids):
ignore_serial_nos.append(d.serial_no)
- # Will be deprecated in v16
returned_serial_nos = []
for pos_invoice in pos_invoices:
if pos_invoice.serial_no:
@@ -1244,8 +1243,7 @@
)
)
# Counter is used to create a hashmap of serial nos, which contains count of each serial no
- # ignore serial nos inlcudes serial nos which are sold and returned
- # so we need to subtract returned serial nos from ignore serial nos after creating a counter of each
+ # so we subtract returned serial nos from ignore serial nos after creating a counter of each to get the items which we need to ignore(which are sold)
ignore_serial_nos_counter = Counter(ignore_serial_nos)
returned_serial_nos_counter = Counter(returned_serial_nos)