Skip to content

Commit b550f4c

Browse files
committed
Merge PR OCA#1970 into 18.0
Signed-off-by simahawk
2 parents be144c9 + c72cf8b commit b550f4c

File tree

16 files changed

+923
-0
lines changed

16 files changed

+923
-0
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
=========================
2+
Product Variant Route MTO
3+
=========================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:19127c85672968523ba9dac247eafabed27aaff202e5e8cc20d87b1f6ee204c6
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Alpha
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fproduct--attribute-lightgray.png?logo=github
20+
:target: https://github.com/OCA/product-attribute/tree/18.0/product_variant_route_mto
21+
:alt: OCA/product-attribute
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/product-attribute-18-0/product-attribute-18-0-product_variant_route_mto
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/product-attribute&target_branch=18.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
This module allows to define if a product variant can use the Make To
32+
Order route without any dependency on its template routes settings.
33+
34+
.. IMPORTANT::
35+
This is an alpha version, the data model and design can change at any time without warning.
36+
Only for development or testing purpose, do not use in production.
37+
`More details on development status <https://odoo-community.org/page/development-status>`_
38+
39+
**Table of contents**
40+
41+
.. contents::
42+
:local:
43+
44+
Bug Tracker
45+
===========
46+
47+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/product-attribute/issues>`_.
48+
In case of trouble, please check there if your issue has already been reported.
49+
If you spotted it first, help us to smash it by providing a detailed and welcomed
50+
`feedback <https://github.com/OCA/product-attribute/issues/new?body=module:%20product_variant_route_mto%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
51+
52+
Do not contact contributors directly about support or help with technical issues.
53+
54+
Credits
55+
=======
56+
57+
Authors
58+
-------
59+
60+
* Camptocamp SA
61+
62+
Contributors
63+
------------
64+
65+
- Matthieu Méquignon <[email protected]>
66+
- Akim Juillerat <[email protected]>
67+
68+
Maintainers
69+
-----------
70+
71+
This module is maintained by the OCA.
72+
73+
.. image:: https://odoo-community.org/logo.png
74+
:alt: Odoo Community Association
75+
:target: https://odoo-community.org
76+
77+
OCA, or the Odoo Community Association, is a nonprofit organization whose
78+
mission is to support the collaborative development of Odoo features and
79+
promote its widespread use.
80+
81+
.. |maintainer-mmequignon| image:: https://github.com/mmequignon.png?size=40px
82+
:target: https://github.com/mmequignon
83+
:alt: mmequignon
84+
85+
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
86+
87+
|maintainer-mmequignon|
88+
89+
This module is part of the `OCA/product-attribute <https://github.com/OCA/product-attribute/tree/18.0/product_variant_route_mto>`_ project on GitHub.
90+
91+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright 2023 Camptocamp SA
2+
# Copyright 2025 Jacques-Etienne Baudoux (BCIM) <[email protected]>
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
4+
5+
{
6+
"name": "Product Variant Route MTO",
7+
"summary": "Allow to individually set variants as MTO",
8+
"version": "18.0.1.0.0",
9+
"development_status": "Alpha",
10+
"category": "Inventory",
11+
"website": "https://github.com/OCA/product-attribute",
12+
"author": "Camptocamp SA, Odoo Community Association (OCA)",
13+
"maintainers": ["mmequignon", "jbaudoux"],
14+
"license": "AGPL-3",
15+
"installable": True,
16+
"auto_install": False,
17+
"depends": ["product_route_mto"],
18+
"data": ["views/product_product.xml"],
19+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import product_product
2+
from . import product_template
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Copyright 2023 Camptocamp SA
2+
# Copyright 2025 Jacques-Etienne Baudoux (BCIM) <[email protected]>
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
4+
5+
from odoo import api, fields, models
6+
from odoo.exceptions import ValidationError
7+
8+
IS_MTO_HELP = """
9+
Check or Uncheck this field to enable the Make To Order on the variant,
10+
independantly from its template configuration.\n
11+
Please note that activating or deactivating Make To Order on the template,
12+
will reset this setting on its variants.
13+
"""
14+
15+
16+
class ProductProduct(models.Model):
17+
_inherit = "product.product"
18+
19+
is_mto = fields.Boolean(
20+
string="Variant is MTO",
21+
compute="_compute_is_mto",
22+
store=True,
23+
readonly=False,
24+
help=IS_MTO_HELP,
25+
)
26+
27+
route_ids = fields.Many2many(
28+
"stock.route",
29+
compute="_compute_route_ids",
30+
domain="[('product_selectable', '=', True)]",
31+
store=False,
32+
search="_search_route_ids",
33+
)
34+
35+
def _compute_is_mto(self):
36+
for product in self:
37+
product.is_mto = product.product_tmpl_id.is_mto
38+
39+
@api.depends("is_mto", "product_tmpl_id.route_ids")
40+
def _compute_route_ids(self):
41+
mto_routes = self.env["stock.route"].search([("is_mto", "=", True)])
42+
for product in self:
43+
routes = product.product_tmpl_id.route_ids
44+
if product.is_mto:
45+
routes += mto_routes
46+
product.route_ids = routes
47+
48+
def _search_route_ids(self, operator, value):
49+
mto_routes = self.env["stock.route"].search([("is_mto", "=", True)])
50+
if operator in ("=", "!=") and value in mto_routes:
51+
return [("is_mto", operator, True)]
52+
domain = []
53+
route_ids = value.copy()
54+
for idx, route_id in enumerate(route_ids):
55+
if route_id in mto_routes.ids:
56+
route_ids.pop(idx)
57+
domain = [("is_mto", "=" if operator == "in" else "!=", True)]
58+
if route_ids:
59+
domain += [("product_tmpl_id.route_ids", operator, route_ids)]
60+
return domain
61+
62+
@api.constrains("is_mto")
63+
def _check_template_is_mto(self):
64+
for product in self:
65+
if not product.is_mto and product.product_tmpl_id.is_mto:
66+
raise ValidationError(
67+
self.env._(
68+
"You cannot mark a variant as non MTO when the product is MTO"
69+
)
70+
)
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Copyright 2023 Camptocamp SA
2+
# Copyright 2025 Jacques-Etienne Baudoux (BCIM) <[email protected]>
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
4+
5+
from odoo import api, models
6+
7+
8+
class ProductTemplate(models.Model):
9+
_inherit = "product.template"
10+
11+
def write(self, values):
12+
if "route_ids" not in values:
13+
return super().write(values)
14+
15+
# As _compute_is_mto cannot use api.depends (or it would reset MTO
16+
# route on variants as soon as there is a change on the template routes),
17+
# we need to check which template in self had MTO route activated
18+
# or deactivated to force the recomputation of is_mto on variants
19+
templates_mto_before = self.filtered("is_mto")
20+
templates_not_mto_before = self - templates_mto_before
21+
22+
res = super().write(values)
23+
24+
templates_mto_after = self.filtered("is_mto")
25+
templates_not_mto_after = self - templates_mto_after
26+
27+
templates_mto_added = templates_not_mto_before & templates_mto_after
28+
templates_mto_removed = templates_not_mto_after & templates_mto_before
29+
30+
(
31+
templates_mto_added | templates_mto_removed
32+
).product_variant_ids._compute_is_mto()
33+
34+
return res
35+
36+
@api.onchange("route_ids")
37+
def onchange_route_ids(self):
38+
mto_routes = self.env["stock.route"].search([("is_mto", "=", True)])
39+
if not mto_routes:
40+
return
41+
42+
origin_routes = (
43+
self._origin.route_ids if self._origin else self.env["stock.route"]
44+
)
45+
current_routes = (
46+
self.route_ids._origin if self.route_ids else self.env["stock.route"]
47+
)
48+
49+
added_routes = current_routes - origin_routes
50+
if set(mto_routes.ids) & set(added_routes.ids):
51+
# Return warning activating MTO route
52+
return {
53+
"warning": {
54+
"title": self.env._("Warning"),
55+
"message": self.env._(
56+
"Activating MTO route will reset `Variant is MTO` "
57+
"setting on the variants."
58+
),
59+
}
60+
}
61+
62+
removed_routes = origin_routes - current_routes
63+
if set(mto_routes.ids) & set(removed_routes.ids):
64+
# Return warning deactivating MTO route
65+
return {
66+
"warning": {
67+
"title": self.env._("Warning"),
68+
"message": self.env._(
69+
"Deactivating MTO route will reset `Variant is MTO` "
70+
"setting on the variants."
71+
),
72+
}
73+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["whool"]
3+
build-backend = "whool.buildapi"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The checkbox `Variant is MTO` on the product variant allows
2+
to force usage or non-usage of the MTO route for the variant.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- Matthieu Méquignon \<<[email protected]>\>
2+
- Akim Juillerat \<<[email protected]>\>
3+
- Chau Le \<<[email protected]>\>
4+
- Jacques-Etienne Baudoux (BCIM) \<<[email protected]>\>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The development and migration of this module has been financially supported by:
2+
3+
- Camptocamp

0 commit comments

Comments
 (0)