Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions sale_stock_mto_as_mts_orderpoint_product_variant/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ Contributors
------------

- Matthieu Méquignon <[email protected]>
- Chau Le <[email protected]>

Other credits
-------------

The development and migration of this module has been financially
supported by:

- Camptocamp

Maintainers
-----------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{
"name": "Sale Stock MTO as MTS Orderpoint Product Variant",
"version": "14.0.1.0.0",
"version": "18.0.1.0.0",
"development_status": "Alpha",
"category": "Operations/Inventory/Delivery",
"website": "https://github.com/OCA/stock-logistics-workflow",
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import product_product
from . import sale_order_line
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
# Copyright 2023 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

from odoo import api, models
from odoo import fields, models


class ProductProduct(models.Model):
_inherit = "product.product"

is_mto = fields.Boolean(inverse="_inverse_is_mto")

def _variant_is_mto(self):
self.ensure_one()
return self.is_mto

def _inverse_is_mto(self):
res = super()._inverse_is_mto()
self._archive_orderpoints_on_mto_removal()
return res

@api.depends("product_tmpl_id.route_ids")
Copy link

@xaviedoanhduy xaviedoanhduy Jan 13, 2025

Choose a reason for hiding this comment

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

why remove this code, i see that route_ids are already stored in this module:

def _compute_is_mto(self):
# Archive orderpoints when variant becomes not mto
res = super()._compute_is_mto()
Expand Down

Choose a reason for hiding this comment

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

just 1 question: is it really necessary?

Copy link
Owner Author

Choose a reason for hiding this comment

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

thanks, after I fixed sale_stock_mto_as_mts_orderpoint, it is not necessary

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2025 Camptocamp
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
from odoo import models


class SaleOrderLine(models.Model):
_inherit = "sale.order.line"

def _get_mto_orderpoint(self, product_id):
orderpoint = super()._get_mto_orderpoint(product_id)

if not product_id.is_mto:
orderpoint.write({"active": False})

return orderpoint
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- Matthieu Méquignon \<<[email protected]>\>
- Chau Le \<<[email protected]>\>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The development and migration of this module has been financially supported by:

- Camptocamp
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,8 @@ <h1 class="title">Sale Stock MTO as MTS Orderpoint Product Variant</h1>
<li><a class="reference internal" href="#credits" id="toc-entry-2">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-3">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-4">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-5">Maintainers</a></li>
<li><a class="reference internal" href="#other-credits" id="toc-entry-5">Other credits</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-6">Maintainers</a></li>
</ul>
</li>
</ul>
Expand All @@ -410,10 +411,19 @@ <h2><a class="toc-backref" href="#toc-entry-3">Authors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
<ul class="simple">
<li>Matthieu Méquignon &lt;<a class="reference external" href="mailto:matthieu.mequignon&#64;camptocamp.com">matthieu.mequignon&#64;camptocamp.com</a>&gt;</li>
<li>Chau Le &lt;<a class="reference external" href="mailto:chaulb&#64;trobz.com">chaulb&#64;trobz.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="other-credits">
<h2><a class="toc-backref" href="#toc-entry-5">Other credits</a></h2>
<p>The development and migration of this module has been financially
supported by:</p>
<ul class="simple">
<li>Camptocamp</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-5">Maintainers</a></h2>
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def setUpClass(cls):
cls.env["product.supplierinfo"].create(
[
{
"name": cls.vendor_partner.id,
"partner_id": cls.vendor_partner.id,
"product_tmpl_id": variant.product_tmpl_id.id,
"product_id": variant.id,
"min_qty": 1.0,
Expand All @@ -25,9 +25,10 @@ def setUpClass(cls):
]
)
cls.warehouse = cls.env.ref("stock.warehouse0")
cls.warehouse.mto_as_mts = True

@classmethod
def setUpClassProduct(cls):
def setUpClassProduct(cls): # pylint: disable=missing-return
super().setUpClassProduct()
cls.buy_route = cls.env.ref("purchase_stock.route_warehouse0_buy")
cls.template_pen.write(
Expand All @@ -46,13 +47,13 @@ def _create_sale_order(cls, products):
return sale_form.save()

def _get_orderpoint_for_products(self, products, archived=False):
orderpoint = self.env["stock.warehouse.orderpoint"]
if archived:
orderpoint = orderpoint.with_context(active_test=False)
return orderpoint.search([("product_id", "in", products.ids)])
return (
self.env["stock.warehouse.orderpoint"]
.with_context(active_test=not archived)
.search([("product_id", "in", products.ids)])
)

def test_mto_as_mts_orderpoint(self):
template_pen = self.template_pen
black_pen = self.black_pen
blue_pen = self.blue_pen
red_pen = self.red_pen
Expand Down Expand Up @@ -88,7 +89,7 @@ def test_mtp_as_mts_orderpoint_product_no_mto(self):
variants_pen = self.variants_pen
# set everything to not mto
template_pen.route_ids = False
self.toggle_is_mto(variants_pen)
variants_pen.write({"is_mto": False})
# then check that no orderpoint is created
order = self._create_sale_order(black_pen)
orderpoint = self.env["stock.warehouse.orderpoint"].search(
Expand All @@ -104,7 +105,7 @@ def test_mtp_as_mts_orderpoint_product_no_mto(self):
def test_cancel_sale_order_orderpoint(self):
order = self._create_sale_order(self.variants_pen)
order.action_confirm()
order.action_cancel()
order.with_context(disable_cancel_warning=True).action_cancel()
order.action_draft()
order.action_confirm()
self.assertEqual(order.state, "sale")
Expand Down