Skip to content

Conversation

jpp-odoo
Copy link
Contributor

@jpp-odoo jpp-odoo commented Dec 10, 2024

This commit adds a new object with the information of the companies, to
the evaluation context of Python expressions.

The object contains:

  • multi_company: A boolean indicating whether the user has access to multiple companies.
  • allowed_ids : The list of company IDs the user is allowed to connect to.
  • active_ids: The list of company IDs the user is connected to (selected in the company switcher dropdown).
  • active_id: The ID of the main company selected (the one highlighted in the company switcher dropdown and displayed in the navbar of the webclient).
  • has(id|ids, 'property', value) : returns a boolean indicating whether there's a company with id in ids for which field matches the given value. Note that the properties of the companies are those sent by the server in the session info. If a new property is needed, the company function _get_session_info can be overridden. For example, the following code will add the company_code property:
    def _get_session_info(self, allowed_company_ids):
        res = super()._get_session_info(allowed_company_ids)
        res.update({
            'country_code': self.country_id.code
        })
        return res

Some usage examples:

  • In this case, the field 'foo' will be visible if the user has access
    to more than one company:

        <field name="foo" invisible="not companies.multi_company"/>
  • In this case, the filed 'foo' will be visible if the user has
    activated one company with the country code 'PE':

        <field name="foo" invisible="not companies.has(companies.active_ids, 'country_code', 'PE')"/>
  • In this case, the field 'float_field' will be visible if the main
    company (the one show on the top bar), has the country code 'PE':

        <field name="float_field" invisible="not companies.has(companies.active_id, 'country_code', 'PE')"/>
  • In this case, the field 'child_ids' will be visible if the company of
    the current record has the country code 'PE'. Note that, to
    evaluate correctly this expression, the 'company_id' field
    should be in the view:

        <field name="child_ids" invisible="not companies.has(company_id, 'country_code', 'PE')"/>

part-of task-id 4250356

@robodoo
Copy link
Contributor

robodoo commented Dec 10, 2024

Pull request status dashboard

@odoo odoo deleted a comment from kebeclibre Dec 10, 2024
@jpp-odoo jpp-odoo force-pushed the master-add_current_company_country_code-jpp branch from 8dca9ae to 831d63e Compare December 10, 2024 13:59
@C3POdoo C3POdoo added the RD research & development, internal work label Dec 10, 2024
@jpp-odoo jpp-odoo force-pushed the master-add_current_company_country_code-jpp branch 12 times, most recently from be0fc90 to 819eb3b Compare December 16, 2024 09:44
Comment on lines 331 to 332
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should try to remove these two (in another PR is fine)

@jpp-odoo jpp-odoo force-pushed the master-add_current_company_country_code-jpp branch 8 times, most recently from 41062c4 to 2e4a2fd Compare December 17, 2024 10:13
@jpp-odoo jpp-odoo changed the title [WIP] [IMP] web: add companies infos to the evaluation context Dec 17, 2024
@jpp-odoo jpp-odoo marked this pull request as ready for review December 17, 2024 10:14
@C3POdoo C3POdoo requested review from a team December 17, 2024 10:17
@jpp-odoo jpp-odoo force-pushed the master-add_current_company_country_code-jpp branch from 5d71a26 to c02ee08 Compare December 19, 2024 08:47
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we depreciate these two values?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but we will do it in a follow-up PR

@jpp-odoo jpp-odoo force-pushed the master-add_current_company_country_code-jpp branch from 0f85e2c to e5779d1 Compare December 19, 2024 13:06
@jpp-odoo jpp-odoo force-pushed the master-add_current_company_country_code-jpp branch from e5779d1 to 8db80ec Compare December 19, 2024 14:11
Copy link
Contributor

@aab-odoo aab-odoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

robodoo rebase-ff r+

@robodoo
Copy link
Contributor

robodoo commented Dec 19, 2024

Merge method set to rebase and fast-forward.

@robodoo
Copy link
Contributor

robodoo commented Dec 19, 2024

@jpp-odoo @aab-odoo 'ci/runbot' failed on this reviewed PR.

@robodoo
Copy link
Contributor

robodoo commented Dec 19, 2024

@jpp-odoo @aab-odoo linked pull request(s) odoo/enterprise#75836 not ready. Linked PRs are not staged until all of them are ready.

This commit adds a new object with the information of the companies, to
the evaluation context of Python expressions.

The object contains:
- multi_company: A boolean indicating whether the user has access to
        multiple companies.
- allowed_ids : The list of company IDs the user is allowed to connect
        to.
- active_ids: The list of company IDs the user is connected to (selected
        in the company switcher dropdown).
- active_id: The ID of the main company selected (the one highlighted in
        the company switcher dropdown and displayed in the navbar of the
        webclient).
- has(id|ids, 'property', value) : returns a boolean indicating whether
        there's a company with id in `ids` for which `field` matches the
        given `value`. Note that the properties of the companies are
        those sent by the server in the session info. If a new property
        is needed, the company function `_get_session_info` can be
        overridden. For example, the following code will add the
        `company_code` property:
    ```py
    def _get_session_info(self, allowed_company_ids):
        res = super()._get_session_info(allowed_company_ids)
        res.update({
            'country_code': self.country_id.code
        })
        return res
    ```

Some usage examples:

- In this case, the field 'foo' will be visible if the user has access
        to more than one company:
    ```xml
        <field name="foo" invisible="not companies.multi_company"/>
    ```
- In this case, the filed 'foo' will be visible if the user has
        activated one company with the country code 'PE':
    ```xml
        <field name="foo" invisible="not companies.has(companies.active_ids, 'country_code', 'PE')"/>
    ```
- In this case, the field 'float_field' will be visible if the main
        company (the one show on the top bar), has the country code 'PE':
    ```xml
        <field name="float_field" invisible="not companies.has(companies.active_id, 'country_code', 'PE')"/>
    ```

- In this case, the field 'child_ids' will be visible if the company of
        the current record has the country code 'PE'. Note that, to
        evaluate correctly this expression, the 'company_id' field
        should be in the view:
    ```xml
        <field name="child_ids" invisible="not companies.has(company_id, 'country_code', 'PE')"/>
    ```

part-of task-id 4250356
This commit removes the display_switch_company_menu from the session,
and uses the company service. Note that, the company service already has
the information about the allowed companies.

part-of task-id 2224776
@aab-odoo aab-odoo force-pushed the master-add_current_company_country_code-jpp branch from 8db80ec to dca22fa Compare December 20, 2024 07:14
@aab-odoo
Copy link
Contributor

robodoo r+

robodoo pushed a commit that referenced this pull request Dec 20, 2024
This commit adds a new object with the information of the companies, to
the evaluation context of Python expressions.

The object contains:
- multi_company: A boolean indicating whether the user has access to
        multiple companies.
- allowed_ids : The list of company IDs the user is allowed to connect
        to.
- active_ids: The list of company IDs the user is connected to (selected
        in the company switcher dropdown).
- active_id: The ID of the main company selected (the one highlighted in
        the company switcher dropdown and displayed in the navbar of the
        webclient).
- has(id|ids, 'property', value) : returns a boolean indicating whether
        there's a company with id in `ids` for which `field` matches the
        given `value`. Note that the properties of the companies are
        those sent by the server in the session info. If a new property
        is needed, the company function `_get_session_info` can be
        overridden. For example, the following code will add the
        `company_code` property:
    ```py
    def _get_session_info(self, allowed_company_ids):
        res = super()._get_session_info(allowed_company_ids)
        res.update({
            'country_code': self.country_id.code
        })
        return res
    ```

Some usage examples:

- In this case, the field 'foo' will be visible if the user has access
        to more than one company:
    ```xml
        <field name="foo" invisible="not companies.multi_company"/>
    ```
- In this case, the filed 'foo' will be visible if the user has
        activated one company with the country code 'PE':
    ```xml
        <field name="foo" invisible="not companies.has(companies.active_ids, 'country_code', 'PE')"/>
    ```
- In this case, the field 'float_field' will be visible if the main
        company (the one show on the top bar), has the country code 'PE':
    ```xml
        <field name="float_field" invisible="not companies.has(companies.active_id, 'country_code', 'PE')"/>
    ```

- In this case, the field 'child_ids' will be visible if the company of
        the current record has the country code 'PE'. Note that, to
        evaluate correctly this expression, the 'company_id' field
        should be in the view:
    ```xml
        <field name="child_ids" invisible="not companies.has(company_id, 'country_code', 'PE')"/>
    ```

part-of task-id 4250356

Part-of: #190218
Related: odoo/enterprise#75836
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
robodoo pushed a commit that referenced this pull request Dec 20, 2024
This commit removes the display_switch_company_menu from the session,
and uses the company service. Note that, the company service already has
the information about the allowed companies.

part-of task-id 2224776

closes #190218

Related: odoo/enterprise#75836
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
@robodoo robodoo added the 18.1 label Dec 20, 2024
@robodoo robodoo closed this Dec 20, 2024
@jpp-odoo jpp-odoo deleted the master-add_current_company_country_code-jpp branch December 23, 2024 09:17
rco-odoo pushed a commit to odoo-dev/odoo that referenced this pull request Feb 4, 2025
This adapts the server-side form to the changes made in
odoo#190218.

The `companies` object contains:
- multi_company: A boolean indicating whether the user has access to
        multiple companies.
- allowed_ids : The list of company IDs the user is allowed to connect
        to.
- active_ids: The list of company IDs the user is connected to (selected
        in the company switcher dropdown).
- active_id: The ID of the main company selected (the one highlighted in
        the company switcher dropdown and displayed in the navbar of the
        webclient).
- has(id|ids, 'property', value) : returns a boolean indicating whether
        there's a company with id in `ids` for which `field` matches the
        given `value`.
robodoo pushed a commit that referenced this pull request Feb 4, 2025
This adapts the server-side form to the changes made in
#190218.

The `companies` object contains:
- multi_company: A boolean indicating whether the user has access to
        multiple companies.
- allowed_ids : The list of company IDs the user is allowed to connect
        to.
- active_ids: The list of company IDs the user is connected to (selected
        in the company switcher dropdown).
- active_id: The ID of the main company selected (the one highlighted in
        the company switcher dropdown and displayed in the navbar of the
        webclient).
- has(id|ids, 'property', value) : returns a boolean indicating whether
        there's a company with id in `ids` for which `field` matches the
        given `value`.

closes #195707

Signed-off-by: Raphael Collet <rco@odoo.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

18.1 RD research & development, internal work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants