frappe / erpnext

Free and Open Source Enterprise Resource Planning (ERP)
https://erpnext.com
GNU General Public License v3.0
21.92k stars 7.34k forks source link

Finishing Work Order with serial numbers results in ValueError #41798

Closed casesolved-co-uk closed 1 month ago

casesolved-co-uk commented 5 months ago

Information about bug

See tests reproducing the issue: https://github.com/frappe/erpnext/pull/41814

It appears get_available_materials has been poorly written and not properly tested.

The code on inspection tries to remove a serial number from a list that has not been populated.

item_data.serial_nos.remove(serial_no) and yet serial_nos is initialised above to an empty list: {"item_details": row, "batch_details": defaultdict(float), "qty": 0, "serial_nos": []}

Module

stock, manufacturing

Version

"erpnext": "15.22.2", "frappe": "15.26.0",

Installation method

None

Relevant log output / Stack trace / Full Error Message.

### App Versions

{
    "erpnext": "15.22.2",
    "frappe": "15.26.0",
    "hrms": "15.14.1",
    "payments": "0.0.1",
    "quickfile_sync": "15.0.1",
    "uk": "14.3.1"
}

Route

Form/Work Order/MFG-WO-2024-00010

Traceback

Traceback (most recent call last):
  File "apps/frappe/frappe/app.py", line 110, in application
    response = frappe.api.handle(request)
  File "apps/frappe/frappe/api/__init__.py", line 49, in handle
    data = endpoint(**arguments)
  File "apps/frappe/frappe/api/v1.py", line 36, in handle_rpc_call
    return frappe.handler.handle()
  File "apps/frappe/frappe/handler.py", line 49, in handle
    data = execute_cmd(cmd)
  File "apps/frappe/frappe/handler.py", line 85, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "apps/frappe/frappe/__init__.py", line 1768, in call
    return fn(*args, **newargs)
  File "apps/frappe/frappe/utils/typing_validations.py", line 31, in wrapper
    return func(*args, **kwargs)
  File "apps/erpnext/erpnext/manufacturing/doctype/work_order/work_order.py", line 1393, in make_stock_entry
    stock_entry.get_items()
  File "apps/frappe/frappe/utils/typing_validations.py", line 31, in wrapper
    return func(*args, **kwargs)
  File "apps/erpnext/erpnext/stock/doctype/stock_entry/stock_entry.py", line 1751, in get_items
    self.add_transfered_raw_materials_in_items()
  File "apps/erpnext/erpnext/stock/doctype/stock_entry/stock_entry.py", line 2137, in add_transfered_raw_materials_in_items
    available_materials = get_available_materials(self.work_order)
  File "apps/erpnext/erpnext/stock/doctype/stock_entry/stock_entry.py", line 3068, in get_available_materials
    item_data.serial_nos.remove(serial_no)
ValueError: list.remove(x): x not in list

Request Data

{
    "type": "POST",
    "args": {
        "work_order_id": "MFG-WO-2024-00010",
        "purpose": "Manufacture",
        "qty": 2
    },
    "headers": {},
    "error_handlers": {},
    "url": "/api/method/erpnext.manufacturing.doctype.work_order.work_order.make_stock_entry",
    "request_id": null
}

Response Data

{
    "exception": "ValueError: list.remove(x): x not in list",
    "exc_type": "ValueError",
    "_exc_source": "erpnext (app)"
}
casesolved-co-uk commented 5 months ago

Appears to be introduced here: https://github.com/frappe/erpnext/commit/333c62de72b1e47a15285b463ec6715cbf46bc40 @rohitwaghchaure

casesolved-co-uk commented 1 month ago

@toofun666 Can you confirm you have seen this?

toofun666 commented 1 month ago

@toofun666 Can you confirm you have seen this?

Sure thing. A few glitches remain but mostly the mystery's been solved. Need more effort though but we can push this.