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

[16.0][FIX] account_chart_update: avoid fiscal position duplication when it's archived #1973

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from

Conversation

edlopen
Copy link
Member

@edlopen edlopen commented Nov 19, 2024

Hi y'all!

I have encountered an error when running the chart of accounts update and one of its fiscal positions is archived, an attempt is made to recreate it and an error occurs as the unique key is duplicated. This simple correction makes the wizard take into account the fiscal positions that are archived.

@moduon MT-8097

@yajo @rafaelbn @fcvalgar please review, if you can.

Comment on lines +472 to +476
fiscal_position = self.env["account.fiscal.position"].search(
[("name", "=", self.fp_template.name), ("company_id", "=", self.company.id)]
)
Copy link
Member

Choose a reason for hiding this comment

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

issue: the test is incomplete AFAICS.

The use case we're testing involves a fiscal position template with tax mappings, and a fiscal position with the same tax mappings.

The issue was when those tax mappings were creating duplicate keys, so without tax mappings, the test is incomplete.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, I've made one mapping but I'm not sure if its the right way to declare them. I'll leave this review open to check this out.

Copy link
Member

Choose a reason for hiding this comment

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

If this assertion passes, then the test is OK:

Suggested change
fiscal_position = self.env["account.fiscal.position"].search(
[("name", "=", self.fp_template.name), ("company_id", "=", self.company.id)]
)
fiscal_position = self.env["account.fiscal.position"].search(
[("name", "=", self.fp_template.name), ("company_id", "=", self.company.id)]
)
self.assertEqual(fiscal_position.tax_ids.tax_src_id.name, self.tax_template.name)
self.assertEqual(fiscal_position.tax_ids.tax_dest_id.name, self.tax_template.name)

@rafaelbn rafaelbn added this to the 16.0 milestone Nov 19, 2024
@edlopen edlopen force-pushed the 16.0-fix-account_chart_update-fiscal_position_archived branch from c506083 to 1998550 Compare November 20, 2024 08:15
Comment on lines +472 to +476
fiscal_position = self.env["account.fiscal.position"].search(
[("name", "=", self.fp_template.name), ("company_id", "=", self.company.id)]
)
Copy link
Member

Choose a reason for hiding this comment

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

If this assertion passes, then the test is OK:

Suggested change
fiscal_position = self.env["account.fiscal.position"].search(
[("name", "=", self.fp_template.name), ("company_id", "=", self.company.id)]
)
fiscal_position = self.env["account.fiscal.position"].search(
[("name", "=", self.fp_template.name), ("company_id", "=", self.company.id)]
)
self.assertEqual(fiscal_position.tax_ids.tax_src_id.name, self.tax_template.name)
self.assertEqual(fiscal_position.tax_ids.tax_dest_id.name, self.tax_template.name)

wizard.action_update_records()
wizard.unlink()
self.assertTrue(fiscal_position.exists())
self.assertFalse(fiscal_position.active)
Copy link
Member

Choose a reason for hiding this comment

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

Please add again the assertion that checks tax mappings are OK.

Copy link
Member Author

Choose a reason for hiding this comment

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

Waiting for all checks to be passed but I guess it's ready to be merged now.

Copy link
Member

Choose a reason for hiding this comment

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

The test is failing:

2024-11-21 08:11:35,717 926 ERROR odoo odoo.addons.account_chart_update.tests.test_account_chart_update: FAIL: TestAccountChartUpdate.test_01_archived_fiscal_position
Traceback (most recent call last):
  File "/__w/account-financial-tools/account-financial-tools/account_chart_update/tests/test_account_chart_update.py", line 483, in test_01_archived_fiscal_position
    self.assertFalse(fiscal_position.active)
AssertionError: True is not false

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh! I see. I just found out that as the account.fiscal.position.template doesn't have the 'active' field, so when the wizard tries to update it makes it active again as is the default value for such field.

So now the error has been fixed but I would raise this question: Is it desirable to make those fiscal fiscal positions active again each time you run the wizard?

@edlopen edlopen force-pushed the 16.0-fix-account_chart_update-fiscal_position_archived branch 4 times, most recently from 6fdf2ce to 52aed36 Compare November 22, 2024 13:01
@edlopen edlopen force-pushed the 16.0-fix-account_chart_update-fiscal_position_archived branch from 52aed36 to dd6bf4f Compare November 22, 2024 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants