Fix status updater (#13033)

* fix the status updater for multiple sources

* patch for updating the status

* patch for updating the sales order item

* Update update_status_for_multiple_source_in_po.py
This commit is contained in:
Manas Solanki 2018-03-05 11:28:29 +05:30 committed by Nabin Hait
parent 35b665cb26
commit 5fd7b3bb80
7 changed files with 86 additions and 12 deletions

View File

@ -30,8 +30,7 @@ class PurchaseOrder(BuyingController):
'target_parent_field': 'per_ordered',
'target_ref_field': 'stock_qty',
'source_field': 'stock_qty',
'percent_join_field': 'material_request',
'overflow_type': 'order'
'percent_join_field': 'material_request'
}]
def onload(self):
@ -232,12 +231,16 @@ class PurchaseOrder(BuyingController):
pass
def update_status_updater(self):
self.status_updater[0].update({
"target_parent_dt": "Sales Order",
"target_dt": "Sales Order Item",
self.status_updater.append({
'source_dt': 'Purchase Order Item',
'target_dt': 'Sales Order Item',
'target_field': 'ordered_qty',
"join_field": "sales_order_item",
"target_parent_field": ''
'target_parent_dt': 'Sales Order',
'target_parent_field': '',
'join_field': 'sales_order_item',
'source_dt': 'Purchase Order Item',
'target_ref_field': 'stock_qty',
'source_field': 'stock_qty'
})
def update_delivered_qty_in_sales_order(self):

View File

@ -250,7 +250,7 @@ class StatusUpdater(Document):
if args['detail_id']:
if not args.get("extra_cond"): args["extra_cond"] = ""
frappe.db.sql("""update `tab%(target_dt)s`
set %(target_field)s = (
(select ifnull(sum(%(source_field)s), 0)
@ -275,7 +275,7 @@ class StatusUpdater(Document):
"""Update percent field in parent transaction"""
self._update_modified(args, update_modified)
if args.get('target_parent_field'):
frappe.db.sql("""update `tab%(target_parent_dt)s`
set %(target_parent_field)s = round(

View File

@ -490,6 +490,7 @@ erpnext.patches.v10_0.set_default_payment_terms_based_on_company
erpnext.patches.v10_0.update_sales_order_link_to_purchase_order
erpnext.patches.v10_0.added_extra_gst_custom_field_in_gstr2 #2018-02-13
erpnext.patches.v10_0.set_b2c_limit
erpnext.patches.v10_0.update_status_for_multiple_source_in_po
erpnext.patches.v10_0.set_auto_created_serial_no_in_stock_entry
erpnext.patches.v10_0.update_territory_and_customer_group
erpnext.patches.v10_0.update_warehouse_address_details

View File

@ -0,0 +1,38 @@
# Copyright (c) 2017, Frappe and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
# update the sales order item in the material request
frappe.reload_doc('stock', 'doctype', 'material_request_item')
frappe.db.sql('''update `tabMaterial Request Item` mri set sales_order_item = (select name from
`tabSales Order Item` soi where soi.parent=mri.sales_order and soi.item_code=mri.item_code) where docstatus = 1 and
ifnull(mri.sales_order, "")!=""
''')
# update the sales order item in the purchase order
frappe.db.sql('''update `tabPurchase Order Item` poi set sales_order_item = (select name from
`tabSales Order Item` soi where soi.parent=poi.sales_order and soi.item_code=poi.item_code) where docstatus = 1 and
ifnull(poi.sales_order, "")!=""
''')
# Update the status in material request and sales order
po_list = frappe.db.sql('''
select parent from `tabPurchase Order Item` where ifnull(material_request, "")!="" and
ifnull(sales_order, "")!="" and docstatus=1
''',as_dict=1)
for po in list(set([d.get("parent") for d in po_list if d.get("parent")])):
try:
po_doc = frappe.get_doc("Purchase Order", po)
# update the so in the status updater
po_doc.update_status_updater()
po_doc.update_qty(update_modified=False)
except Exception:
pass

View File

@ -435,6 +435,7 @@ def make_material_request(source_name, target_doc=None):
"Sales Order Item": {
"doctype": "Material Request Item",
"field_map": {
"name": "sales_order_item",
"parent": "sales_order",
"stock_uom": "uom",
"stock_qty": "qty"

View File

@ -241,7 +241,8 @@ def make_purchase_order(source_name, target_doc=None):
["parent", "material_request"],
["uom", "stock_uom"],
["uom", "uom"],
["sales_order", "sales_order"]
["sales_order", "sales_order"],
["sales_order_item", "sales_order_item"]
],
"postprocess": update_item,
"condition": lambda doc: doc.ordered_qty < doc.stock_qty

View File

@ -670,6 +670,36 @@
"set_only_once": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "sales_order_item",
"fieldtype": "Data",
"hidden": 1,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Sales Order Item",
"length": 0,
"no_copy": 1,
"permlevel": 0,
"precision": "",
"print_hide": 1,
"print_hide_if_no_value": 0,
"read_only": 1,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 1,
"set_only_once": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
@ -898,8 +928,8 @@
"issingle": 0,
"istable": 1,
"max_attachments": 0,
"modified": "2017-12-15 16:29:18.902085",
"modified_by": "nabinhait@gmail.com",
"modified": "2018-02-12 05:51:39.954530",
"modified_by": "Administrator",
"module": "Stock",
"name": "Material Request Item",
"owner": "Administrator",