Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work Order throws Overproduction Error if Item exists multiple times in Sales Order #37497

Closed
ophl55 opened this issue Oct 13, 2023 · 4 comments
Assignees
Labels

Comments

@ophl55
Copy link

ophl55 commented Oct 13, 2023

Information about bug

Problem

In case "Allow Item to be Added Multiple Times in a Transaction" is enabled in the Selling Settings it is possible to add an item mutliple times to the Sales Order.

Bild_2023-10-13_141133808

Now you can use the Production Plan to generate Work Orders for that Sales Order. The Production Plan then sums up the quantities of the multiple positions of the item and creates one Work Order.

image

On saving the Work Order the validation for overproduction is triggered. The qty to produce of the Work Order is the sum of the multiple positions of the item. Therefore it exceeds the qty to produce of the single position in the Production Plan. Hence the Overproduction Error is thrown.

image

Possible Solution

A possible solution is not to sum up the quantities of the multiple positions. Instead create a Work Order for each position in the Production Plan.

Change line 576 of erpnext/manufacturing/doctype/production_plan/productan_plan.py from
item_dict[(d.item_code, d.sales_order, d.warehouse)] = item_details to
item_dict[(d.sales_order_item, d.sales_order, d.warehouse)] = item_details would do the trick.

Then you will receive a Work Order for each Sales Order Item and all links and validations shall work out-of-the-box as expected.

Module

manufacturing

Version

ERPNext: v14.44.0 (HEAD)
Frappe Framework: v14.52.0 (HEAD)
Frappe HR: v14.13.1 (HEAD)
Payments: v0.0.1 (version-14)

Installation method

docker

Relevant log output / Stack trace / Full Error Message.

File "apps/frappe/frappe/app.py", line 95, in application
    response = frappe.api.handle()
  File "apps/frappe/frappe/api.py", line 54, in handle
    return frappe.handler.handle()
  File "apps/frappe/frappe/handler.py", line 47, 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 1622, in call
    return fn(*args, **newargs)
  File "apps/frappe/frappe/desk/form/save.py", line 28, in savedocs
    doc.save()
  File "apps/frappe/frappe/model/document.py", line 307, in save
    return self._save(*args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 341, in _save
    self.run_before_save_methods()
  File "apps/frappe/frappe/model/document.py", line 1053, in run_before_save_methods
    self.run_method("validate")
  File "apps/frappe/frappe/model/document.py", line 917, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1279, in composer
    return composed(self, method, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1261, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "apps/frappe/frappe/model/document.py", line 914, in fn
    return method_object(*args, **kwargs)
  File "apps/erpnext/erpnext/manufacturing/doctype/work_order/work_order.py", line 86, in validate
    self.validate_qty()
  File "apps/erpnext/erpnext/manufacturing/doctype/work_order/work_order.py", line 832, in validate_qty
    frappe.throw(
  File "apps/frappe/frappe/__init__.py", line 534, in throw
    msgprint(
  File "apps/frappe/frappe/__init__.py", line 502, in msgprint
    _raise_exception()
  File "apps/frappe/frappe/__init__.py", line 451, in _raise_exception
    raise raise_exception(msg)
erpnext.manufacturing.doctype.work_order.work_order.OverProductionError: Cannot produce more than 1.0 items for 7150001
@ophl55 ophl55 added the bug label Oct 13, 2023
@ophl55 ophl55 changed the title Work Order throws Overrproduction Error if Item exists multiple times in Sales Order Work Order throws Overproduction Error if Item exists multiple times in Sales Order Oct 13, 2023
@ophl55
Copy link
Author

ophl55 commented Oct 13, 2023

Actually I think in most cases it is the desired behaviour to have one work order for each sales order position. This is of value for instance if each sales order item has a different delivery date.

@ophl55
Copy link
Author

ophl55 commented Oct 18, 2023

@rohitwaghchaure Can you maybe please check the issue?

I suppose that minor changes to the code lead to an overall enhancement of the manufacturing module.

Maybe that an if-else-branch is needed to check if the item to produce is linked to an Sales Order Item, since you can also use the Production Plan without the linking against a Sales Order.

@ophl55
Copy link
Author

ophl55 commented Nov 7, 2023

@s-aga-r @rohitwaghchaure

Sorry that I post the possible solution here. If I find some time I will learn how to create proper pull requests for frappe/erpnext.
Here the modified code for the method get_production_items() of erpnext/manufacturing/doctype/production_plan/productan_plan.py:

              # Begin of modification
              # Check if sales_order_item exists which means that the item is linked to a sales order
              if None is not d.sales_order_item:
                  # Treat each position of sales order individually so that generated work orders do not run into an overproduction error
                  # See https://github.com/frappe/erpnext/issues/37497 for further information
                  item_dict[(d.sales_order_item, d.sales_order, d.warehouse)] = item_details
              else:
                  # Go on with default core method procedure to process items without a link to a sales order
                  item_dict[(d.item_code, d.sales_order, d.warehouse)] = item_details
              # End of modification

The solution works like a charm and enables the Production Plan to fulfill the feature "Allow Item to be Added Multiple Times in a Transaction" of the Selling module. Would be great if you guys could have a look and maybe merge the modification into the core code.

@rohitwaghchaure rohitwaghchaure self-assigned this Jan 8, 2024
@rohitwaghchaure
Copy link
Collaborator

@ophl55 We have identified and fixed the issue and we'll release the fix tomorrow.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants