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

[17.0] [MIG] stock_putaway_hook: Migration to 17.0 #1842

Open
wants to merge 19 commits into
base: 17.0
Choose a base branch
from

Conversation

alexandregaldeano
Copy link

@alexandregaldeano alexandregaldeano commented Jan 21, 2025

  • replaced fields_view_get to _get_view and within it, attrs updates have been replaced by direct attributes changes
  • added odoo_test_helper as test dependency

guewen and others added 18 commits January 18, 2025 11:27
Add hooks allowing modules to add more putaway strategies.
It adds hooks to the core putaway method
``StockLocation._get_putaway_strategy()`` allowing to plug other
strategies and makes the selector fields in the tree views dynamic
(required/readonly).

The fields_view_get override is to handle a tricky issue:

By default, the product_id field as such attrs:

"{'readonly': [('category_id', '!=', False)], 'required': [('category_id', '=', False)]}"

And the category_id field:

"{'readonly': [('product_id', '!=', False)], 'required': [('product_id', '=', False)]}"

If we add a new field "route_id", we want to extend the domains to
include it, such as:

"{'readonly': ['|', ('category_id', '!=', False), ('route_id '!=', False)],
  'required': [('category_id', '=', False), ('route_id', '=', False)]}"

And every new field will need to be added in the product_id and
category_id field, but also in the other fields (exemple, if we add a
"foo_id" field, it needs to be added in the attrs of "route_id"), which
isn't possible with the extension mechanisms of the XML views.

The solution provided by this module is that new fields must have the
{'exclusive_selection': True} in the options attribute, and an override
of fields_view_get automatically generates the attrs for all these
"exclusive" fields.

The code here will be tested by `stock_putaway_by_route` in a follow-up
commit.
The module matching a putaway rule by a route can now:

* find a putaway rule by the route related to a stock move
* or a route related to the product on the move

The changes required to enable this feature:

* In stock_putaway_hook: in the part that match the value, support "in"
  when the value is a container (recordset, list, tuple), so we can pass
  product.route_ids (and match any route set on a put-away rule)
* In stock_putaway_by_route, in the various parts where
  `StockLocation._get_putaway_strategy()` is called, propagate the
  product's routes as well
* In StockMoveLine.onchange_product_id, remove the computation based on
  self.move_id: it cannot change.
…eturn a location mer 05 oct 2022 12:41:58

From v15, the _get_putaway_strategy() method on stock locations shoul always return a location.
Currently translated at 100.0% (2 of 2 strings)

Translation: stock-logistics-workflow-16.0/stock-logistics-workflow-16.0-stock_putaway_hook
Translate-URL: https://translation.odoo-community.org/projects/stock-logistics-workflow-16-0/stock-logistics-workflow-16-0-stock_putaway_hook/it/
@alexandregaldeano alexandregaldeano force-pushed the 17.0-mig-stock_putaway_hook branch 7 times, most recently from 2c96171 to 8140862 Compare January 21, 2025 13:24
@alexandregaldeano alexandregaldeano marked this pull request as ready for review January 21, 2025 13:30
@rousseldenis
Copy link
Contributor

/ocabot migration stock_putaway_hook

@OCA-git-bot OCA-git-bot added this to the 17.0 milestone Jan 22, 2025
@OCA-git-bot OCA-git-bot mentioned this pull request Jan 22, 2025
62 tasks
@rousseldenis
Copy link
Contributor

@alexandregaldeano Thanks for this. A test with Form could be great as _get_view() override is always touchy. Thanks

@alexandregaldeano alexandregaldeano force-pushed the 17.0-mig-stock_putaway_hook branch from 8140862 to 3fa31bd Compare January 23, 2025 16:28
@alexandregaldeano
Copy link
Author

alexandregaldeano commented Jan 23, 2025

@rousseldenis that was a great suggestion, I understand more how this code works. I have added tests as you suggested. But now I'm questioning whether the _get_view override is useful at all. I have added the following test to check what was the behavior without the module: 95a9784#diff-0c5186a1fcedfbbd1cd6b4d951d6a372b6c527330313759f55edb1f9e4a4f0a7R74
I feel like the changes in how Odoo 17 works make this part of the change irrelevant, what do you think?

@alexandregaldeano alexandregaldeano force-pushed the 17.0-mig-stock_putaway_hook branch from 3fa31bd to 95a9784 Compare January 23, 2025 16:33
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