fix: POS Runtime Effect completed

This commit is contained in:
Ritvik Sardana 2023-08-04 16:47:49 +05:30
parent 5b1aa07ecb
commit c9d5a62350
3 changed files with 33 additions and 54 deletions

View File

@ -542,6 +542,7 @@ def get_stock_availability(item_code, warehouse):
is_stock_item = True is_stock_item = True
bin_qty = get_bin_qty(item_code, warehouse) bin_qty = get_bin_qty(item_code, warehouse)
pos_sales_qty = get_pos_reserved_qty(item_code, warehouse) pos_sales_qty = get_pos_reserved_qty(item_code, warehouse)
return bin_qty - pos_sales_qty, is_stock_item return bin_qty - pos_sales_qty, is_stock_item
else: else:
is_stock_item = True is_stock_item = True

View File

@ -83,30 +83,19 @@ class POSInvoiceMergeLog(Document):
pos_invoice_docs = [ pos_invoice_docs = [
frappe.get_cached_doc("POS Invoice", d.pos_invoice) for d in self.pos_invoices 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: returns = [d for d in pos_invoice_docs if d.get("is_return") == 1]
sales_invoice, credit_note = "", "" sales = [d for d in pos_invoice_docs if d.get("is_return") == 0]
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)
self.save() # save consolidated_sales_invoice & consolidated_credit_note ref in merge log sales_invoice, credit_note = "", ""
self.update_pos_invoices(pos_invoice_docs, sales_invoice, credit_note) if returns:
credit_note = self.process_merging_into_credit_note(returns)
# returns = [d for d in pos_invoice_docs if d.get("is_return") == 1] if sales:
# sales = [d for d in pos_invoice_docs if d.get("is_return") == 0] sales_invoice = self.process_merging_into_sales_invoice(sales)
# sales_invoice, credit_note = "", "" self.save() # save consolidated_sales_invoice & consolidated_credit_note ref in merge log
# if returns: self.update_pos_invoices(pos_invoice_docs, sales_invoice, credit_note)
# 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): def on_cancel(self):
pos_invoice_docs = [ pos_invoice_docs = [
@ -171,23 +160,20 @@ class POSInvoiceMergeLog(Document):
for item in doc.get("items"): for item in doc.get("items"):
found = False found = False
if not item.serial_and_batch_bundle: for i in items:
for i in items: if (
i.item_code == item.item_code
if ( and not i.serial_and_batch_bundle
i.item_code == item.item_code and i.uom == item.uom
and not i.serial_no and i.net_rate == item.net_rate
and not i.batch_no and i.warehouse == item.warehouse
and i.uom == item.uom ):
and i.net_rate == item.net_rate found = True
and i.warehouse == item.warehouse i.qty = i.qty + item.qty
): i.amount = i.amount + item.net_amount
found = True i.net_amount = i.amount
i.qty = i.qty + item.qty i.base_amount = i.base_amount + item.base_net_amount
i.amount = i.amount + item.net_amount i.base_net_amount = i.base_amount
i.net_amount = i.amount
i.base_amount = i.base_amount + item.base_net_amount
i.base_net_amount = i.base_amount
if not found: if not found:
item.rate = item.net_rate item.rate = item.net_rate
@ -287,21 +273,6 @@ class POSInvoiceMergeLog(Document):
si.flags.ignore_validate = True si.flags.ignore_validate = True
si.cancel() 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): def update_item_wise_tax_detail(consolidate_tax_row, tax_row):
consolidated_tax_detail = json.loads(consolidate_tax_row.item_wise_tax_detail) consolidated_tax_detail = json.loads(consolidate_tax_row.item_wise_tax_detail)

View File

@ -3,7 +3,7 @@
import collections import collections
import csv import csv
from collections import defaultdict from collections import Counter, defaultdict
from typing import Dict, List from typing import Dict, List
import frappe import frappe
@ -1197,6 +1197,7 @@ def get_reserved_serial_nos_for_pos(kwargs):
filters=[ filters=[
["POS Invoice", "consolidated_invoice", "is", "not set"], ["POS Invoice", "consolidated_invoice", "is", "not set"],
["POS Invoice", "docstatus", "=", 1], ["POS Invoice", "docstatus", "=", 1],
["POS Invoice", "is_return", "=", 0],
["POS Invoice Item", "item_code", "=", kwargs.item_code], ["POS Invoice Item", "item_code", "=", kwargs.item_code],
["POS Invoice", "name", "!=", kwargs.ignore_voucher_no], ["POS Invoice", "name", "!=", kwargs.ignore_voucher_no],
], ],
@ -1242,8 +1243,14 @@ def get_reserved_serial_nos_for_pos(kwargs):
child_doc, parent_doc, ignore_voucher_detail_no=kwargs.get("ignore_voucher_detail_no") child_doc, parent_doc, ignore_voucher_detail_no=kwargs.get("ignore_voucher_detail_no")
) )
) )
# 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
return list(set(ignore_serial_nos) - set(returned_serial_nos)) ignore_serial_nos_counter = Counter(ignore_serial_nos)
returned_serial_nos_counter = Counter(returned_serial_nos)
return list(ignore_serial_nos_counter - returned_serial_nos_counter)
def get_reserved_batches_for_pos(kwargs): def get_reserved_batches_for_pos(kwargs):