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: Divide by zero exception fix in item wise purchase register #16247

Merged

Conversation

Projects
None yet
4 participants
@deepeshgarg007
Copy link
Collaborator

commented Dec 20, 2018

Do not prepare row if stock quantity is zero
If d.stock_qty is not zero then only row for that item will be prepared

Before:

Traceback (most recent call last):
  File "/home/frappe/benches/bench-2018-11-15/apps/frappe/frappe/app.py", line 62, in application
    response = frappe.handler.handle()
  File "/home/frappe/benches/bench-2018-11-15/apps/frappe/frappe/handler.py", line 22, in handle
    data = execute_cmd(cmd)
  File "/home/frappe/benches/bench-2018-11-15/apps/frappe/frappe/handler.py", line 53, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "/home/frappe/benches/bench-2018-11-15/apps/frappe/frappe/__init__.py", line 939, in call
    return fn(*args, **newargs)
  File "/home/frappe/benches/bench-2018-11-15/apps/frappe/frappe/desk/query_report.py", line 96, in run
    res = frappe.get_attr(method_name)(frappe._dict(filters))
  File "/home/frappe/benches/bench-2018-11-15/apps/erpnext/erpnext/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py", line 11, in execute
    return _execute(filters)
  File "/home/frappe/benches/bench-2018-11-15/apps/erpnext/erpnext/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py", line 52, in _execute
    purchase_receipt, expense_account, d.stock_qty, d.stock_uom, d.base_net_amount / d.stock_qty, d.base_net_amount
ZeroDivisionError: float division by zero

After:
screenshot 2018-12-26 at 11 21 55 am

@saurabh6790
Copy link
Member

left a comment

Can you add screenshots (before/after)?

@deepeshgarg007

This comment has been minimized.

Copy link
Collaborator Author

commented Dec 26, 2018

@saurabh6790 Done.

@deepeshgarg007 deepeshgarg007 changed the title [Minor] Divide by zero exception fix in item wise purchase register fix: Divide by zero exception fix in item wise purchase register Jan 6, 2019

purchase_receipt = d.purchase_receipt
elif d.po_detail:
purchase_receipt = ", ".join(po_pr_map.get(d.po_detail, []))
if d.stock_qty:

This comment has been minimized.

Copy link
@sagarvora

sagarvora Jan 7, 2019

Contributor

you can reduce indentation to increase readability by doing something like:

if not d.stock_qty:
    continue
@deepeshgarg007

This comment has been minimized.

Copy link
Collaborator Author

commented Jan 8, 2019

@sagarvora Done

@sagarvora sagarvora merged commit 7c45f45 into frappe:staging-fixes Jan 8, 2019

4 of 5 checks passed

continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
Codacy/PR Quality Review Up to standards. A positive pull request.
Details
Semantic Pull Request ready to be squashed
Details
Travis CI - Pull Request Build Passed
Details
security/snyk - requirements.txt (frappe) No manifest changes detected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.