fix: exclude spurious Stock Entry Types from 'consumed' calculation (#25352)

* fix: exclude spurious 'Stock Entry Type's from 'consumed' calculation

* fix: filter using purpose, make requested changes

Co-authored-by: Ankush Menat <ankush@iwebnotes.com>
This commit is contained in:
Alan 2021-04-19 12:38:25 +05:30 committed by GitHub
parent 6c88ab07c7
commit ac8a467b0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -55,19 +55,31 @@ def get_item_info(filters):
def get_consumed_items(condition):
purpose_to_exclude = [
"Material Transfer for Manufacture",
"Material Transfer",
"Send to Subcontractor"
]
condition += """
and (
purpose is NULL
or purpose not in ({})
)
""".format(', '.join([f"'{p}'" for p in purpose_to_exclude]))
condition = condition.replace("posting_date", "sle.posting_date")
consumed_items = frappe.db.sql("""
select item_code, abs(sum(actual_qty)) as consumed_qty
from `tabStock Ledger Entry`
where actual_qty < 0
from `tabStock Ledger Entry` as sle left join `tabStock Entry` as se
on sle.voucher_no = se.name
where
actual_qty < 0
and voucher_type not in ('Delivery Note', 'Sales Invoice')
%s
group by item_code
""" % condition, as_dict=1)
consumed_items_map = {}
for item in consumed_items:
consumed_items_map.setdefault(item.item_code, item.consumed_qty)
group by item_code""" % condition, as_dict=1)
consumed_items_map = {item.item_code : item.consumed_qty for item in consumed_items}
return consumed_items_map
def get_delivered_items(condition):