Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] account: include user company in currency mapping #171605

Closed

Conversation

jjmaksoud
Copy link
Contributor

Description of the issue/feature this PR addresses:

When the current user is the system user, which happens during install and upgrades, the env company is possibly not included with the companies given to _get_query_currency_table, this can lead to a KeyError when fetching the rate for said company.

Current behavior before PR:
Steps to reproduce:

  • Create company 2 with a currency different than the original company
  • Deactivate the original company
  • Install module Purchase (or another module that uses _get_query_currency_table)
  • failure

Same behavior on upgrade if purchase is already installed and the company linked to the system user is deactivated and has a different currency than the active companies.

Desired behavior after PR is merged:


I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr

@robodoo
Copy link
Contributor

robodoo commented Jul 2, 2024

Pull request status dashboard

@@ -56,6 +56,8 @@ def _get_query_currency_table(self, company_ids, conversion_date):
if companies == user_company:
currency_rates = {user_company.currency_id.id: 1.0}
else:
if user_company not in companies:
companies = companies | user_company
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
companies = companies | user_company
companies |= user_company

@C3POdoo C3POdoo requested review from a team and william-andre and removed request for a team July 2, 2024 14:45
@C3POdoo C3POdoo added the RD research & development, internal work label Jul 2, 2024
When the current user is the system user, which happens
during install and upgrades, the env company is possibly
not included with the companies given to
_get_query_currency_table, this can lead to a KeyError
when fetching the rate for said company.
@jjmaksoud jjmaksoud force-pushed the 17.0-account-currency-companies-maji branch from 8a95269 to a20e712 Compare July 3, 2024 06:50
Copy link
Contributor

@william-andre william-andre left a comment

Choose a reason for hiding this comment

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

If this is called during upgrade, doesn't it mean that it is for something stored in the database, and therefore should not depend on the user's context's company, but on the company of the records being updated?

@jjmaksoud
Copy link
Contributor Author

Not really, the instances when it was called during upgrade is when the record rules were updated and those are not company dependent. That's why it also happens during the installation of a module.

To be more specific, the failure happens when the ir.rule validates the domain, and for model purchase.report it uses the model's _table_query that uses _get_query_currency_table, and the problem arises when odoobot's company is not in self.env.companies

Copy link
Contributor

@william-andre william-andre left a comment

Choose a reason for hiding this comment

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

Thanks for the explanation
@robodoo r+

@robodoo robodoo closed this in d9852ff Aug 9, 2024
hsal-odoo pushed a commit to odoo-dev/odoo that referenced this pull request Aug 12, 2024
When the current user is the system user, which happens
during install and upgrades, the env company is possibly
not included with the companies given to
_get_query_currency_table, this can lead to a KeyError
when fetching the rate for said company.

closes odoo#171605

Signed-off-by: William André (wan) <wan@odoo.com>
Dasanchez1992 pushed a commit to Nosolotec/odoo that referenced this pull request Aug 22, 2024
When the current user is the system user, which happens
during install and upgrades, the env company is possibly
not included with the companies given to
_get_query_currency_table, this can lead to a KeyError
when fetching the rate for said company.

closes odoo#171605

Signed-off-by: William André (wan) <wan@odoo.com>
@fw-bot fw-bot deleted the 17.0-account-currency-companies-maji branch August 23, 2024 15:47
riccardo-metrum pushed a commit to resultrum/odoo that referenced this pull request Sep 30, 2024
When the current user is the system user, which happens
during install and upgrades, the env company is possibly
not included with the companies given to
_get_query_currency_table, this can lead to a KeyError
when fetching the rate for said company.

closes odoo#171605

Signed-off-by: William André (wan) <wan@odoo.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RD research & development, internal work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants