From 0b5e340b6e7f68a41a09cad0ab8dca8105ec905d Mon Sep 17 00:00:00 2001 From: Saqib Date: Fri, 21 May 2021 16:32:56 +0530 Subject: [PATCH] fix(pos): return case for item with available qty equal to one (#25760) --- .../pos_closing_entry_detail.json | 3 ++- .../accounts/doctype/pos_invoice/pos_invoice.py | 16 +++++----------- .../pos_invoice_merge_log.py | 6 +++--- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/erpnext/accounts/doctype/pos_closing_entry_detail/pos_closing_entry_detail.json b/erpnext/accounts/doctype/pos_closing_entry_detail/pos_closing_entry_detail.json index 6e7768dc54..bbf1ba0020 100644 --- a/erpnext/accounts/doctype/pos_closing_entry_detail/pos_closing_entry_detail.json +++ b/erpnext/accounts/doctype/pos_closing_entry_detail/pos_closing_entry_detail.json @@ -46,6 +46,7 @@ "reqd": 1 }, { + "default": "0", "fieldname": "closing_amount", "fieldtype": "Currency", "in_list_view": 1, @@ -57,7 +58,7 @@ "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2020-10-23 16:45:43.662034", + "modified": "2021-05-19 20:08:44.523861", "modified_by": "Administrator", "module": "Accounts", "name": "POS Closing Entry Detail", diff --git a/erpnext/accounts/doctype/pos_invoice/pos_invoice.py b/erpnext/accounts/doctype/pos_invoice/pos_invoice.py index 473db565fa..f55fdab21c 100644 --- a/erpnext/accounts/doctype/pos_invoice/pos_invoice.py +++ b/erpnext/accounts/doctype/pos_invoice/pos_invoice.py @@ -455,32 +455,26 @@ class POSInvoice(SalesInvoice): @frappe.whitelist() def get_stock_availability(item_code, warehouse): - latest_sle = frappe.db.sql("""select qty_after_transaction - from `tabStock Ledger Entry` + bin_qty = frappe.db.sql("""select actual_qty from `tabBin` where item_code = %s and warehouse = %s - order by posting_date desc, posting_time desc limit 1""", (item_code, warehouse), as_dict=1) pos_sales_qty = get_pos_reserved_qty(item_code, warehouse) - sle_qty = latest_sle[0].qty_after_transaction or 0 if latest_sle else 0 + bin_qty = bin_qty[0].actual_qty or 0 if bin_qty else 0 - if sle_qty and pos_sales_qty: - return sle_qty - pos_sales_qty - else: - return sle_qty + return bin_qty - pos_sales_qty def get_pos_reserved_qty(item_code, warehouse): reserved_qty = frappe.db.sql("""select sum(p_item.qty) as qty from `tabPOS Invoice` p, `tabPOS Invoice Item` p_item where p.name = p_item.parent - and p.consolidated_invoice is NULL - and p.docstatus = 1 + and ifnull(p.consolidated_invoice, '') = '' and p_item.docstatus = 1 and p_item.item_code = %s and p_item.warehouse = %s """, (item_code, warehouse), as_dict=1) - + return reserved_qty[0].qty or 0 if reserved_qty else 0 @frappe.whitelist() 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 bc7874305c..b0ddea304c 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 @@ -56,12 +56,12 @@ class POSInvoiceMergeLog(Document): sales = [d for d in pos_invoice_docs if d.get('is_return') == 0] sales_invoice, credit_note = "", "" - if sales: - sales_invoice = self.process_merging_into_sales_invoice(sales) - 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)