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

fix: allow creating stock entry based on work order for customer provided items #24885

Merged
merged 2 commits into from Mar 26, 2021

Conversation

sagarvora
Copy link
Member

@sagarvora sagarvora commented Mar 15, 2021

Earlier PR: #24753


Allows creation of Stock Entry based on Work Order if items are customer provided (valuation rate is zero).
This used to work previously, but since #24031 it throws below traceback:

Traceback (most recent call last):
  File "/home/walstan/Work/develop/apps/frappe/frappe/app.py", line 67, in application
    response = frappe.api.handle()
  File "/home/walstan/Work/develop/apps/frappe/frappe/api.py", line 58, in handle
    return frappe.handler.handle()
  File "/home/walstan/Work/develop/apps/frappe/frappe/handler.py", line 30, in handle
    data = execute_cmd(cmd)
  File "/home/walstan/Work/develop/apps/frappe/frappe/handler.py", line 70, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "/home/walstan/Work/develop/apps/frappe/frappe/__init__.py", line 1136, in call
    return fn(*args, **newargs)
  File "/home/walstan/Work/develop/apps/erpnext/erpnext/manufacturing/doctype/work_order/work_order.py", line 790, in make_stock_entry
    stock_entry.get_items()
  File "/home/walstan/Work/develop/apps/erpnext/erpnext/stock/doctype/stock_entry/stock_entry.py", line 1013, in get_items
    self.calculate_rate_and_amount(raise_error_if_no_rate=False)
  File "/home/walstan/Work/develop/apps/erpnext/erpnext/stock/doctype/stock_entry/stock_entry.py", line 449, in calculate_rate_and_amount
    self.set_basic_rate(reset_outgoing_rate, raise_error_if_no_rate)
  File "/home/walstan/Work/develop/apps/erpnext/erpnext/stock/doctype/stock_entry/stock_entry.py", line 461, in set_basic_rate
    outgoing_items_cost = self.set_rate_for_outgoing_items(reset_outgoing_rate)
  File "/home/walstan/Work/develop/apps/erpnext/erpnext/stock/doctype/stock_entry/stock_entry.py", line 491, in set_rate_for_outgoing_items
    rate = get_incoming_rate(args)
  File "/home/walstan/Work/develop/apps/erpnext/erpnext/stock/utils.py", line 210, in get_incoming_rate
    in_rate = get_valuation_rate(args.get('item_code'), args.get('warehouse'),
  File "/home/walstan/Work/develop/apps/erpnext/erpnext/stock/stock_ledger.py", line 805, in get_valuation_rate
    frappe.throw(msg=msg, title=_("Valuation Rate Missing"))
  File "/home/walstan/Work/develop/apps/frappe/frappe/__init__.py", line 416, in throw
    msgprint(msg, raise_exception=exc, title=title, indicator='red', is_minimizable=is_minimizable, wide=wide, as_list=as_list)
  File "/home/walstan/Work/develop/apps/frappe/frappe/__init__.py", line 395, in msgprint
    _raise_exception()
  File "/home/walstan/Work/develop/apps/frappe/frappe/__init__.py", line 349, in _raise_exception
    raise raise_exception(msg)
frappe.exceptions.ValidationError: Valuation Rate for the Item <a href="http://127.0.0.1:8010/app/item/Test%20Item">Test Item</a>, is required to do accounting entries for Stock Entry .<br><br> Here are the options to proceed:<li>If the item is transacting as a Zero Valuation Rate item in this entry, please enable 'Allow Zero Valuation Rate' in the Stock Entry Item table.</li><li>If not, you can Cancel / Submit this entry <b>after</b> performing either one below:</li><ul><li>Create an incoming stock transaction for the Item.</li><li>Mention Valuation Rate in the Item master.</li></ul></li>

image


Changes Made

  • Run validate_customer_provided_item method in get_items.
  • Remove raise_error_if_no_rate param from call to get_customer_provided_items in get_items.
  • Keep earlier fix to ensure raise_error_if_no_rate works, since it is still being used in Stock Ledger.
  • Add Test Cases

Steps to Replicate

  1. Create a customer provided item.
  2. Create a BOM and corresponding Work Order where above item is a required item.
  3. Try creating a Stock Entry from such Work Order.

It is true that this error does not get thrown if at least one Stock Ledger entry exists (for this customer provided item at the source warehouse) when trying to create a Stock Entry. But this may not always be the case. Take following scenarios:

  • Customer provides items in phases, and manufacturing can be started with some of these items. In this case, above error will be raised for items not yet provided by Customer.
  • Company allows negative stock, and the entry for inward of customer provided item is being done by someone else at a later stage.

@sagarvora sagarvora added the squash Meant to tell reviewers that this PR should be squashed into a single commit while merging. label Mar 26, 2021
@sagarvora sagarvora merged commit 0b569b3 into frappe:develop Mar 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
squash Meant to tell reviewers that this PR should be squashed into a single commit while merging.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants