frappe / erpnext

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

Item quantity can not be zero #23882

Closed kvt closed 1 year ago

kvt commented 3 years ago

Description of the issue

Error occurs while creating sales order when some of line items have 0 quantity in amazon order.

Context information (for bug reports)

Output of bench version

 $ bench version
WARN: bench is installed in editable mode!

This is not the recommended mode of installation for production. Instead, install the package from PyPI with: `pip install frappe-bench`

WARN: Command not being executed in bench directory
Usage: bench [OPTIONS] COMMAND [ARGS]...
Try "bench --help" for help.

Error: No such command "version".
$ bench --version
WARN: bench is installed in editable mode!

This is not the recommended mode of installation for production. Instead, install the package from PyPI with: `pip install frappe-bench`

WARN: Command not being executed in bench directory
5.2.1

Steps to reproduce the issue

Observed result

Expected result

Stacktrace / full error message

Traceback (most recent call last):
  File "/home/useuserr/frappe-bench/apps/erpnext/erpnext/erpnext_integrations/doctype/amazon_mws_settings/amazon_methods.py", line 309, in create_sales_order
    order_customer_name = order_json.BuyerName
  File "/home/user/frappe-bench/apps/frappe/frappe/model/document.py", line 867, in submit
    self._submit()
  File "/home/user/frappe-bench/apps/frappe/frappe/model/document.py", line 856, in _submit
    self.save()
  File "/home/user/frappe-bench/apps/frappe/frappe/model/document.py", line 273, in save
    return self._save(*args, **kwargs)
  File "/home/user/frappe-bench/apps/frappe/frappe/model/document.py", line 309, in _save
    self.run_before_save_methods()
  File "/home/user/frappe-bench/apps/frappe/frappe/model/document.py", line 900, in run_before_save_methods
    self.run_method("validate")
  File "/home/user/frappe-bench/apps/frappe/frappe/model/document.py", line 797, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "/home/user/frappe-bench/apps/frappe/frappe/model/document.py", line 1073, in composer
    return composed(self, method, *args, **kwargs)
  File "/home/user/frappe-bench/apps/frappe/frappe/model/document.py", line 1056, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "/home/user/frappe-bench/apps/frappe/frappe/model/document.py", line 791, in <lambda>
    fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
  File "/home/user/frappe-bench/apps/erpnext/erpnext/selling/doctype/sales_order/sales_order.py", line 36, in validate
    super(SalesOrder, self).validate()
  File "/home/user/frappe-bench/apps/erpnext/erpnext/controllers/selling_controller.py", line 40, in validate
    super(SellingController, self).validate()
  File "/home/user/frappe-bench/apps/erpnext/erpnext/controllers/stock_controller.py", line 21, in validate
    super(StockController, self).validate()
  File "/home/user/frappe-bench/apps/erpnext/erpnext/controllers/accounts_controller.py", line 68, in validate
    self.validate_qty_is_not_zero()
  File "/home/user/frappe-bench/apps/erpnext/erpnext/controllers/accounts_controller.py", line 435, in validate_qty_is_not_zero
    frappe.throw(_("Item quantity can not be zero"))
  File "/home/user/frappe-bench/apps/frappe/frappe/__init__.py", line 377, in throw
    msgprint(msg, raise_exception=exc, title=title, indicator='red', is_minimizable=is_minimizable)
  File "/home/user/frappe-bench/apps/frappe/frappe/__init__.py", line 356, in msgprint
    _raise_exception()
  File "/home/user/frappe-bench/apps/frappe/frappe/__init__.py", line 316, in _raise_exception
    raise raise_exception(msg)
frappe.exceptions.ValidationError: Item quantity can not be zero

Additional information

OS version / distribution, ERPNext install method, etc.

Ubuntu 20.04
Easy Install Script: ERPNext: v12.13.0 (version-12)
Frappe Framework: v12.11.0 (version-12)
kennethsequeira commented 3 years ago

@kvt the error message is pretty clear that you cannot add items with zero quantity be it via amazon or any other method (try creating one manually as well).

Why should this be tagged as a bug?

barredterra commented 3 years ago

@kvt by the way, bench version must be executed within the bench directory (for example, /home/frappe/frappe-bench) . Same goes for almost all bench commands. ;)

barredterra commented 3 years ago

@kennethsequeira amazon sends this information and ERPNext cannot handle it. That is a bug, right?

kennethsequeira commented 3 years ago

@barredterra looks like for integrations there need to be a way to handle this.

Basically, ERPNext will not let you create a quote/order/invoice with quantity 0. I imagine the validation was added for a purpose 😅.

landaverdelbo commented 3 years ago

{ "customer": "SOOOOOXYZ", "items": { "batch_id": "J-20-00048", "conversion_factor": 1.0, "stock_qty": 1, "description": "NADA", "item_code": "AVJ-130", "item_name": "JUGO DE SABILA", "qty": 1.0, "stock_uom": "Litre", "uom": "Litre" }, "sales_order": "SAL-ORD-2020-00001" }


ERROR

File \\"/home/erpnext/sabila-2/apps/erpnext/erpnext/controllers/accounts_controller.py\\", line 434, in validate_qty_is_not_zero\n if not item.qty:\nAttributeError: 'str' object has no attribute 'qty'\n\"]"

landaverdelbo commented 3 years ago

Delivery Note

curl --request POST \ --url http://IP:81/api/resource/Delivery%20Note \ --header 'Accept: application/json' \ --header 'Content-Type: application/json' \ --cookie 'sid=c0c91b0620e69cf3e1772f866f99c2363b90108b9162b009e8f425c2; system_user=yes; full_name=Arthur%2520M; user_id=a.m@test.local; user_image=' \ --data '{ "customer": "SOOOXYZ", "items": { "batch_id": "J-20-00048", "conversion_factor": 1.0, "stock_qty": 1, "description": "NADA", "item_code": "AVJ-130", "item_name": "JUGO DE SABILA", "qty": 1.0, "stock_uom": "Litre", "uom": "Litre" }, "sales_order": "SAL-ORD-2020-00001" }'

erpnext version

erpnext 12.14.0 frappe 12.12.0 ubuntu 18