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

[14.0][IMP/ADD] stock_product_variant_mto, sale_stock_mto_as_mts_orderpoint_product_variant: Handle mto route at variant level #1461

Draft
wants to merge 6 commits into
base: 14.0
Choose a base branch
from

Conversation

mmequignon
Copy link
Member

I have to move commits in dedicated PRs, but pushed everything here for the time being

@mmequignon mmequignon force-pushed the handle_mto_route_at_variant_level branch from e394efc to 4cccd24 Compare December 22, 2023 12:10
mto_route_product_variant/__manifest__.py Outdated Show resolved Hide resolved
mto_route_product_variant/models/product_product.py Outdated Show resolved Hide resolved
mto_route_product_variant/models/product_product.py Outdated Show resolved Hide resolved
mto_route_product_variant/__manifest__.py Outdated Show resolved Hide resolved
Copy link
Contributor

@grindtildeath grindtildeath left a comment

Choose a reason for hiding this comment

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

I'm wondering if the issue at hand couldn't be solved by redefining route_ids as a computed field on product.product and then select the MTO route in the compute function only if the is_mto field is marked?

Maybe we should discuss this together.

mto_route_product_variant/__manifest__.py Outdated Show resolved Hide resolved
mto_route_product_variant/models/product_product.py Outdated Show resolved Hide resolved
mto_route_product_variant/models/product_product.py Outdated Show resolved Hide resolved
mto_route_product_variant/models/product_product.py Outdated Show resolved Hide resolved
mto_route_product_variant/models/product_template.py Outdated Show resolved Hide resolved
mto_route_product_variant/models/product_product.py Outdated Show resolved Hide resolved
@mmequignon mmequignon force-pushed the handle_mto_route_at_variant_level branch 2 times, most recently from 5badb3f to e694809 Compare January 9, 2024 10:26
@api.onchange("route_ids")
def onchange_route_ids(self):
mto_route = self.env.ref("stock.route_warehouse0_mto", raise_if_not_found=False)
if mto_route not in self._origin.route_ids and mto_route in self.route_ids._origin:
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess we can make the condition more selective and raise the warning only if we have multiple variants, and these variants have different MTO settings.

"message": _("Activating MTO route will reset `Variant is MTO` setting on the variants.")
}
}
if mto_route in self._origin.route_ids and mto_route not in self.route_ids._origin:
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above

templates_mto_after = self.filtered(lambda t: mto_route in t.route_ids)
templates_mto_added = template_not_mto_before & templates_mto_after
templates_mto_removed = (self - template_not_mto_before) & (self - templates_mto_after)
(templates_mto_added | templates_mto_removed).product_variant_ids._compute_is_mto()
Copy link
Contributor

Choose a reason for hiding this comment

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

return res missing

@mmequignon mmequignon force-pushed the handle_mto_route_at_variant_level branch from f4bc814 to 6d7b34d Compare January 24, 2024 09:53
@sebalix sebalix changed the title [14.0][IMP/ADD] Handle mto route at variant level [14.0][IMP/ADD] stock_product_variant_mto, sale_stock_mto_as_mts_orderpoint_product_variant: Handle mto route at variant level Apr 19, 2024
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 Aug 18, 2024
@github-actions github-actions bot closed this Sep 22, 2024
@simahawk
Copy link
Contributor

@mmequignon to be reopened?

@mmequignon
Copy link
Member Author

@mmequignon to be reopened?

yes please

@simahawk simahawk reopened this Sep 23, 2024
@simahawk simahawk removed the stale PR/Issue without recent activity, it'll be soon closed automatically. label Sep 23, 2024
mmequignon and others added 5 commits October 11, 2024 15:14
Define route_ids as computed on the product variant, in order to
reuse route_ids from its template and add or remove MTO route
according to the setting on the variant.

In case MTO route is changed on the template, it must reset any
variant specific setting.
self.ensure_one()
return self.is_mto

def _inverse_is_mto(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Where is this defined on the field? I don't think this is called.
Check you have a unit test for this (archiving orderpoint when variant is not MTO anymore)

@mmequignon
Copy link
Member Author

I'll rollback @grindtildeath changes as it doesn't work.
Saving a backup with current code here https://github.com/camptocamp/stock-logistics-workflow/tree/handle_mto_route_at_variant_level_backup

@mmequignon mmequignon force-pushed the handle_mto_route_at_variant_level branch from d634638 to bc17928 Compare February 10, 2025 12:58
@mmequignon
Copy link
Member Author

For reviewers, I know a test is failing, this is because in sale_stock_mto_as_mts_orderpoint mto products are enabled/disabled differently. I have to modify this, but feature works, tested from the ui.

@grindtildeath grindtildeath force-pushed the handle_mto_route_at_variant_level branch from bc17928 to 4ed01c0 Compare February 10, 2025 19:53
There were multiple issues:

- Inverse function on storable field is not reliable and we should
prefer overriding write to add any processing when the field value
is changed. Moreover, the field is_mto on product.product did not
have its inverse function set on the field, so the function was not
called.

- When mto_as_mts is changed on the warehouse, we do not want to
archive MTO rule for this warehouse (because we could still want
to do MTO but not "as MTS").
@grindtildeath grindtildeath force-pushed the handle_mto_route_at_variant_level branch from 4ed01c0 to 3d81b69 Compare February 10, 2025 19:57
Copy link

@henrybackman henrybackman left a comment

Choose a reason for hiding this comment

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

Looks good 👍

@@ -0,0 +1,19 @@
# Copyright 2024 Camptocamp SA

Choose a reason for hiding this comment

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

Inconsistent years

Suggested change
# Copyright 2024 Camptocamp SA
# Copyright 2025 Camptocamp SA

@@ -0,0 +1,39 @@
# Copyright 2023 Camptocamp SA

Choose a reason for hiding this comment

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

Suggested change
# Copyright 2023 Camptocamp SA
# Copyright 2025 Camptocamp SA

return res

def _get_orderpoints_to_archive_domain(self, warehouse):
# Orderpoints to archive are those where

Choose a reason for hiding this comment

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

Incomplete comment?

@@ -0,0 +1,155 @@
# Copyright 2023 Camptocamp SA

Choose a reason for hiding this comment

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

Suggested change
# Copyright 2023 Camptocamp SA
# Copyright 2025 Camptocamp SA

@@ -0,0 +1,18 @@
# Copyright 2023 Camptocamp SA

Choose a reason for hiding this comment

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

Suggested change
# Copyright 2023 Camptocamp SA
# Copyright 2025 Camptocamp SA


IS_MTO_HELP = """
Check or Uncheck this field to enable the Make To Order on the variant,
independantly from its template configuration.\n

Choose a reason for hiding this comment

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

Suggested change
independantly from its template configuration.\n
independently from its template configuration.\n

@@ -0,0 +1,44 @@
# Copyright 2023 Camptocamp SA

Choose a reason for hiding this comment

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

Suggested change
# Copyright 2023 Camptocamp SA
# Copyright 2025 Camptocamp SA

@@ -0,0 +1,80 @@
# Copyright 2023 Camptocamp SA

Choose a reason for hiding this comment

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

Suggested change
# Copyright 2023 Camptocamp SA
# Copyright 2025 Camptocamp SA

@@ -0,0 +1,108 @@
# Copyright 2023 Camptocamp SA

Choose a reason for hiding this comment

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

Suggested change
# Copyright 2023 Camptocamp SA
# Copyright 2025 Camptocamp SA

@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2023 Camptocamp SA

Choose a reason for hiding this comment

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

Suggested change
<!-- Copyright 2023 Camptocamp SA
<!-- Copyright 2025 Camptocamp SA

help=IS_MTO_HELP,
)

route_ids = fields.Many2many(
Copy link
Member

@TDu TDu Feb 11, 2025

Choose a reason for hiding this comment

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

If find having this field on product.product for handling the feature of this module worrisome and could be conflicting with other modules or implementation...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants