Module
account_reconcile_oca
Version
18.0
Description
When using the manual reconciliation feature in bank statement lines, a TypeError: Object of type LazyGettext is not JSON serializable error occurs.
Steps to reproduce
- Go to Accounting > Bank > Bank Statements
- Open a statement line for reconciliation
- Try to manually reconcile without selecting an account (leaving account empty)
Error traceback
File "/opt/odoo18/oca-addons/account-reconcile/account_reconcile_oca/models/account_bank_statement_line.py", line 540, in _onchange_manual_reconcile_vals
self.reconcile_data_info = self._recompute_suspense_line(
File "/opt/odoo18/odoo/fields.py", line 1414, in __set__
self.write(new_records, value)
File "/opt/odoo18/odoo/fields.py", line 1213, in write
cache_value = self.convert_to_cache(value, records)
File "/opt/odoo18/addons/base_sparse_field/models/fields.py", line 89, in convert_to_cache
return json.dumps(value) if isinstance(value, dict) else (value or None)
File "/usr/lib/python3.12/json/__init__.py", line 231, in dumps
return _default_encoder.encode(obj)
TypeError: Object of type LazyGettext is not JSON serializable
Cause
In _get_manual_reconcile_vals() method (line 454), when manual_account_id is not set, the code returns:
"account_id": (
[self.manual_account_id.id, self.manual_account_id.display_name]
if self.manual_account_id
else [False, _lt("Undefined")]
),
The _lt("Undefined") returns a LazyGettext object which cannot be serialized to JSON when stored in the reconcile_data_info sparse field.
Proposed fix
Wrap the lazy translation with str() to convert it to a regular string:
"account_id": (
[self.manual_account_id.id, self.manual_account_id.display_name]
if self.manual_account_id
else [False, str(_lt("Undefined"))]
),
Module
account_reconcile_oca
Version
18.0
Description
When using the manual reconciliation feature in bank statement lines, a
TypeError: Object of type LazyGettext is not JSON serializableerror occurs.Steps to reproduce
Error traceback
Cause
In
_get_manual_reconcile_vals()method (line 454), whenmanual_account_idis not set, the code returns:The
_lt("Undefined")returns aLazyGettextobject which cannot be serialized to JSON when stored in thereconcile_data_infosparse field.Proposed fix
Wrap the lazy translation with
str()to convert it to a regular string: