Skip to content

Commit 8c24218

Browse files
committed
sale_stock_mto_as_mts_orderpoint: Add hooks
1 parent c7f9fa2 commit 8c24218

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from . import product
1+
from . import product_template
2+
from . import product_product
23
from . import sale_order
34
from . import stock_move
45
from . import stock_warehouse
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright 2023 Camptocamp SA
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
3+
4+
from odoo import models
5+
6+
class ProductProduct(models.Model):
7+
_inherit = "product.product"
8+
9+
def _variant_is_mto(self):
10+
self.ensure_one()
11+
mto_route = self.env.ref("stock.route_warehouse0_mto", raise_if_not_found=False)
12+
return mto_route in self.route_ids
13+
14+
def _variant_is_not_mto(self):
15+
return not self._variant_is_mto()

sale_stock_mto_as_mts_orderpoint/models/product.py renamed to sale_stock_mto_as_mts_orderpoint/models/product_template.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,21 @@ def write(self, vals):
2020
products_to_update._archive_orderpoints_on_mto_removal()
2121
return res
2222

23+
def _template_is_mto(self):
24+
self.ensure_one()
25+
mto_route = self.env.ref("stock.route_warehouse0_mto", raise_if_not_found=False)
26+
return mto_route in self.route_ids
27+
28+
def _template_is_not_mto(self):
29+
self.ensure_one()
30+
return not self._template_is_mto()
31+
2332
def _filter_mto_products(self, mto=True):
2433
mto_route = self.env.ref("stock.route_warehouse0_mto", raise_if_not_found=False)
2534
if mto:
26-
func = lambda p: mto_route in p.route_ids # noqa
35+
return self.filtered(lambda t: t._template_is_mto())
2736
else:
28-
func = lambda p: mto_route not in p.route_ids # noqa
29-
return self.filtered(func)
37+
return self.filtered(lambda t: t._template_is_not_mto())
3038

3139
def _get_orderpoints_to_archive_domain(self):
3240
warehouses = self.env["stock.warehouse"].search([])

sale_stock_mto_as_mts_orderpoint/models/sale_order.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def _run_orderpoints_for_mto_products(self):
2727
for delivery_move in delivery_moves:
2828
if (
2929
not delivery_move.is_from_mto_route
30-
or mto_route not in line.product_id.route_ids
30+
or line.product_id._variant_is_not_mto()
3131
):
3232
continue
3333
orderpoint = line._get_mto_orderpoint(delivery_move.product_id)

0 commit comments

Comments
 (0)