frappe / erpnext

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

same SN or Serial Numbers cannot be used to different item Code #34076

Closed Ponyooooo closed 1 year ago

Ponyooooo commented 1 year ago

Information about bug

Cannot sumbit a purchase receipt or stock entry if a serial number is already used or encoded on the serial number to a specific item code already.

However there is a scenario that two item code has the same format of the serial numbers.

The Bug is saying: Serial No 00003 does not belong to Item MICROWAVE -3

image

Module

stock

Version

ERPNext: v13.45.0 (HEAD) Frappe Framework: v13.49.0 (HEAD)

Installation method

FrappeCloud

Relevant log output / Stack trace / Full Error Message.

Traceback (most recent call last):
  File "apps/frappe/frappe/app.py", line 69, in application
    response = frappe.api.handle()
  File "apps/frappe/frappe/api.py", line 55, in handle
    return frappe.handler.handle()
  File "apps/frappe/frappe/handler.py", line 38, in handle
    data = execute_cmd(cmd)
  File "apps/frappe/frappe/handler.py", line 76, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "apps/frappe/frappe/__init__.py", line 1473, in call
    return fn(*args, **newargs)
  File "apps/frappe/frappe/desk/form/save.py", line 22, in savedocs
    doc.submit()
  File "apps/frappe/frappe/model/document.py", line 1020, in submit
    return self._submit()
  File "apps/frappe/frappe/model/document.py", line 1009, in _submit
    return self.save()
  File "apps/frappe/frappe/model/document.py", line 312, in save
    return self._save(*args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 366, in _save
    self.run_post_save_methods()
  File "apps/frappe/frappe/model/document.py", line 1090, in run_post_save_methods
    self.run_method("on_submit")
  File "apps/frappe/frappe/model/document.py", line 943, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1264, in composer
    return composed(self, method, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1246, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "apps/frappe/frappe/model/document.py", line 940, in fn
    return method_object(*args, **kwargs)
  File "apps/erpnext/erpnext/stock/doctype/stock_entry/stock_entry.py", line 134, in on_submit
    self.update_stock_ledger()
  File "apps/erpnext/erpnext/stock/doctype/stock_entry/stock_entry.py", line 1037, in update_stock_ledger
    self.make_sl_entries(sl_entries)
  File "apps/erpnext/erpnext/controllers/stock_controller.py", line 426, in make_sl_entries
    make_sl_entries(sl_entries, allow_negative_stock, via_landed_cost_voucher)
  File "apps/erpnext/erpnext/stock/stock_ledger.py", line 73, in make_sl_entries
    sle_doc = make_entry(sle, allow_negative_stock, via_landed_cost_voucher)
  File "apps/erpnext/erpnext/stock/stock_ledger.py", line 198, in make_entry
    sle.submit()
  File "apps/frappe/frappe/model/document.py", line 1020, in submit
    return self._submit()
  File "apps/frappe/frappe/model/document.py", line 1009, in _submit
    return self.save()
  File "apps/frappe/frappe/model/document.py", line 312, in save
    return self._save(*args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 334, in _save
    return self.insert()
  File "apps/frappe/frappe/model/document.py", line 293, in insert
    self.run_post_save_methods()
  File "apps/frappe/frappe/model/document.py", line 1090, in run_post_save_methods
    self.run_method("on_submit")
  File "apps/frappe/frappe/model/document.py", line 943, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1264, in composer
    return composed(self, method, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1246, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "apps/frappe/frappe/model/document.py", line 940, in fn
    return method_object(*args, **kwargs)
  File "apps/erpnext/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py", line 59, in on_submit
    process_serial_no(self)
  File "apps/erpnext/erpnext/stock/doctype/serial_no/serial_no.py", line 298, in process_serial_no
    validate_serial_no(sle, item_det)
  File "apps/erpnext/erpnext/stock/doctype/serial_no/serial_no.py", line 357, in validate_serial_no
    SerialNoItemError,
  File "apps/frappe/frappe/__init__.py", line 511, in throw
    as_list=as_list,
  File "apps/frappe/frappe/__init__.py", line 479, in msgprint
    _raise_exception()
  File "apps/frappe/frappe/__init__.py", line 434, in _raise_exception
    raise raise_exception(msg)
erpnext.stock.doctype.serial_no.serial_no.SerialNoItemError: Serial No 00003 does not belong to Item MICROWAVE -3
s-aga-r commented 1 year ago

@Ponyooooo please provide steps to replicate.

Ponyooooo commented 1 year ago

Example scenarios:

First

I have 2 different Item Codes:

Microwave - 1 Microwave -2

Purchased item code Microwave - 1 to Manufacturer 1 with SN 0001

and then Purchased item code Microwave - 2 to Manufacturer 2 with SN 0001

Both the manufacturers started their SN on 0001

Result: when encoded on a different purchase receipt, the second purchase receipt to be submitted is not allowed since the SN was already used for the first purchase receipt.

Second

I have 2 different Item Codes:

Oven Stove

Purchased item code Oven and Stove to Manufacturer 3 and then submitted the following purchase receipt:

  1. Submit SN 004 to item code Oven and SN 0010 to Item code Stove
  2. But I have realized after submitting the purchase receipt I have mis matched the SNs. 0004 should be for Stove and SN 0010 for Oven. So after saving the amended transaction (or I have cancelled the original purchase receipt and created another purchase receipt) when I need to submit the document the system will have an error message that SN 004 does not belong to item code Stove.

Result: I cannot cancel and amend or create another document to replace or interchange the used SN.

s-aga-r commented 1 year ago

So, it's a known issue, we will consider in somewhere near future. It will be a breaking change and the entire code related to Serial Nos needs to be rewritten. Ideally, you should use a different naming prefix for each item.