fix: sales order item shwoing incorrect produced qty (#19584)
This commit is contained in:
parent
16f6ca12a7
commit
6424416886
@ -216,7 +216,9 @@ class WorkOrder(Document):
|
||||
self.db_set(fieldname, qty)
|
||||
|
||||
from erpnext.selling.doctype.sales_order.sales_order import update_produced_qty_in_so_item
|
||||
update_produced_qty_in_so_item(self.sales_order_item)
|
||||
|
||||
if self.sales_order and self.sales_order_item:
|
||||
update_produced_qty_in_so_item(self.sales_order, self.sales_order_item)
|
||||
|
||||
if self.production_plan:
|
||||
self.update_production_plan_status()
|
||||
|
@ -5,6 +5,10 @@ from erpnext.selling.doctype.sales_order.sales_order import update_produced_qty_
|
||||
def execute():
|
||||
frappe.reload_doctype('Sales Order Item')
|
||||
frappe.reload_doctype('Sales Order')
|
||||
sales_order_items = frappe.db.get_all('Sales Order Item', ['name'])
|
||||
for so_item in sales_order_items:
|
||||
update_produced_qty_in_so_item(so_item.get('name'))
|
||||
|
||||
for d in frappe.get_all('Work Order',
|
||||
fields = ['sales_order', 'sales_order_item'],
|
||||
filters={'sales_order': ('!=', ''), 'sales_order_item': ('!=', '')}):
|
||||
|
||||
# update produced qty in sales order
|
||||
update_produced_qty_in_so_item(d.sales_order, d.sales_order_item)
|
@ -1038,14 +1038,18 @@ def create_pick_list(source_name, target_doc=None):
|
||||
|
||||
return doc
|
||||
|
||||
def update_produced_qty_in_so_item(sales_order_item):
|
||||
def update_produced_qty_in_so_item(sales_order, sales_order_item):
|
||||
#for multiple work orders against same sales order item
|
||||
linked_wo_with_so_item = frappe.db.get_all('Work Order', ['produced_qty'], {
|
||||
'sales_order_item': sales_order_item,
|
||||
'sales_order': sales_order,
|
||||
'docstatus': 1
|
||||
})
|
||||
if len(linked_wo_with_so_item) > 0:
|
||||
|
||||
total_produced_qty = 0
|
||||
for wo in linked_wo_with_so_item:
|
||||
total_produced_qty += flt(wo.get('produced_qty'))
|
||||
|
||||
if not total_produced_qty and frappe.flags.in_patch: return
|
||||
|
||||
frappe.db.set_value('Sales Order Item', sales_order_item, 'produced_qty', total_produced_qty)
|
Loading…
Reference in New Issue
Block a user