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][MIG] stock_picking_analytic: Migration to 16.0 #527

Merged
merged 8 commits into from
Aug 8, 2023

Conversation

yostashiro
Copy link
Member

@yostashiro yostashiro commented Jan 21, 2023

  • Switch field from analytic_account_id to analytic_distribution.
  • Change depends referenced field from move_ids_without_package to move_ids. move_ids_without_package is a non-stored compute field and therefore is not appropriate to be used as a trigger (you get a warning message in running tests without this change). Add dummy search arg to move_ids_without_package to bypass warning.
  • Remove groups="analytic.group_analytic_accounting" from the analytic_distribution field added in the picking form, because it would cause an error Field 'analytic_distribution' used in context ({'default_company_id': company_id, 'default_date': scheduled_date, 'default_date_deadline': date_deadline, 'picking_type_code': picking_type_code, 'default_picking_id': id, 'form_view_ref': 'stock.view_move_form', 'address_in_id': partner_id, 'default_picking_type_id': picking_type_id, 'default_location_id': location_id, 'default_location_dest_id': location_dest_id, 'default_partner_id': partner_id, 'default_analytic_distribution': analytic_distribution}) is restricted to the group(s) analytic.group_analytic_accounting in loading the view. Looks like this refactoring odoo/odoo@0501bbd has added the check. Not sure there is a good way to still add the group to the field, however there is not much point doint it since the module wouldn't be installed without enabling the analytic accounting. -> Add an invisible analytic_distribution field without group assignment (thanks @luisg123v ).
  • Extension of the search view to add analytic_distribution field is disabled as the search on json fields do not work in a meaningful manner as of now.

@qrtl

@yostashiro yostashiro force-pushed the 16.0-mig-stock_picking_analytic branch 2 times, most recently from 4718794 to 88a8944 Compare January 21, 2023 14:29
@yostashiro yostashiro changed the title [16.0][MIG] stock_picking_analytic [16.0][MIG] stock_picking_analytic: Migration to 16.0 Jan 21, 2023
@yostashiro yostashiro force-pushed the 16.0-mig-stock_picking_analytic branch from 88a8944 to 8b8ae36 Compare January 21, 2023 16:08
@github-actions
Copy link

There hasn't been any activity on this pull request in the past 4 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days.
If you want this PR to never become stale, please ask a PSC member to apply the "no stale" label.

@github-actions github-actions bot added the stale PR/Issue without recent activity, it'll be soon closed automatically. label May 28, 2023
@rafaelbn rafaelbn removed the stale PR/Issue without recent activity, it'll be soon closed automatically. label Jun 1, 2023
@rafaelbn
Copy link
Member

rafaelbn commented Jun 1, 2023

/ocabot migration stock_picking_analytic

@OCA-git-bot OCA-git-bot added this to the 16.0 milestone Jun 1, 2023
@OCA-git-bot OCA-git-bot mentioned this pull request Jun 1, 2023
17 tasks
@rousseldenis
Copy link
Contributor

@yostashiro Shouldn't this deserves a migration script ?

@yostashiro
Copy link
Member Author

@yostashiro Shouldn't this deserves a migration script ?

@rousseldenis I was thinking no, as I thought the whole point of having analytic account (analytic distribution now) in the picking was to propagate the value to stock moves, and few people would care about the data persistency of itself (but I might be wrong). If anything, migration script should be added in https://github.com/OCA/account-analytic/tree/16.0/stock_analytic for analytic distribution of stock moves?

@yostashiro yostashiro force-pushed the 16.0-mig-stock_picking_analytic branch 2 times, most recently from 2b9e8e8 to 0c7d0f8 Compare June 14, 2023 15:45
Copy link

@desdelinux desdelinux left a comment

Choose a reason for hiding this comment

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

Functional review is ok.

cc @rolandojduartem @rousseldenis @luisg123v

@desdelinux
Copy link

@yostashiro Shouldn't this deserves a migration script ?

@rousseldenis I was thinking no, as I thought the whole point of having analytic account (analytic distribution now) in the picking was to propagate the value to stock moves, and few people would care about the data persistency of itself (but I might be wrong). If anything, migration script should be added in https://github.com/OCA/account-analytic/tree/16.0/stock_analytic for analytic distribution of stock moves?

@rousseldenis I agree with this

@rolandojduartem
Copy link

LGTM +1

@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). 🤖

Copy link

@luisg123v luisg123v left a comment

Choose a reason for hiding this comment

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

You're including commits that are not merged in the stable branch, some of which are even WIP:

Those are migration commits to 15.0, but this module is not migrated to 15.0 yet. I'd suggest either:

  • removing those ones from this migration
  • Or creating (first) a migration PR to 15.0 and, after that one is merged, resume this one

On the other hand:

"pre-commit" -> "pre-commit stuff"

# Assign a dummy search arg to the field to avoid triggering the warning.
# Without this, use of move_ids_without_package in @api.depends() of the compute
# method would trigger a warning from
# https://github.com/odoo/odoo/blob/ae94f14a844352f66490ec326fe2d1a716023891/odoo/fields.py#L808-L812 # noqa

Choose a reason for hiding this comment

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

If you use a shorter hash, line won't be as long and noqa won't be required, e.g.:

Suggested change
# https://github.com/odoo/odoo/blob/ae94f14a844352f66490ec326fe2d1a716023891/odoo/fields.py#L808-L812 # noqa
# https://github.com/odoo/odoo/blob/ae94f14a/odoo/fields.py#L808-L812

"move_ids": [
(
0,
0,

Choose a reason for hiding this comment

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

Prefer the Command syntax

Same below

Check analytic distribution on picking is set
"""
picking = self.picking
self.assertNotEqual(len(picking.move_ids), 0)

Choose a reason for hiding this comment

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

Suggested change
self.assertNotEqual(len(picking.move_ids), 0)
self.assertTrue(picking.move_ids)

Same below

<field name="inherit_id" ref="stock.view_picking_form" />
<field name="arch" type="xml">
<xpath expr="//group/group/field[@name='picking_type_id']" position="after">
<!-- groups="analytic.group_analytic_accounting" has been removed from

Choose a reason for hiding this comment

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

You just need to add the field again as invisible, so the field is included no matter if current user belongs to the group

@luisg123v
Copy link

PR description is a comprehensive one, it would be a shame if it's not included also in commit description.

@desdelinux
Copy link

@yostashiro Hello, you can apply the suggested changes

@yostashiro
Copy link
Member Author

@luisg123v @desdelinux Thanks for your review comments. Will try and follow up on them but give me some time. A bit swamped at the moment.

@rousseldenis
Copy link
Contributor

@yostashiro Any news on this ?

@yostashiro
Copy link
Member Author

I plan to update the PR this weekend.

@yostashiro yostashiro force-pushed the 16.0-mig-stock_picking_analytic branch from 0c7d0f8 to bc92469 Compare July 24, 2023 03:27
@yostashiro
Copy link
Member Author

@luisg123v @desdelinux @rousseldenis Thanks for waiting. Just updated the PR. I believe I took care of all the points in the feedback.

Copy link

@desdelinux desdelinux left a comment

Choose a reason for hiding this comment

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

Functional Review is ok.

cc @luisg123v @rousseldenis

@rolandojduartem
Copy link

@luisg123v could you review this PR?

widget="analytic_distribution"
groups="analytic.group_analytic_accounting"
/>
<!-- Just to prevent error in subsequent context update - assigining

Choose a reason for hiding this comment

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

Typo: assigining -> assigning

But I think this comment should be removed, this is not a special case but just the way v16 works. Most of views containing fields with groups (e.g. almost all views with the company_id field) define the same field as invisible.

A similar case occurred in previous versions when using a field in attrs that was not already present in the view

an invisible field that is accessible to everyone. -->
<field
name="analytic_distribution"
widget="analytic_distribution"

Choose a reason for hiding this comment

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

Since it's invisible, widget is meaningless

)
picking.move_ids_without_package.write(
picking.move_ids_without_package.update(

Choose a reason for hiding this comment

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

Why update instead of write?

write is preferred, because update writes fields one by one

Same below

Copy link
Member Author

Choose a reason for hiding this comment

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

write() would throw an error for picking.move_ids_without_package not having the database record when tests started. I have switched to assign move_ids instead of move_ids_without_package to the picking in the setup to use write() in tests.

- Switch field from analytic_account_id to analytic_distribution.
- Assign a dummy search arg to move_ids_without_package field (stock.picking) to bypass
  the warning from https://github.com/odoo/odoo/blob/0f84366/odoo/fields.py#L808-L812.
- Add an invisible analytic distribution field without group assignment in the picking
  form, due to newly added check in odoo/odoo@0501bbd.
@yostashiro yostashiro force-pushed the 16.0-mig-stock_picking_analytic branch from bc92469 to def630d Compare August 2, 2023 01:29
Copy link

@desdelinux desdelinux left a comment

Choose a reason for hiding this comment

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

Functional Review is ok.

@rousseldenis

@desdelinux
Copy link

@OCA/accounting-maintainers This one is ready

Copy link

@luisg123v luisg123v left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@luisg123v
Copy link

@moylop260,

Could you review/merge, please?

Regards,

@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). 🤖

@moylop260
Copy link

/ocabot merge nobump

@OCA-git-bot
Copy link
Contributor

Hey, thanks for contributing! Proceeding to merge this for you.
Prepared branch 16.0-ocabot-merge-pr-527-by-moylop260-bump-nobump, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit be6f573 into OCA:16.0 Aug 8, 2023
6 checks passed
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.

8 participants