This question has been flagged

When I select a customer in res.partner and attempt to add a contact to its child_ids through edit>add>Save & Close it seems that Odoo tries to compute the newly created customer's debit and credit but somehow crashes trying to execute the below query seemingly because where_params seems to be null. (Below you can observe the full traceback error)

Note that I have not altered the code, I suspect the error might be originating from some sort of misconfiguration of my chart of accounts but that's a guess at best and unrelated at worst. Any ideas?

@api.multi
def _credit_debit_get(self):
tables, where_clause, where_params = self.env['account.move.line'].with_context(company_id=self.env.user.company_id.id)._query_get()
where_params = [tuple(self.ids)] + where_params
if where_clause:
where_clause = 'AND ' + where_clause
self._cr.execute("""SELECT account_move_line.partner_id, act.type, SUM(account_move_line.amount_residual)
FROM account_move_line
LEFT JOIN account_account a ON (account_move_line.account_id=a.id)
LEFT JOIN account_account_type act ON (a.user_type_id=act.id)
WHERE act.type IN ('receivable','payable')
AND account_move_line.partner_id IN %s
AND account_move_line.reconciled IS FALSE
""" + where_clause + """
GROUP BY account_move_line.partner_id, act.type
""", where_params)
for pid, type, val in self._cr.fetchall():
partner = self.browse(pid)
if type == 'receivable':
partner.credit = val
elif type == 'payable':
partner.debit = -val

The full traceback error:

Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/odoo/api.py", line 1039, in get
value = self._data[key][field][record._ids[0]]
KeyError: <odoo.models.NewId object at 0x7f9ae55a6c78>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/odoo/fields.py", line 976, in __get__
value = record.env.cache.get(record, self)
File "/usr/lib/python3/dist-packages/odoo/api.py", line 1041, in get
raise CacheMiss(record, field)
odoo.exceptions.CacheMiss: ('res.partner(<odoo.models.NewId object at 0x7f9ae55a6c78>,).credit', None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/odoo/http.py", line 654, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/usr/lib/python3/dist-packages/odoo/http.py", line 312, in _handle_exception
raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
File "/usr/lib/python3/dist-packages/odoo/tools/pycompat.py", line 87, in reraise
raise value
File "/usr/lib/python3/dist-packages/odoo/http.py", line 696, in dispatch
result = self._call_function(**self.params)
File "/usr/lib/python3/dist-packages/odoo/http.py", line 344, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/usr/lib/python3/dist-packages/odoo/service/model.py", line 97, in wrapper
return f(dbname, *args, **kwargs)
File "/usr/lib/python3/dist-packages/odoo/http.py", line 337, in checked_call
result = self.endpoint(*a, **kw)
File "/usr/lib/python3/dist-packages/odoo/http.py", line 939, in __call__
return self.method(*args, **kw)
File "/usr/lib/python3/dist-packages/odoo/http.py", line 517, in response_wrap
response = f(*args, **kw)
File "/usr/lib/python3/dist-packages/odoo/addons/web/controllers/main.py", line 962, in call_kw
return self._call_kw(model, method, args, kwargs)
File "/usr/lib/python3/dist-packages/odoo/addons/web/controllers/main.py", line 954, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/usr/lib/python3/dist-packages/odoo/api.py", line 749, in call_kw
return _call_kw_multi(method, model, args, kwargs)
File "/usr/lib/python3/dist-packages/odoo/api.py", line 736, in _call_kw_multi
result = method(recs, *args, **kwargs)
File "/usr/lib/python3/dist-packages/odoo/models.py", line 5438, in onchange
snapshot0 = snapshot1 = Snapshot(record, nametree)
File "/usr/lib/python3/dist-packages/odoo/models.py", line 5378, in __init__
if subnames else record[name]
File "/usr/lib/python3/dist-packages/odoo/models.py", line 5377, in <listcomp>
[Snapshot(line, subnames) for line in record[name]]
File "/usr/lib/python3/dist-packages/odoo/models.py", line 5378, in __init__
if subnames else record[name]
File "/usr/lib/python3/dist-packages/odoo/models.py", line 5087, in __getitem__
return self._fields[key].__get__(self, type(self))
File "/usr/lib/python3/dist-packages/odoo/fields.py", line 982, in __get__
self.determine_draft_value(record)
File "/usr/lib/python3/dist-packages/odoo/fields.py", line 1102, in determine_draft_value
self._compute_value(record)
File "/usr/lib/python3/dist-packages/odoo/fields.py", line 1038, in _compute_value
getattr(records, self.compute)()
File "/usr/lib/python3/dist-packages/odoo/addons/account/models/partner.py", line 220, in _credit_debit_get
""", where_params)
File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 148, in wrapper
return f(self, *args, **kwargs)
File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 225, in execute
res = self._obj.execute(query, params)
psycopg2.ProgrammingError: syntax error at or near ")"
LINE 6: AND account_move_line.partner_id IN ()
^​
Avatar
Discard