diff --git a/erpnext/manufacturing/doctype/work_order/work_order.py b/erpnext/manufacturing/doctype/work_order/work_order.py index a636b871e2..24b798b04c 100644 --- a/erpnext/manufacturing/doctype/work_order/work_order.py +++ b/erpnext/manufacturing/doctype/work_order/work_order.py @@ -213,6 +213,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.production_plan: self.update_production_plan_status() diff --git a/erpnext/patches.txt b/erpnext/patches.txt index a001d168be..722baaf622 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -636,4 +636,5 @@ erpnext.patches.v12_0.generate_leave_ledger_entries erpnext.patches.v12_0.move_credit_limit_to_customer_credit_limit erpnext.patches.v12_0.add_variant_of_in_item_attribute_table erpnext.patches.v12_0.rename_bank_account_field_in_journal_entry_account -erpnext.patches.v12_0.create_default_energy_point_rules \ No newline at end of file +erpnext.patches.v12_0.create_default_energy_point_rules +erpnext.patches.v12_0.set_produced_qty_field_in_sales_order_for_work_order diff --git a/erpnext/patches/v12_0/set_produced_qty_field_in_sales_order_for_work_order.py b/erpnext/patches/v12_0/set_produced_qty_field_in_sales_order_for_work_order.py new file mode 100644 index 0000000000..44d8fa767a --- /dev/null +++ b/erpnext/patches/v12_0/set_produced_qty_field_in_sales_order_for_work_order.py @@ -0,0 +1,10 @@ +import frappe +from frappe.utils import flt +from erpnext.selling.doctype.sales_order.sales_order import update_produced_qty_in_so_item + +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')) \ No newline at end of file diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py index 12b9a8e96d..e60be5a216 100755 --- a/erpnext/selling/doctype/sales_order/sales_order.py +++ b/erpnext/selling/doctype/sales_order/sales_order.py @@ -1023,3 +1023,15 @@ def create_pick_list(source_name, target_doc=None): doc.set_item_locations() return doc + +def update_produced_qty_in_so_item(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, + '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')) + frappe.db.set_value('Sales Order Item', sales_order_item, 'produced_qty', total_produced_qty) \ No newline at end of file diff --git a/erpnext/selling/doctype/sales_order_item/sales_order_item.json b/erpnext/selling/doctype/sales_order_item/sales_order_item.json index 01dfc7d084..b94dce15ab 100644 --- a/erpnext/selling/doctype/sales_order_item/sales_order_item.json +++ b/erpnext/selling/doctype/sales_order_item/sales_order_item.json @@ -110,6 +110,7 @@ "read_only": 1 }, { + "default": "0", "fieldname": "ensure_delivery_based_on_produced_serial_no", "fieldtype": "Check", "label": "Ensure Delivery Based on Produced Serial No" @@ -381,6 +382,7 @@ "read_only": 1 }, { + "default": "0", "fieldname": "is_free_item", "fieldtype": "Check", "label": "Is Free Item", @@ -436,6 +438,7 @@ "print_hide": 1 }, { + "default": "0", "fieldname": "delivered_by_supplier", "fieldtype": "Check", "label": "Supplier delivers to Customer", @@ -662,6 +665,7 @@ }, { "allow_on_submit": 1, + "default": "0", "fieldname": "page_break", "fieldtype": "Check", "label": "Page Break", @@ -689,7 +693,6 @@ "description": "For Production", "fieldname": "produced_qty", "fieldtype": "Float", - "hidden": 1, "label": "Produced Quantity", "oldfieldname": "produced_qty", "oldfieldtype": "Currency", @@ -740,7 +743,7 @@ ], "idx": 1, "istable": 1, - "modified": "2019-05-01 17:52:32.810797", + "modified": "2019-09-13 12:18:54.903107", "modified_by": "Administrator", "module": "Selling", "name": "Sales Order Item",