fix: added code for batched items in POS

This commit is contained in:
Ritvik Sardana 2023-08-01 19:28:40 +05:30
parent e36c8ce5be
commit 17771a55fb
2 changed files with 41 additions and 16 deletions

View File

@ -276,10 +276,10 @@ class POSInvoice(SalesInvoice):
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 (
@ -595,7 +595,6 @@ def get_pos_reserved_qty(item_code, warehouse):
.where(
(p_inv.name == p_item.parent)
& (IfNull(p_inv.consolidated_invoice, "") == "")
& (p_inv.is_return == 0)
& (p_item.docstatus == 1)
& (p_item.item_code == item_code)
& (p_item.warehouse == warehouse)

View File

@ -83,20 +83,30 @@ class POSInvoiceMergeLog(Document):
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)
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]
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)
sales_invoice, credit_note = "", ""
if returns:
credit_note = self.process_merging_into_credit_note(returns)
self.save() # save consolidated_sales_invoice & consolidated_credit_note ref in merge log
self.update_pos_invoices(pos_invoice_docs, sales_invoice, credit_note)
if sales:
sales_invoice = self.process_merging_into_sales_invoice(sales)
# 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
# sales_invoice, credit_note = "", ""
# if returns:
# credit_note = self.process_merging_into_credit_note(returns)
self.update_pos_invoices(pos_invoice_docs, sales_invoice, credit_note)
# 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 = [
@ -108,7 +118,6 @@ class POSInvoiceMergeLog(Document):
def process_merging_into_sales_invoice(self, data):
sales_invoice = self.get_new_sales_invoice()
sales_invoice = self.merge_pos_invoice_into(sales_invoice, data)
sales_invoice.is_consolidated = 1
@ -276,6 +285,21 @@ class POSInvoiceMergeLog(Document):
si.flags.ignore_validate = True
si.cancel()
def get_batched_invoices(self, pos_invoice_docs):
grouped_batch = []
current_batch = []
for item in pos_invoice_docs:
if not current_batch:
current_batch.append(item)
elif current_batch[-1].get("is_return") != item.get("is_return"):
grouped_batch.append(current_batch)
current_batch = [item]
else:
current_batch.append(item)
grouped_batch.append(current_batch)
return grouped_batch
def update_item_wise_tax_detail(consolidate_tax_row, tax_row):
consolidated_tax_detail = json.loads(consolidate_tax_row.item_wise_tax_detail)
@ -385,13 +409,15 @@ def split_invoices(invoices):
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:
continue
return_against_is_added = any(
d for d in _invoices if d.pos_invoice == pos_invoice.return_against
d for d in invoices if d.pos_invoice == pos_invoice.return_against
)
if return_against_is_added:
break