adjust stock_qty for expired quantities

adjust based on warehouse

add parameters to `get_qty_in_stock` so it can be useful in other parts of the code base
This commit is contained in:
tundebabzy
2018-01-27 06:28:29 +01:00
parent 186bea6e95
commit c14f1f145b
2 changed files with 68 additions and 4 deletions

View File

@@ -9,6 +9,7 @@ from frappe.utils.nestedset import NestedSet
from frappe.website.website_generator import WebsiteGenerator
from frappe.website.render import clear_cache
from frappe.website.doctype.website_slideshow.website_slideshow import get_slideshow
from erpnext.utilities.product import get_qty_in_stock
class ItemGroup(NestedSet, WebsiteGenerator):
@@ -83,7 +84,8 @@ def get_product_list_for_group(product_group=None, start=0, limit=10, search=Non
# base query
query = """select I.name, I.item_name, I.item_code, I.route, I.image, I.website_image, I.thumbnail, I.item_group,
I.description, I.web_long_description as website_description, I.is_stock_item,
case when (S.actual_qty - S.reserved_qty) > 0 then 1 else 0 end as in_stock
case when (S.actual_qty - S.reserved_qty) > 0 then 1 else 0 end as in_stock, I.website_warehouse,
I.has_batch_no
from `tabItem` I
left join tabBin S on I.item_code = S.item_code and I.website_warehouse = S.warehouse
where I.show_in_website = 1
@@ -104,8 +106,26 @@ def get_product_list_for_group(product_group=None, start=0, limit=10, search=Non
data = frappe.db.sql(query, {"product_group": product_group,"search": search, "today": nowdate()}, as_dict=1)
data = adjust_for_expired_items(data)
return [get_item_for_list_in_html(r) for r in data]
def adjust_for_expired_items(data):
adjusted_data = []
for item in data:
if item.get('has_batch_no') and item.get('website_warehouse'):
stock_qty_dict = get_qty_in_stock(
item.get('name'), 'website_warehouse', item.get('website_warehouse'))
qty = stock_qty_dict.stock_qty[0][0]
item['in_stock'] = 1 if qty else 0
adjusted_data.append(item)
return adjusted_data
def get_child_groups(item_group_name):
item_group = frappe.get_doc("Item Group", item_group_name)
return frappe.db.sql("""select name