odoo/odoo#162564

Created by Bugfix, Aayush Modi (aamo)
Merged at 48d0480dd0c44c7719b5fcd6c82e255a26a297a8

Statuses:

label
odoo-dev:17.0-sentry-5209971284-valueerror-account-aamo
head
e984ccac19a9dd66abeda0429252fd8d3e65aea1
merged
1 year ago by Platform, Brice Bartoletti (bib)
odoo/odoo
17.0 #162564
saas-17.1 #164210
saas-17.2 #164230
18.0
saas-18.1
saas-18.2
saas-18.3
saas-18.4
master #164271

[FIX] account: prevent error when clicking on early discount

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] : https://github.com/odoo/odoo/blob/5673ea9d8c6993575bd9ce9c2a931a8738e77e76/addons/account/models/account_payment_term.py#L67

sentry - 5209971284


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