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

[15.0] [BUG] account_invoice_fixed_discount by putting the same unit price amount in the fixed discount. #1557

Open
JorgeQuinteros opened this issue Sep 20, 2023 · 0 comments
Labels

Comments

@JorgeQuinteros
Copy link

Module

account_invoice_fixed_discount

Describe the bug

ZeroDivisionError: float division by zero

If we set a fixed discount equal to the unit price or which gives as subtotal 0

Traceback (most recent call last):
  File "/opt/odoo/odoo/addons/base/models/ir_http.py", line 237, in _dispatch
    result = request.dispatch()
  File "/opt/odoo/odoo/http.py", line 698, in dispatch
    result = self._call_function(**self.params)
  File "/opt/odoo/odoo/http.py", line 368, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/opt/odoo/odoo/service/model.py", line 94, in wrapper
    return f(dbname, *args, **kwargs)
  File "/opt/odoo/odoo/http.py", line 357, in checked_call
    result = self.endpoint(*a, **kw)
  File "/opt/odoo/odoo/http.py", line 921, in __call__
    return self.method(*args, **kw)
  File "/opt/odoo/odoo/http.py", line 546, in response_wrap
    response = f(*args, **kw)
  File "/opt/odoo/addons/web/controllers/main.py", line 1328, in call_button
    action = self._call_kw(model, method, args, kwargs)
  File "/opt/odoo/addons/web/controllers/main.py", line 1316, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "/opt/odoo/odoo/api.py", line 464, in call_kw
    result = _call_kw_multi(method, model, args, kwargs)
  File "/opt/odoo/odoo/api.py", line 451, in _call_kw_multi
    result = method(recs, *args, **kwargs)
  File "/opt/odoo/addons/sale/models/account_move.py", line 76, in action_post
    res = super(AccountMove, self).action_post()
  File "/mnt/data/odoo-addons-dir/account_invoice_check_picking_date/models/account_move.py", line 65, in action_post
    return super().action_post()
  File "/mnt/data/odoo-addons-dir/account_move_exception/models/account_move.py", line 42, in action_post
    return super().action_post()
  File "/mnt/data/odoo-addons-dir/account_invoice_tax_required/models/account_move.py", line 54, in action_post
    return super(AccountMove, self).action_post()
  File "/mnt/data/odoo-addons-dir/account_invoice_force_number/models/account_move.py", line 36, in action_post
    return super(AccountMove, self).action_post()
  File "/mnt/data/odoo-addons-dir/account_invoice_check_total/models/account_move.py", line 57, in action_post
    return super().action_post()
  File "/opt/odoo/addons/account/models/account_move.py", line 3199, in action_post
    other_moves._post(soft=False)
  File "/opt/odoo/addons/sale/models/account_move.py", line 92, in _post
    posted = super()._post(soft)
  File "/opt/odoo/addons/purchase_stock/models/account_invoice.py", line 173, in _post
    return super()._post(soft)
  File "/opt/odoo/addons/stock_account/models/account_move.py", line 53, in _post
    posted = super()._post(soft)
  File "/mnt/data/odoo-addons-dir/account_invoice_supplier_self_invoice/models/account_move.py", line 65, in _post
    res = super()._post(soft=soft)
  File "/opt/odoo/addons/account_edi/models/account_move.py", line 502, in _post
    posted = super()._post(soft=soft)
  File "/opt/odoo/addons/account/models/account_move.py", line 3112, in _post
    move.with_context(check_move_validity=False)._onchange_invoice_date()
  File "/opt/odoo/addons/account/models/account_move.py", line 472, in _onchange_invoice_date
    self._onchange_currency()
  File "/opt/odoo/addons/account/models/account_move.py", line 552, in _onchange_currency
    self._recompute_dynamic_lines(recompute_tax_base_amount=True)
  File "/opt/odoo/addons/account/models/account_move.py", line 1177, in _recompute_dynamic_lines
    invoice._recompute_tax_lines(recompute_tax_base_amount=True)
  File "/mnt/data/odoo-addons-dir/account_invoice_triple_discount/models/account_move.py", line 34, in _recompute_tax_lines
    res = super(AccountMove, self)._recompute_tax_lines(**kwargs)
  File "/mnt/data/odoo-addons-dir/account_invoice_fixed_discount/models/account_move.py", line 18, in _recompute_tax_lines
    line.update({"price_unit": price_unit})
  File "/opt/odoo/odoo/models.py", line 5645, in update
    record[name] = value
  File "/opt/odoo/odoo/models.py", line 5925, in __setitem__
    return self._fields[key].__set__(self, value)
  File "/opt/odoo/odoo/fields.py", line 1242, in __set__
    records.write({self.name: write_value})
  File "/opt/odoo/addons/account/models/account_move.py", line 4889, in write
    to_write = line._get_price_total_and_subtotal()
  File "/mnt/data/odoo-addons-dir/account_invoice_triple_discount/models/account_move_line.py", line 73, in _get_price_total_and_subtotal
    return super(AccountMoveLine, self)._get_price_total_and_subtotal(**kwargs)
  File "/opt/odoo/addons/account/models/account_move.py", line 4078, in _get_price_total_and_subtotal
    return self._get_price_total_and_subtotal_model(
  File "/mnt/data/odoo-addons-dir/account_invoice_fixed_discount/models/account_move.py", line 74, in _get_price_total_and_subtotal_model
    discount = ((self.discount_fixed) / price_unit) * 100 or 0.00
Exception

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/odoo/odoo/http.py", line 654, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/opt/odoo/odoo/http.py", line 301, in _handle_exception
    raise exception.with_traceback(None) from new_cause
ZeroDivisionError: float division by zero

To Reproduce

15.0

Steps to reproduce the behavior:
These are the steps I have followed in the OCA Runboat (Odoo 15.0):

  1. Move a published invoice of at least one day difference to draft and remove the invoice date.

  2. Set a fixed discount on a line so that the subtotal is 0.
    image

  3. Click on "Confirm" button.

Expected behavior
Invoice confirmed with no division by zero errors.

Additional context
Tested on runboat 15.0
http://oca-account-invoicing-15-0-1172046897ce.runboat.odoo-community.org/web?debug=1#id=3&cids=1&menu_id=143&action=258&model=account.move&view_type=form

The problem is when we try to confirm an invoice at least 1 day late, because if we create an invoice today and confirm it today, there is no problem.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant