account-closing icon indicating copy to clipboard operation
account-closing copied to clipboard

[IMP] account_fiscal_year_closing: Avoid memory error

Open Chionne27 opened this issue 5 months ago • 1 comments

mapped loads a lot of data in the cache, so when we are closing a fiscal year with a lot of lines the following exception might be raised:

  File "/opt/odoo/custom/oca/account-closing/account_fiscal_year_closing/models/account_fiscalyear_closing.py", line 291, in button_calculate
    res = self.calculate()
  File "/opt/odoo/custom/oca/account-closing/account_fiscal_year_closing/models/account_fiscalyear_closing.py", line 275, in calculate
    move, data = config.moves_create()
  File "/opt/odoo/custom/oca/account-closing/account_fiscal_year_closing/models/account_fiscalyear_closing.py", line 509, in moves_create
    move_lines = self._mapping_move_lines_get()
  File "/opt/odoo/custom/oca/account-closing/account_fiscal_year_closing/models/account_fiscalyear_closing.py", line 456, in _mapping_move_lines_get
    balance, move_line = account_map.move_line_prepare(account, lines)
  File "/opt/odoo/custom/oca/account-closing/account_fiscal_year_closing/models/account_fiscalyear_closing.py", line 593, in move_line_prepare
    balance = sum(account_lines.mapped("debit")) - sum(
  File "/usr/lib/python3/dist-packages/odoo/models.py", line 5292, in mapped
    recs = recs._fields[name].mapped(recs)
  File "/usr/lib/python3/dist-packages/odoo/fields.py", line 1109, in mapped
    self.__get__(first(remaining), type(remaining))
  File "/usr/lib/python3/dist-packages/odoo/fields.py", line 1019, in __get__
    recs._fetch_field(self)
  File "/usr/lib/python3/dist-packages/odoo/models.py", line 3078, in _fetch_field
    self._read(fnames)
  File "/usr/lib/python3/dist-packages/odoo/models.py", line 3175, in _read
    self.env.cache.update(fetched, field, values)
  File "/usr/lib/python3/dist-packages/odoo/api.py", line 817, in update
    field_cache.update(zip(records._ids, values))
Exception

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 652, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 317, in _handle_exception
    raise exception.with_traceback(None) from new_cause
MemoryError

Chionne27 avatar Jul 21 '25 13:07 Chionne27

@grindtildeath fw-porting of https://github.com/OCA/account-closing/pull/346

francesco-ooops avatar Jul 21 '25 14:07 francesco-ooops

There hasn't been any activity on this pull request in the past 4 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days. If you want this PR to never become stale, please ask a PSC member to apply the "no stale" label.

github-actions[bot] avatar Nov 23 '25 12:11 github-actions[bot]