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: fixed import name for account test case #159112

Open
wants to merge 1 commit into
base: saas-16.3
Choose a base branch
from

Conversation

atp-odoo
Copy link
Contributor

During upgrade got the import name error:

'odoo.addons.account.models.chart_template' ```

`code_translations` function defined in odoo.tools.translate
and there is function `get_python_translations`
by mistake give `from odoo.tools.translate import code_translations`
to correct that.

File "/home/odoo/src/odoo/17.0/addons/stock_account/tests/test_account_move.py", line 4, in
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
File "/home/odoo/src/odoo/17.0/addons/account/tests/init.py", line 22, in
from . import test_chart_template
File "/home/odoo/src/odoo/17.0/addons/account/tests/test_chart_template.py", line 4, in
from odoo.addons.account.models.chart_template import code_translations
ImportError: cannot import name 'code_translations' from 'odoo.addons.account.models.chart_template' (/home/odoo/src/odoo/17.0/addons/account/models/chart_template.py)


Description of the issue/feature this PR addresses:

Current behavior before PR:

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 Mar 25, 2024

Pull request status dashboard.

@C3POdoo C3POdoo requested review from a team and hupo-odoo and removed request for a team March 25, 2024 13:33
@atp-odoo atp-odoo force-pushed the saas-16.3-fix-import-code-translation-atp branch from 30a8597 to 7c5c580 Compare March 25, 2024 13:37
@C3POdoo C3POdoo added the RD research & development, internal work label Mar 25, 2024
It appears that during an upgrade process, there was an ImportError
due to a change in the import statement for the code_translations
function within the odoo.addons.account.models.chart_template module.
The correct import should be from odoo.tools.translate,
not from odoo.addons.account.models.chart_template.

```
from odoo.tools.translate import get_python_translations

```

The traceback indicates that the error occurred in the test file test_chart_template.py.
Here's the formatted error message:

```
 File "/home/odoo/src/odoo/17.0/addons/stock_account/tests/test_account_move.py", line 4, in <module>
    from odoo.addons.account.tests.common import AccountTestInvoicingCommon
  File "/home/odoo/src/odoo/17.0/addons/account/tests/__init__.py", line 22, in <module>
    from . import test_chart_template
  File "/home/odoo/src/odoo/17.0/addons/account/tests/test_chart_template.py", line 4, in <module>
    from odoo.addons.account.models.chart_template import code_translations
ImportError: cannot import name 'code_translations' from 'odoo.addons.account.models.chart_template' (/home/odoo/src/odoo/17.0/addons/account/models/chart_template.py)
```
@atp-odoo atp-odoo force-pushed the saas-16.3-fix-import-code-translation-atp branch from 7c5c580 to 3165d0c Compare March 25, 2024 14:13
with patch.object(code_translations, 'python_translations', mock_python_translations):
with patch.object(code_translations, 'get_python_translations', mock_python_translations):
Copy link
Contributor

Choose a reason for hiding this comment

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

Hello, thanks for the PR. Why do you do this change ? Your commit message does not explain why you change the dictionary object python_translations to the function get_python_translations. This is wrong since mock_python_translations is itself a dictionary. The error you get with the upgrade seems only related to the wrong import, not this test. With your change, the test TestChartTemplate.test_install_with_translations is failing

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.

None yet

4 participants