mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-23 23:19:20 +00:00
Merge pull request #26726 from marination/stock-reco-fetch-non-empty-stock
feat: (Stock Reco) Ignore Empty Stock while fetching items from warehouse
This commit is contained in:
@@ -56,25 +56,40 @@ frappe.ui.form.on("Stock Reconciliation", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
get_items: function(frm) {
|
get_items: function(frm) {
|
||||||
let fields = [{
|
let fields = [
|
||||||
label: 'Warehouse', fieldname: 'warehouse', fieldtype: 'Link', options: 'Warehouse', reqd: 1,
|
{
|
||||||
"get_query": function() {
|
label: 'Warehouse',
|
||||||
return {
|
fieldname: 'warehouse',
|
||||||
"filters": {
|
fieldtype: 'Link',
|
||||||
"company": frm.doc.company,
|
options: 'Warehouse',
|
||||||
}
|
reqd: 1,
|
||||||
};
|
"get_query": function() {
|
||||||
|
return {
|
||||||
|
"filters": {
|
||||||
|
"company": frm.doc.company,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Item Code",
|
||||||
|
fieldname: "item_code",
|
||||||
|
fieldtype: "Link",
|
||||||
|
options: "Item",
|
||||||
|
"get_query": function() {
|
||||||
|
return {
|
||||||
|
"filters": {
|
||||||
|
"disabled": 0,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: __("Ignore Empty Stock"),
|
||||||
|
fieldname: "ignore_empty_stock",
|
||||||
|
fieldtype: "Check"
|
||||||
}
|
}
|
||||||
}, {
|
];
|
||||||
label: "Item Code", fieldname: "item_code", fieldtype: "Link", options: "Item",
|
|
||||||
"get_query": function() {
|
|
||||||
return {
|
|
||||||
"filters": {
|
|
||||||
"disabled": 0,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}];
|
|
||||||
|
|
||||||
frappe.prompt(fields, function(data) {
|
frappe.prompt(fields, function(data) {
|
||||||
frappe.call({
|
frappe.call({
|
||||||
@@ -84,22 +99,21 @@ frappe.ui.form.on("Stock Reconciliation", {
|
|||||||
posting_date: frm.doc.posting_date,
|
posting_date: frm.doc.posting_date,
|
||||||
posting_time: frm.doc.posting_time,
|
posting_time: frm.doc.posting_time,
|
||||||
company: frm.doc.company,
|
company: frm.doc.company,
|
||||||
item_code: data.item_code
|
item_code: data.item_code,
|
||||||
|
ignore_empty_stock: data.ignore_empty_stock
|
||||||
},
|
},
|
||||||
callback: function(r) {
|
callback: function(r) {
|
||||||
|
if (r.exc || !r.message || !r.message.length) return;
|
||||||
|
|
||||||
frm.clear_table("items");
|
frm.clear_table("items");
|
||||||
for (var i=0; i<r.message.length; i++) {
|
|
||||||
var d = frm.add_child("items");
|
|
||||||
$.extend(d, r.message[i]);
|
|
||||||
|
|
||||||
if (!d.qty) {
|
r.message.forEach((row) => {
|
||||||
d.qty = 0;
|
let item = frm.add_child("items");
|
||||||
}
|
$.extend(item, row);
|
||||||
|
|
||||||
if (!d.valuation_rate) {
|
item.qty = item.qty || 0;
|
||||||
d.valuation_rate = 0;
|
item.valuation_rate = item.valuation_rate || 0;
|
||||||
}
|
});
|
||||||
}
|
|
||||||
frm.refresh_field("items");
|
frm.refresh_field("items");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -483,7 +483,8 @@ class StockReconciliation(StockController):
|
|||||||
self._cancel()
|
self._cancel()
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_items(warehouse, posting_date, posting_time, company, item_code=None):
|
def get_items(warehouse, posting_date, posting_time, company, item_code=None, ignore_empty_stock=False):
|
||||||
|
ignore_empty_stock = cint(ignore_empty_stock)
|
||||||
items = [frappe._dict({
|
items = [frappe._dict({
|
||||||
'item_code': item_code,
|
'item_code': item_code,
|
||||||
'warehouse': warehouse
|
'warehouse': warehouse
|
||||||
@@ -497,18 +498,24 @@ def get_items(warehouse, posting_date, posting_time, company, item_code=None):
|
|||||||
|
|
||||||
for d in items:
|
for d in items:
|
||||||
if d.item_code in itemwise_batch_data:
|
if d.item_code in itemwise_batch_data:
|
||||||
stock_bal = get_stock_balance(d.item_code, d.warehouse,
|
valuation_rate = get_stock_balance(d.item_code, d.warehouse,
|
||||||
posting_date, posting_time, with_valuation_rate=True)
|
posting_date, posting_time, with_valuation_rate=True)[1]
|
||||||
|
|
||||||
for row in itemwise_batch_data.get(d.item_code):
|
for row in itemwise_batch_data.get(d.item_code):
|
||||||
args = get_item_data(row, row.qty, stock_bal[1])
|
if ignore_empty_stock and not row.qty:
|
||||||
|
continue
|
||||||
|
|
||||||
|
args = get_item_data(row, row.qty, valuation_rate)
|
||||||
res.append(args)
|
res.append(args)
|
||||||
else:
|
else:
|
||||||
stock_bal = get_stock_balance(d.item_code, d.warehouse, posting_date, posting_time,
|
stock_bal = get_stock_balance(d.item_code, d.warehouse, posting_date, posting_time,
|
||||||
with_valuation_rate=True , with_serial_no=cint(d.has_serial_no))
|
with_valuation_rate=True , with_serial_no=cint(d.has_serial_no))
|
||||||
|
qty, valuation_rate, serial_no = stock_bal[0], stock_bal[1], stock_bal[2] if cint(d.has_serial_no) else ''
|
||||||
|
|
||||||
args = get_item_data(d, stock_bal[0], stock_bal[1],
|
if ignore_empty_stock and not stock_bal[0]:
|
||||||
stock_bal[2] if cint(d.has_serial_no) else '')
|
continue
|
||||||
|
|
||||||
|
args = get_item_data(d, qty, valuation_rate, serial_no)
|
||||||
|
|
||||||
res.append(args)
|
res.append(args)
|
||||||
|
|
||||||
@@ -516,24 +523,44 @@ def get_items(warehouse, posting_date, posting_time, company, item_code=None):
|
|||||||
|
|
||||||
def get_items_for_stock_reco(warehouse, company):
|
def get_items_for_stock_reco(warehouse, company):
|
||||||
lft, rgt = frappe.db.get_value("Warehouse", warehouse, ["lft", "rgt"])
|
lft, rgt = frappe.db.get_value("Warehouse", warehouse, ["lft", "rgt"])
|
||||||
items = frappe.db.sql("""
|
items = frappe.db.sql(f"""
|
||||||
select i.name as item_code, i.item_name, bin.warehouse as warehouse, i.has_serial_no, i.has_batch_no
|
select
|
||||||
from tabBin bin, tabItem i
|
i.name as item_code, i.item_name, bin.warehouse as warehouse, i.has_serial_no, i.has_batch_no
|
||||||
where i.name=bin.item_code and IFNULL(i.disabled, 0) = 0 and i.is_stock_item = 1
|
from
|
||||||
and i.has_variants = 0 and exists(
|
tabBin bin, tabItem i
|
||||||
select name from `tabWarehouse` where lft >= %s and rgt <= %s and name=bin.warehouse
|
where
|
||||||
)
|
i.name = bin.item_code
|
||||||
""", (lft, rgt), as_dict=1)
|
and IFNULL(i.disabled, 0) = 0
|
||||||
|
and i.is_stock_item = 1
|
||||||
|
and i.has_variants = 0
|
||||||
|
and exists(
|
||||||
|
select name from `tabWarehouse` where lft >= {lft} and rgt <= {rgt} and name = bin.warehouse
|
||||||
|
)
|
||||||
|
""", as_dict=1)
|
||||||
|
|
||||||
items += frappe.db.sql("""
|
items += frappe.db.sql("""
|
||||||
select i.name as item_code, i.item_name, id.default_warehouse as warehouse, i.has_serial_no, i.has_batch_no
|
select
|
||||||
from tabItem i, `tabItem Default` id
|
i.name as item_code, i.item_name, id.default_warehouse as warehouse, i.has_serial_no, i.has_batch_no
|
||||||
where i.name = id.parent
|
from
|
||||||
and exists(select name from `tabWarehouse` where lft >= %s and rgt <= %s and name=id.default_warehouse)
|
tabItem i, `tabItem Default` id
|
||||||
and i.is_stock_item = 1 and i.has_variants = 0 and IFNULL(i.disabled, 0) = 0 and id.company=%s
|
where
|
||||||
|
i.name = id.parent
|
||||||
|
and exists(
|
||||||
|
select name from `tabWarehouse` where lft >= %s and rgt <= %s and name=id.default_warehouse
|
||||||
|
)
|
||||||
|
and i.is_stock_item = 1
|
||||||
|
and i.has_variants = 0
|
||||||
|
and IFNULL(i.disabled, 0) = 0
|
||||||
|
and id.company = %s
|
||||||
group by i.name
|
group by i.name
|
||||||
""", (lft, rgt, company), as_dict=1)
|
""", (lft, rgt, company), as_dict=1)
|
||||||
|
|
||||||
|
# remove duplicates
|
||||||
|
# check if item-warehouse key extracted from each entry exists in set iw_keys
|
||||||
|
# and update iw_keys
|
||||||
|
iw_keys = set()
|
||||||
|
items = [item for item in items if [(item.item_code, item.warehouse) not in iw_keys, iw_keys.add((item.item_code, item.warehouse))][0]]
|
||||||
|
|
||||||
return items
|
return items
|
||||||
|
|
||||||
def get_item_data(row, qty, valuation_rate, serial_no=None):
|
def get_item_data(row, qty, valuation_rate, serial_no=None):
|
||||||
|
|||||||
Reference in New Issue
Block a user