OCA / account-reconcile

Odoo account reconciliation modules (statements, data completion...)
https://odoo-community.org/psc-teams/banking-10
GNU Affero General Public License v3.0
127 stars 368 forks source link

[16.0] account_reconcile_oca: Error when using counterpart reconcile model with taxes #669

Open PNurm opened 2 weeks ago

PNurm commented 2 weeks ago

Module

account_reconcile_oca

Describe the bug

Using the buttons for creating counterparts will throw this error

Traceback (most recent call last): File "/home/legenda/IdeaProjects/odoo-16.0/odoo-16.0/odoo/api.py", line 997, in get cache_value = field_cache[record._ids[0]] KeyError: res.partner(13569,)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/legenda/IdeaProjects/odoo-16.0/odoo-16.0/odoo/fields.py", line 1161, in get value = env.cache.get(record, self) File "/home/legenda/IdeaProjects/odoo-16.0/odoo-16.0/odoo/api.py", line 1004, in get raise CacheMiss(record, field) odoo.exceptions.CacheMiss: 'res.partner(res.partner(13569,),).name'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/legenda/IdeaProjects/odoo-16.0/odoo-16.0/odoo/http.py", line 1632, in _serve_db return service_model.retrying(self._serve_ir_http, self.env) File "/home/legenda/IdeaProjects/odoo-16.0/odoo-16.0/odoo/service/model.py", line 133, in retrying result = func() File "/home/legenda/IdeaProjects/odoo-16.0/odoo-16.0/odoo/http.py", line 1659, in _serve_ir_http response = self.dispatcher.dispatch(rule.endpoint, args) File "/home/legenda/IdeaProjects/odoo-16.0/odoo-16.0/odoo/http.py", line 1863, in dispatch result = self.request.registry['ir.http']._dispatch(endpoint) File "/home/legenda/IdeaProjects/odoo-16.0/odoo-16.0/addons/website/models/ir_http.py", line 237, in _dispatch response = super()._dispatch(endpoint) File "/home/legenda/IdeaProjects/odoo-16.0/odoo-16.0/odoo/addons/base/models/ir_http.py", line 154, in _dispatch result = endpoint(request.params) File "/home/legenda/IdeaProjects/odoo-16.0/odoo-16.0/odoo/http.py", line 716, in route_wrapper result = endpoint(self, *args, *params_ok) File "/home/legenda/IdeaProjects/odoo-16.0/odoo-16.0/addons/web/controllers/dataset.py", line 42, in call_kw return self._call_kw(model, method, args, kwargs) File "/home/legenda/IdeaProjects/odoo-16.0/odoo-16.0/addons/web/controllers/dataset.py", line 33, in _call_kw return call_kw(request.env[model], method, args, kwargs) File "/home/legenda/IdeaProjects/odoo-16.0/odoo-16.0/odoo/api.py", line 468, in call_kw result = _call_kw_multi(method, model, args, kwargs) File "/home/legenda/IdeaProjects/odoo-16.0/odoo-16.0/odoo/api.py", line 453, in _call_kw_multi result = method(recs, args, kwargs) File "/home/legenda/IdeaProjects/odoo-16.0/odoo-16.0/odoo/models.py", line 6606, in onchange record._onchange_eval(name, field_onchange[name], result) File "/home/legenda/IdeaProjects/odoo-16.0/odoo-16.0/odoo/models.py", line 6317, in _onchange_eval method_res = method(self) File "/home/legenda/IdeaProjects/odoo-16.0/modules-16.0/OCA/account-reconcile/account_reconcile_oca/models/account_bank_statement_line.py", line 161, in _onchange_manual_model_id *self._reconcile_data_by_model( File "/home/legenda/IdeaProjects/odoo-16.0/modules-16.0/OCA/account-reconcile/account_reconcile_oca/models/account_bank_statement_line.py", line 419, in _reconcile_data_by_model for line in reconcile_model._get_write_off_move_lines_dict( File "/home/legenda/IdeaProjects/odoo-16.0/odoo-16.0/addons/account/models/account_reconcile_model.py", line 547, in _get_write_off_move_lines_dict detected_fiscal_position = self.env['account.fiscal.position']._get_fiscal_position(self.env['res.partner'].browse(partner_id)) File "/home/legenda/IdeaProjects/odoo-16.0/odoo-16.0/addons/account/models/partner.py", line 223, in _get_fiscal_position print(partner.name) File "/home/legenda/IdeaProjects/odoo-16.0/odoo-16.0/odoo/fields.py", line 1187, in get recs._fetch_field(self) File "/home/legenda/IdeaProjects/odoo-16.0/odoo-16.0/odoo/models.py", line 3201, in _fetch_field self._read(fnames) File "/home/legenda/IdeaProjects/odoo-16.0/odoo-16.0/odoo/models.py", line 3278, in _read cr.execute(query_str, params + [sub_ids]) File "/home/legenda/IdeaProjects/odoo-16.0/odoo-16.0/odoo/sql_db.py", line 321, in execute res = self._obj.execute(query, params) File "/home/legenda/IdeaProjects/odoo-15.0/env/lib/python3.8/site-packages/psycopg2/extensions.py", line 121, in getquoted pobjs = [adapt(o) for o in self._seq] File "/home/legenda/IdeaProjects/odoo-15.0/env/lib/python3.8/site-packages/psycopg2/extensions.py", line 121, in pobjs = [adapt(o) for o in self._seq] psycopg2.ProgrammingError: can't adapt type 'res.partner'

To Reproduce

Affected versions: 16.0

Steps to reproduce the behavior:

Counterpart entries

Reconcile a bank statement row with the button, you will be greeted with this error.

Expected behavior Shouldn't be broken

Additional context

__get_fiscalposition is given recordset of a recordset res.partner(res.partner(13569,),)

This is caused by an oversight at:

account_reconcile_oca/account_bank_statement_line Lines 419 - 421

        for line in reconcile_model._get_write_off_move_lines_dict(
            -liquidity_amount, self._retrieve_partner()
        ):

_retrieve_partner() returns a recordset which is incorrect input for the __get_write_off_moves_linedict method, it expects the id of the partner, not a recordset as we can witness from code below, and can tell from the parameter name.

account/account_reconcile_model Lines 545 - 547

            if line.tax_ids:
                taxes = line.tax_ids
                detected_fiscal_position = self.env['account.fiscal.position']._get_fiscal_position(self.env['res.partner'].browse(partner_id))
pedrobaeza commented 2 weeks ago

Can you please propose a PR with the fix?