Skip to content

[18.0] account_reconcile_oca: LazyGettext not JSON serializable in _get_manual_reconcile_vals #956

@bojkic

Description

@bojkic

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

  1. Go to Accounting > Bank > Bank Statements
  2. Open a statement line for reconciliation
  3. 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"))]
),

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions