Skip to content

[IMP][16.0] project_sequence: set analytic's code as per project's sequence_code#1658

Open
arnaudlayec wants to merge 9 commits intoOCA:16.0from
arnaudlayec:16.0
Open

[IMP][16.0] project_sequence: set analytic's code as per project's sequence_code#1658
arnaudlayec wants to merge 9 commits intoOCA:16.0from
arnaudlayec:16.0

Conversation

@arnaudlayec
Copy link

Before, the project's display_name was synched in the project's analytic account (aac) name. This way, the "code" field of aac was empty, and the name had both the project's code and the name in the default format "[code] - [name]" Proposal : synch the 2 fields ("sequence_code" and "name") of the project respectively in the 2 fields ("code" and "name") of the aac

This allow:

  • standard display of aac (see aac's display_name method)
  • ability to target aac with according project's code. Can be useful when importing account move and needing to set an analytic_distribution using the aac's code

This PR also update tests.
I needed to fix some:

  • default_plan_id must be computed once to exist
  • the 2 following tests cannot coexist. I aligned the code & tests like in v18.0 : test_project_without_sequence and test_project_with_empty_sequence. Doing that required to change project's create method

Note: if OK, I can port to upper version.

@OCA-git-bot
Copy link
Contributor

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

Copy link
Member

@yajo yajo left a comment

Choose a reason for hiding this comment

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

Please could you share screenshots or screencast to see how it was before and how it is now? I think that will make it easier to review.

Code looks OK. Just one doubt.

@arnaudlayec
Copy link
Author

Please could you share screenshots or screencast to see how it was before and how it is now? I think that will make it easier to review.

Code looks OK. Just one doubt.

Thank you for your review!
Yes indeed, a quick Screencast here (00:32), with hr_timesheet installed so project's analytic account is created right at project creation.

Screencast.from.2026-01-20.14-08-38.mp4

Se how Analytic Account's field "code" is filled in, as per project's sequence code:
image

Copy link

@luisDIXMIT luisDIXMIT left a comment

Choose a reason for hiding this comment

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

Code review, LGTM!

@arnaudlayec
Copy link
Author

Please could you share screenshots or screencast to see how it was before and how it is now? I think that will make it easier to review.

Code looks OK. Just one doubt.

Hello @yajo , would you like to review this PR?

Copy link
Contributor

@alexey-pelykh alexey-pelykh 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 this improvement, @arnaudlayec. Syncing the project's name and sequence_code separately into the analytic account's name and code fields is the right approach -- it lets the AAC's own display_name handle formatting and makes code-based lookups possible (e.g. for analytic distribution in imports).

Code is clean and CI is green. One small gap I noticed:

In test_sync_analytic_account, you now assert proj.analytic_account_id.name == proj.name, but since the method now also writes code, it would be good to assert proj.analytic_account_id.code == proj.sequence_code as well -- for consistency with the other tests that already do this.

Also a note on the create condition change (not vals.get("sequence_code", False) -> "sequence_code" not in vals): this means passing sequence_code="" will no longer auto-assign a sequence. I see this aligns with v18.0, just flagging it as a behavioral change for other reviewers.

Otherwise LGTM.

proj.analytic_account_id = analytic_account
proj._sync_analytic_account_name()
self.assertEqual(proj.analytic_account_id.name, proj.display_name)
proj._sync_analytic_account()
Copy link
Contributor

Choose a reason for hiding this comment

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

The method now syncs both name and code, but this test only asserts name. Consider adding:

self.assertEqual(proj.analytic_account_id.code, proj.sequence_code)

The other test methods (test_analytic_account_after_creation_named, test_sequence_copied_to_name_if_emptied) already verify both fields.

Copy link
Contributor

@alexey-pelykh alexey-pelykh left a comment

Choose a reason for hiding this comment

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

Good improvement. Syncing sequence_code into the analytic account's code field separately from name is the right call -- it leverages the AAC's own display_name formatting and enables code-based lookups (useful for import scenarios with analytic_distribution).

CI is green, tests are updated and cover the new behavior well. The create condition change (not vals.get(...) to "sequence_code" not in vals) is a deliberate v18.0 alignment and has been discussed in the review thread.

One minor suggestion below (non-blocking).

Review posted via CorporateHub OCA review campaign

proj.analytic_account_id = analytic_account
proj._sync_analytic_account_name()
self.assertEqual(proj.analytic_account_id.name, proj.display_name)
proj._sync_analytic_account()
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (non-blocking): Since _sync_analytic_account() now writes both name and code, consider adding:

self.assertEqual(proj.analytic_account_id.code, proj.sequence_code)

The other test methods (test_analytic_account_after_creation_named, test_sequence_copied_to_name_if_emptied) already verify both fields -- this would keep coverage consistent.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for review, indeed the analytic's code should be tested here too, it's now added

@OCA-git-bot
Copy link
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

limit=1,
)
)
default_plan_id = cls.env.company.analytic_plan_id
Copy link
Member

Choose a reason for hiding this comment

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

question: regarding this change, I see a behavioral change. Before, an AAP without company would be considered as a default plan. Now, only the one from the company will be considered.

Could you please explain why this change?

Thanks!

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.

9 participants