mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-22 06:29:20 +00:00
fix(material-request): consider delivered qty for remaining qty calculation
(cherry picked from commit 88dd869a11)
This commit is contained in:
committed by
Mergify
parent
6e3394a6b1
commit
074faa162f
@@ -871,10 +871,33 @@ def make_material_request(source_name, target_doc=None):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def get_remaining_packed_item_qty(so_item):
|
||||||
|
delivered_qty = frappe.db.get_value(
|
||||||
|
"Sales Order Item", {"docstatus": 1, "name": so_item.parent_detail_docname}, ["delivered_qty"]
|
||||||
|
)
|
||||||
|
|
||||||
|
bundle_item_qty = frappe.db.get_value("Product Bundle Item", {"parent": so_item.parent_item}, ["qty"])
|
||||||
|
|
||||||
|
return flt(
|
||||||
|
(
|
||||||
|
flt(so_item.qty)
|
||||||
|
- flt(requested_item_qty.get(so_item.name, {}).get("qty"))
|
||||||
|
- max(
|
||||||
|
flt(delivered_qty) - flt(requested_item_qty.get(so_item.name, {}).get("received_qty")),
|
||||||
|
0,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
* bundle_item_qty
|
||||||
|
)
|
||||||
|
|
||||||
def update_item(source, target, source_parent):
|
def update_item(source, target, source_parent):
|
||||||
# qty is for packed items, because packed items don't have stock_qty field
|
# qty is for packed items, because packed items don't have stock_qty field
|
||||||
target.project = source_parent.project
|
target.project = source_parent.project
|
||||||
target.qty = get_remaining_qty(source)
|
target.qty = (
|
||||||
|
get_remaining_packed_item_qty(source)
|
||||||
|
if source.parentfield == "packed_items"
|
||||||
|
else get_remaining_qty(source)
|
||||||
|
)
|
||||||
target.stock_qty = flt(target.qty) * flt(target.conversion_factor)
|
target.stock_qty = flt(target.qty) * flt(target.conversion_factor)
|
||||||
target.actual_qty = get_bin_details(
|
target.actual_qty = get_bin_details(
|
||||||
target.item_code, target.warehouse, source_parent.company, True
|
target.item_code, target.warehouse, source_parent.company, True
|
||||||
@@ -905,7 +928,7 @@ def make_material_request(source_name, target_doc=None):
|
|||||||
"Packed Item": {
|
"Packed Item": {
|
||||||
"doctype": "Material Request Item",
|
"doctype": "Material Request Item",
|
||||||
"field_map": {"parent": "sales_order", "uom": "stock_uom", "name": "packed_item"},
|
"field_map": {"parent": "sales_order", "uom": "stock_uom", "name": "packed_item"},
|
||||||
"condition": lambda item: get_remaining_qty(item) > 0,
|
"condition": lambda item: get_remaining_packed_item_qty(item) > 0,
|
||||||
"postprocess": update_item,
|
"postprocess": update_item,
|
||||||
},
|
},
|
||||||
"Sales Order Item": {
|
"Sales Order Item": {
|
||||||
|
|||||||
Reference in New Issue
Block a user