OCA / multi-company

GNU Affero General Public License v3.0
100 stars 281 forks source link

[16.0][FIX] base_multi_company: Check multiple companies #551

Closed SirAionTech closed 8 months ago

SirAionTech commented 8 months ago

Before this PR, executing _check_company on multiple companies failed with our beloved

Expected singleton

error

Steps

  1. Install stock: this module sets _check_company_auto = True in https://github.com/odoo/odoo/blob/6485872d00f47e351e40741283f3b9219adcd8a8/addons/stock/models/res_company.py#L9
  2. Create multiple companies in one shot with self.env["res.company"].create([ ... ]) syntax

Actual behavior Error traceback ending with something like

  File "/path/to/multi-company/base_multi_company/models/base.py", line 21, in _check_company
    company_source_id = self.id
  File "/path/to/odoo/odoo/fields.py", line 5069, in __get__
    raise ValueError("Expected singleton: %s" % record)
ValueError: Expected singleton: res.company(214, 215)

Expected behavior No error

OCA-git-bot commented 8 months ago

Hi @pedrobaeza, some modules you are maintaining are being modified, check this out!

OCA-git-bot commented 8 months ago

On my way to merge this fine PR! Prepared branch 16.0-ocabot-merge-pr-551-by-pedrobaeza-bump-patch, awaiting test results.

pedrobaeza commented 8 months ago

Please check if this is applicable to other versions.

OCA-git-bot commented 8 months ago

Congratulations, your PR was merged at 13a87e27661f7cc71e47021647a5e810ff350f22. Thanks a lot for contributing to OCA. ❤️

SirAionTech commented 8 months ago

Please check if this is applicable to other versions.

It is applicable to 15.0: https://github.com/OCA/multi-company/blob/81092e7ddd53c60723a8b9eb7be49596e42ab0d7/base_multi_company/models/base.py#L21-L25

and 14.0: https://github.com/OCA/multi-company/blob/29f8d599e4ca278aa2dd41c6f4d2b7f5de12b353/base_multi_company/models/base.py#L21-L25 here it was partially fixed by https://github.com/OCA/multi-company/pull/548.

Can't find similar code anywhere else. I'll probably oca-port tomorrow or the day after.