fix: UOM fixes in Sales Order,Material Request & Production Plan

This commit is contained in:
marination 2020-03-20 17:49:59 +05:30
parent 2602c7ea38
commit 73c8d23a79
3 changed files with 7 additions and 13 deletions

View File

@ -144,7 +144,7 @@ class ProductionPlan(Document):
item_condition = " and mr_item.item_code ={0}".format(frappe.db.escape(self.item_code)) item_condition = " and mr_item.item_code ={0}".format(frappe.db.escape(self.item_code))
items = frappe.db.sql("""select distinct parent, name, item_code, warehouse, description, items = frappe.db.sql("""select distinct parent, name, item_code, warehouse, description,
(qty - ordered_qty) as pending_qty (qty - ordered_qty) * conversion_factor as pending_qty
from `tabMaterial Request Item` mr_item from `tabMaterial Request Item` mr_item
where parent in (%s) and docstatus = 1 and qty > ordered_qty where parent in (%s) and docstatus = 1 and qty > ordered_qty
and exists (select name from `tabBOM` bom where bom.item=mr_item.item_code and exists (select name from `tabBOM` bom where bom.item=mr_item.item_code

View File

@ -496,7 +496,7 @@ def close_or_unclose_sales_orders(names, status):
def get_requested_item_qty(sales_order): def get_requested_item_qty(sales_order):
return frappe._dict(frappe.db.sql(""" return frappe._dict(frappe.db.sql("""
select sales_order_item, sum(stock_qty) select sales_order_item, sum(qty)
from `tabMaterial Request Item` from `tabMaterial Request Item`
where docstatus = 1 where docstatus = 1
and sales_order = %s and sales_order = %s
@ -507,16 +507,12 @@ def get_requested_item_qty(sales_order):
def make_material_request(source_name, target_doc=None): def make_material_request(source_name, target_doc=None):
requested_item_qty = get_requested_item_qty(source_name) requested_item_qty = get_requested_item_qty(source_name)
def postprocess(source, doc):
doc.material_request_type = "Purchase"
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
qty = source.get("stock_qty") or source.get("qty") qty = source.get("qty")
target.project = source_parent.project target.project = source_parent.project
target.qty = qty - requested_item_qty.get(source.name, 0) target.qty = qty - requested_item_qty.get(source.name, 0)
target.conversion_factor = 1 target.stock_qty = flt(target.qty) * flt(target.conversion_factor)
target.stock_qty = qty - requested_item_qty.get(source.name, 0)
doc = get_mapped_doc("Sales Order", source_name, { doc = get_mapped_doc("Sales Order", source_name, {
"Sales Order": { "Sales Order": {
@ -537,14 +533,12 @@ def make_material_request(source_name, target_doc=None):
"doctype": "Material Request Item", "doctype": "Material Request Item",
"field_map": { "field_map": {
"name": "sales_order_item", "name": "sales_order_item",
"parent": "sales_order", "parent": "sales_order"
"stock_uom": "uom",
"stock_qty": "qty"
}, },
"condition": lambda doc: not frappe.db.exists('Product Bundle', doc.item_code) and doc.stock_qty > requested_item_qty.get(doc.name, 0), "condition": lambda doc: not frappe.db.exists('Product Bundle', doc.item_code) and doc.stock_qty > requested_item_qty.get(doc.name, 0),
"postprocess": update_item "postprocess": update_item
} }
}, target_doc, postprocess) }, target_doc)
return doc return doc

View File

@ -501,7 +501,7 @@ def raise_work_orders(material_request):
wo_order = frappe.new_doc("Work Order") wo_order = frappe.new_doc("Work Order")
wo_order.update({ wo_order.update({
"production_item": d.item_code, "production_item": d.item_code,
"qty": d.qty - d.ordered_qty, "qty": d.stock_qty - d.ordered_qty,
"fg_warehouse": d.warehouse, "fg_warehouse": d.warehouse,
"wip_warehouse": default_wip_warehouse, "wip_warehouse": default_wip_warehouse,
"description": d.description, "description": d.description,