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] account: prevent error when clicking on early discount #162564

Open
wants to merge 1 commit into
base: 17.0
Choose a base branch
from

Conversation

aamo-odoo
Copy link
Contributor

@aamo-odoo aamo-odoo commented Apr 19, 2024

This error arises when the someone clicks on Early Discount in Payment Terms while creating a new one.

Steps to reproduce

  • Install account module
  • Invoicing -> Configuration -> Invoicing -> Payment Terms
  • Click on New -> click on Early Discount

Traceback :

ValueError: not enough values to unpack (expected 1, got 0)
  File "odoo/models.py", line 5848, in ensure_one
    _id, = self._ids
ValueError: Expected singleton: res.currency()
  File "odoo/http.py", line 2251, in __call__
    response = request._serve_db()
  File "odoo/http.py", line 1827, in _serve_db
    return self._transactioning(_serve_ir_http, readonly=ro)
  File "odoo/http.py", line 1847, in _transactioning
    return service_model.retrying(func, env=self.env)
  File "odoo/service/model.py", line 134, in retrying
    result = func()
  File "odoo/http.py", line 1825, in _serve_ir_http
    return self._serve_ir_http(rule, args)
  File "odoo/http.py", line 1832, in _serve_ir_http
    response = self.dispatcher.dispatch(rule.endpoint, args)
  File "odoo/http.py", line 2057, in dispatch
    result = self.request.registry['ir.http']._dispatch(endpoint)
  File "odoo/addons/base/models/ir_http.py", line 220, in _dispatch
    result = endpoint(**request.params)
  File "odoo/http.py", line 739, in route_wrapper
    result = endpoint(self, *args, **params_ok)
  File "addons/web/controllers/dataset.py", line 38, in call_kw
    return self._call_kw(model, method, args, kwargs)
  File "addons/web/controllers/dataset.py", line 34, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "odoo/api.py", line 458, in call_kw
    result = getattr(recs, name)(*args, **kwargs)
  File "addons/web/models/models.py", line 1011, in onchange
    todo = [
  File "addons/web/models/models.py", line 1014, in <listcomp>
    if field_name not in done and snapshot0.has_changed(field_name)
  File "addons/web/models/models.py", line 1127, in has_changed
    return self[field_name] != self.record[field_name]
  File "odoo/models.py", line 6576, in __getitem__
    return self._fields[key].__get__(self, self.env.registry[self._name])
  File "odoo/fields.py", line 1261, in __get__
    self.compute_value(recs)
  File "odoo/fields.py", line 1443, in compute_value
    records._compute_field_value(self)
  File "odoo/models.py", line 4931, in _compute_field_value
    fields.determine(field.compute, self)
  File "odoo/fields.py", line 100, in determine
    return needle(*args)
  File "addons/account/models/account_payment_term.py", line 95, in _compute_example_preview
    discount_amount = record._get_amount_due_after_discount(record.example_amount, 0.0)
  File "addons/account/models/account_payment_term.py", line 67, in _get_amount_due_after_discount
    discount_amount_currency = self.currency_id.round(total_amount - (total_amount * (1 - (percentage))))
  File "odoo/addons/base/models/res_currency.py", line 217, in round
    self.ensure_one()
  File "odoo/models.py", line 5851, in ensure_one
    raise ValueError("Expected singleton: %s" % self)

This error occurs from line[1] where the currency ID is getting false within the self, leading to a value error being raised. This happens because of this PR #161044, where they have removed the default currency from currency ID field.

This commit will fix the above error by adding company_id field in the payment term from view.

[1] :

discount_amount_currency = self.currency_id.round(total_amount - (total_amount * (1 - (percentage))))

sentry - 5209971284


I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr

@robodoo
Copy link
Contributor

robodoo commented Apr 19, 2024

@C3POdoo C3POdoo added the RD research & development, internal work label Apr 19, 2024
@aamo-odoo
Copy link
Contributor Author

Hello @odoo/sentry_reviewers
Please review this PR 🙂

@adwid adwid requested a review from ushyme April 23, 2024 06:15
@ushyme
Copy link
Contributor

ushyme commented Apr 25, 2024

Hello 👋🏾,

Thank you for your contribution. It appears that the underlying issue may be related to the absence of the company_id field in the payment term from view.

To address this, could you please insert the following line: <field name="company_id" invisible="1"/> at this location:

<field name="fiscal_country_codes" invisible="1"/>

This should help resolve the issue. Thank you!

This error arises when the someone clicks on "Early Discount" in Payment Terms
while creating a new one.

Steps to reproduce:
- Install "account" module
- Invoicing -> Configuration -> Invoicing -> Payment Terms
- Click on "New" -> click on "Early Discount"

Traceback : ValueError
Expected singleton: res.currency()

This error occurs from line[1] where the currency ID is getting false within the
self, leading to a value error being raised. This happens because of this PR
odoo#161044, where they have removed the default
currency from currency ID field.

This commit will fix the above error by adding 'company_id' field in the payment
term from view.

[1] : https://github.com/odoo/odoo/blob/5673ea9d8c6993575bd9ce9c2a931a8738e77e76/addons/account/models/account_payment_term.py#L67

sentry - 5209971284
@aamo-odoo aamo-odoo force-pushed the 17.0-sentry-5209971284-valueerror-account-aamo branch from 6e21229 to e984cca Compare April 25, 2024 15:38
@aamo-odoo
Copy link
Contributor Author

Hello @ushyme
Requested changes have been made.
Please have a look 🙂

@ushyme
Copy link
Contributor

ushyme commented Apr 26, 2024

LGTM 👍🏾, thank you!

@ushyme ushyme marked this pull request as ready for review April 26, 2024 06:09
@C3POdoo C3POdoo requested review from a team and FlorianGilbert and removed request for a team April 26, 2024 06:10
@aamo-odoo
Copy link
Contributor Author

Hello @FlorianGilbert
Can I have your review on this PR?

Thanks in advance 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RD research & development, internal work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants