-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
Information about bug
This is a duplicate/reopen of #50673, with more information and possible solution:
It still occurs in v16.6.0/v16.5.0
Steps to reproduce:
- Enable automatic creation of subcontracting order
- Create a service item for subcontracting (Group Services, Maintain Stock=no)
- Create an item (is subcontracted=yes)
- Create a BOM, add a material, and submit
- Create a subcontracting BOM (finished good=new item, service item=new service item)
- Create a new material request (purpose = Subcontracting) for said item and submit
- Use the action button in the top right (Create -> Subcontracted Purchase Order)
- Create the purchase order, select a supplier and supplier warehouse and submit
- Open the new subcontracting order that was just created and try to submit it
The bug will only happen when there is a material request connected to the purchase order item in the Reference -> material_request field of the purchase order item.
Result:
It will throw the same error as in the original issue
MySQLdb.OperationalError: (1054, "Unknown column 'fg_item_qty' in 'SELECT'")
Debugging:
The query in this line causes the error:
https://github.com/frappe/erpnext/blob/390294a92bb8bfc8f22088435e0d8ec980774464/erpnext/controllers/status_updater.py#L547C2-L556C6
Debugging shows that the query it tries to execute and fails is:
(select ifnull(sum(fg_item_qty), 0)
from `tabSubcontracting Order Item` where `material_request_item`='ko04vu2k99'
and (docstatus=1 or parent='SC-ORD-2026-00002') )
The reason is that "fg_item_qty" does not exist in "Subcontracting Order Item", and the correct DocType should be "Subcontracting Order Service Item"?
Possible Solution
It seems the bug can be solved by changing
erpnext/erpnext/controllers/status_updater.py
Line 519 in 390294a
| args.update({"source_field": "fg_item_qty"}) |
to
args.update({"source_field": "fg_item_qty",'source_dt':'Subcontracting Order Service Item'})
If someone can confirm this does not break anything else, I can submit a PR.
Module
manufacturing
Version
Frappe Framework: v16.6.0 (version-16)
ERPNext: v16.5.0 (version-16)
Installation method
docker
Relevant log output / Stack trace / Full Error Message.
See #50673
11:04:54 web.1 | Traceback (most recent call last):
11:04:54 web.1 | File "apps/frappe/frappe/app.py", line 121, in application
11:04:54 web.1 | response = frappe.api.handle(request)
11:04:54 web.1 | File "apps/frappe/frappe/api/__init__.py", line 63, in handle
11:04:54 web.1 | data = endpoint(**arguments)
11:04:54 web.1 | File "apps/frappe/frappe/api/v1.py", line 40, in handle_rpc_call
11:04:54 web.1 | return frappe.handler.handle()
11:04:54 web.1 | ~~~~~~~~~~~~~~~~~~~~~^^
11:04:54 web.1 | File "apps/frappe/frappe/handler.py", line 53, in handle
11:04:54 web.1 | data = execute_cmd(cmd)
11:04:54 web.1 | File "apps/frappe/frappe/handler.py", line 86, in execute_cmd
11:04:54 web.1 | return frappe.call(method, **frappe.form_dict)
11:04:54 web.1 | ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11:04:54 web.1 | File "apps/frappe/frappe/__init__.py", line 1124, in call
11:04:54 web.1 | return fn(*args, **newargs)
11:04:54 web.1 | File "apps/frappe/frappe/utils/typing_validations.py", line 36, in wrapper
11:04:54 web.1 | return func(*args, **kwargs)
11:04:54 web.1 | File "apps/frappe/frappe/desk/form/save.py", line 41, in savedocs
11:04:54 web.1 | doc.submit()
11:04:54 web.1 | ~~~~~~~~~~^^
11:04:54 web.1 | File "apps/frappe/frappe/utils/typing_validations.py", line 36, in wrapper
11:04:54 web.1 | return func(*args, **kwargs)
11:04:54 web.1 | File "apps/frappe/frappe/model/document.py", line 1270, in submit
11:04:54 web.1 | return self._submit()
11:04:54 web.1 | ~~~~~~~~~~~~^^
11:04:54 web.1 | File "apps/frappe/frappe/model/document.py", line 1251, in _submit
11:04:54 web.1 | return self.save()
11:04:54 web.1 | ~~~~~~~~~^^
11:04:54 web.1 | File "apps/frappe/frappe/model/document.py", line 518, in save
11:04:54 web.1 | return self._save(*args, **kwargs)
11:04:54 web.1 | ~~~~~~~~~~^^^^^^^^^^^^^^^^^
11:04:54 web.1 | File "apps/frappe/frappe/model/document.py", line 572, in _save
11:04:54 web.1 | self.run_post_save_methods()
11:04:54 web.1 | ~~~~~~~~~~~~~~~~~~~~~~~~~~^^
11:04:54 web.1 | File "apps/frappe/frappe/model/document.py", line 1378, in run_post_save_methods
11:04:54 web.1 | self.run_method("on_submit")
11:04:54 web.1 | ~~~~~~~~~~~~~~~^^^^^^^^^^^^^
11:04:54 web.1 | File "apps/frappe/frappe/model/document.py", line 1181, in run_method
11:04:54 web.1 | out = Document.hook(fn)(self, *args, **kwargs)
11:04:54 web.1 | File "apps/frappe/frappe/model/document.py", line 1578, in composer
11:04:54 web.1 | return composed(self, method, *args, **kwargs)
11:04:54 web.1 | File "apps/frappe/frappe/model/document.py", line 1556, in runner
11:04:54 web.1 | add_to_return_value(self, fn(self, *args, **kwargs))
11:04:54 web.1 | ~~^^^^^^^^^^^^^^^^^^^^^^^
11:04:54 web.1 | File "apps/frappe/frappe/model/document.py", line 1178, in fn
11:04:54 web.1 | return method_object(*args, **kwargs)
11:04:54 web.1 | File "apps/erpnext/erpnext/subcontracting/doctype/subcontracting_order/subcontracting_order.py", line 142, in on_submit
11:04:54 web.1 | self.update_prevdoc_status()
11:04:54 web.1 | ~~~~~~~~~~~~~~~~~~~~~~~~~~^^
11:04:54 web.1 | File "apps/erpnext/erpnext/controllers/status_updater.py", line 192, in update_prevdoc_status
11:04:54 web.1 | self.update_qty()
11:04:54 web.1 | ~~~~~~~~~~~~~~~^^
11:04:54 web.1 | File "apps/erpnext/erpnext/controllers/status_updater.py", line 503, in update_qty
11:04:54 web.1 | self._update_children(args, update_modified)
11:04:54 web.1 | ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
11:04:54 web.1 | File "apps/erpnext/erpnext/controllers/status_updater.py", line 552, in _update_children
11:04:54 web.1 | frappe.db.sql(
11:04:54 web.1 | ~~~~~~~~~~~~~^
11:04:54 web.1 | """
11:04:54 web.1 | ^^^
11:04:54 web.1 | ...<3 lines>...
11:04:54 web.1 | """.format(**args)
11:04:54 web.1 | ^^^^^^^^^^^^^^^^^^
11:04:54 web.1 | )[0][0]
11:04:54 web.1 | ^
11:04:54 web.1 | File "apps/frappe/frappe/database/database.py", line 272, in sql
11:04:54 web.1 | self.execute_query(query, values)
11:04:54 web.1 | ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
11:04:54 web.1 | File "apps/frappe/frappe/database/database.py", line 372, in execute_query
11:04:54 web.1 | return self._cursor.execute(query, values)
11:04:54 web.1 | ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
11:04:54 web.1 | File "env/lib/python3.14/site-packages/MySQLdb/cursors.py", line 179, in execute
11:04:54 web.1 | res = self._query(mogrified_query)
11:04:54 web.1 | File "env/lib/python3.14/site-packages/MySQLdb/cursors.py", line 330, in _query
11:04:54 web.1 | db.query(q)
11:04:54 web.1 | ~~~~~~~~^^^
11:04:54 web.1 | File "env/lib/python3.14/site-packages/MySQLdb/connections.py", line 280, in query
11:04:54 web.1 | _mysql.connection.query(self, query)
11:04:54 web.1 | ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
11:04:54 web.1 | MySQLdb.OperationalError: (1054, "Unknown column 'fg_item_qty' in 'SELECT'")
11:04:54 web.1 |