feat(pos): show POS reserved stock in stock projected qty report (#25593)

* feat(pos): consider POS reserved stock in stock projected qty report

* chore: remove unwanted string formats
This commit is contained in:
Saqib 2021-05-07 13:37:42 +05:30 committed by GitHub
parent 5618ce3852
commit 27cf19a19f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 21 deletions

View File

@ -461,7 +461,17 @@ def get_stock_availability(item_code, warehouse):
order by posting_date desc, posting_time desc order by posting_date desc, posting_time desc
limit 1""", (item_code, warehouse), as_dict=1) limit 1""", (item_code, warehouse), as_dict=1)
pos_sales_qty = frappe.db.sql("""select sum(p_item.qty) as qty 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
if sle_qty and pos_sales_qty:
return sle_qty - pos_sales_qty
else:
return sle_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 from `tabPOS Invoice` p, `tabPOS Invoice Item` p_item
where p.name = p_item.parent where p.name = p_item.parent
and p.consolidated_invoice is NULL and p.consolidated_invoice is NULL
@ -470,14 +480,8 @@ def get_stock_availability(item_code, warehouse):
and p_item.item_code = %s and p_item.item_code = %s
and p_item.warehouse = %s and p_item.warehouse = %s
""", (item_code, warehouse), as_dict=1) """, (item_code, warehouse), as_dict=1)
sle_qty = latest_sle[0].qty_after_transaction or 0 if latest_sle else 0 return reserved_qty[0].qty or 0 if reserved_qty else 0
pos_sales_qty = pos_sales_qty[0].qty or 0 if pos_sales_qty else 0
if sle_qty and pos_sales_qty:
return sle_qty - pos_sales_qty
else:
return sle_qty
@frappe.whitelist() @frappe.whitelist()
def make_sales_return(source_name, target_doc=None): def make_sales_return(source_name, target_doc=None):

View File

@ -116,22 +116,19 @@ def validate_filters(filters):
frappe.throw(_("Can not filter based on Payment Method, if grouped by Payment Method")) frappe.throw(_("Can not filter based on Payment Method, if grouped by Payment Method"))
def get_conditions(filters): def get_conditions(filters):
conditions = "company = %(company)s AND posting_date >= %(from_date)s AND posting_date <= %(to_date)s".format( conditions = "company = %(company)s AND posting_date >= %(from_date)s AND posting_date <= %(to_date)s"
company=filters.get("company"),
from_date=filters.get("from_date"),
to_date=filters.get("to_date"))
if filters.get("pos_profile"): if filters.get("pos_profile"):
conditions += " AND pos_profile = %(pos_profile)s".format(pos_profile=filters.get("pos_profile")) conditions += " AND pos_profile = %(pos_profile)s"
if filters.get("owner"): if filters.get("owner"):
conditions += " AND owner = %(owner)s".format(owner=filters.get("owner")) conditions += " AND owner = %(owner)s"
if filters.get("customer"): if filters.get("customer"):
conditions += " AND customer = %(customer)s".format(customer=filters.get("customer")) conditions += " AND customer = %(customer)s"
if filters.get("is_return"): if filters.get("is_return"):
conditions += " AND is_return = %(is_return)s".format(is_return=filters.get("is_return")) conditions += " AND is_return = %(is_return)s"
if filters.get("mode_of_payment"): if filters.get("mode_of_payment"):
conditions += """ conditions += """

View File

@ -14,7 +14,14 @@ frappe.query_reports["Stock Projected Qty"] = {
"fieldname":"warehouse", "fieldname":"warehouse",
"label": __("Warehouse"), "label": __("Warehouse"),
"fieldtype": "Link", "fieldtype": "Link",
"options": "Warehouse" "options": "Warehouse",
"get_query": () => {
return {
filters: {
company: frappe.query_report.get_filter_value('company')
}
}
}
}, },
{ {
"fieldname":"item_code", "fieldname":"item_code",

View File

@ -6,6 +6,7 @@ import frappe
from frappe import _ from frappe import _
from frappe.utils import flt, today from frappe.utils import flt, today
from erpnext.stock.utils import update_included_uom_in_report, is_reposting_item_valuation_in_progress from erpnext.stock.utils import update_included_uom_in_report, is_reposting_item_valuation_in_progress
from erpnext.accounts.doctype.pos_invoice.pos_invoice import get_pos_reserved_qty
def execute(filters=None): def execute(filters=None):
is_reposting_item_valuation_in_progress() is_reposting_item_valuation_in_progress()
@ -49,9 +50,13 @@ def execute(filters=None):
if (re_order_level or re_order_qty) and re_order_level > bin.projected_qty: if (re_order_level or re_order_qty) and re_order_level > bin.projected_qty:
shortage_qty = re_order_level - flt(bin.projected_qty) shortage_qty = re_order_level - flt(bin.projected_qty)
reserved_qty_for_pos = get_pos_reserved_qty(bin.item_code, bin.warehouse)
if reserved_qty_for_pos:
bin.projected_qty -= reserved_qty_for_pos
data.append([item.name, item.item_name, item.description, item.item_group, item.brand, bin.warehouse, data.append([item.name, item.item_name, item.description, item.item_group, item.brand, bin.warehouse,
item.stock_uom, bin.actual_qty, bin.planned_qty, bin.indented_qty, bin.ordered_qty, item.stock_uom, bin.actual_qty, bin.planned_qty, bin.indented_qty, bin.ordered_qty,
bin.reserved_qty, bin.reserved_qty_for_production, bin.reserved_qty_for_sub_contract, bin.reserved_qty, bin.reserved_qty_for_production, bin.reserved_qty_for_sub_contract, reserved_qty_for_pos,
bin.projected_qty, re_order_level, re_order_qty, shortage_qty]) bin.projected_qty, re_order_level, re_order_qty, shortage_qty])
if include_uom: if include_uom:
@ -74,9 +79,11 @@ def get_columns():
{"label": _("Requested Qty"), "fieldname": "indented_qty", "fieldtype": "Float", "width": 110, "convertible": "qty"}, {"label": _("Requested Qty"), "fieldname": "indented_qty", "fieldtype": "Float", "width": 110, "convertible": "qty"},
{"label": _("Ordered Qty"), "fieldname": "ordered_qty", "fieldtype": "Float", "width": 100, "convertible": "qty"}, {"label": _("Ordered Qty"), "fieldname": "ordered_qty", "fieldtype": "Float", "width": 100, "convertible": "qty"},
{"label": _("Reserved Qty"), "fieldname": "reserved_qty", "fieldtype": "Float", "width": 100, "convertible": "qty"}, {"label": _("Reserved Qty"), "fieldname": "reserved_qty", "fieldtype": "Float", "width": 100, "convertible": "qty"},
{"label": _("Reserved Qty for Production"), "fieldname": "reserved_qty_for_production", "fieldtype": "Float", {"label": _("Reserved for Production"), "fieldname": "reserved_qty_for_production", "fieldtype": "Float",
"width": 100, "convertible": "qty"}, "width": 100, "convertible": "qty"},
{"label": _("Reserved for sub contracting"), "fieldname": "reserved_qty_for_sub_contract", "fieldtype": "Float", {"label": _("Reserved for Sub Contracting"), "fieldname": "reserved_qty_for_sub_contract", "fieldtype": "Float",
"width": 100, "convertible": "qty"},
{"label": _("Reserved for POS Transactions"), "fieldname": "reserved_qty_for_pos", "fieldtype": "Float",
"width": 100, "convertible": "qty"}, "width": 100, "convertible": "qty"},
{"label": _("Projected Qty"), "fieldname": "projected_qty", "fieldtype": "Float", "width": 100, "convertible": "qty"}, {"label": _("Projected Qty"), "fieldname": "projected_qty", "fieldtype": "Float", "width": 100, "convertible": "qty"},
{"label": _("Reorder Level"), "fieldname": "re_order_level", "fieldtype": "Float", "width": 100, "convertible": "qty"}, {"label": _("Reorder Level"), "fieldname": "re_order_level", "fieldtype": "Float", "width": 100, "convertible": "qty"},