Skip to content

Commit

Permalink
[MIG] sale_exception_product_sale_manufactured_for: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukas Tran committed Feb 11, 2025
1 parent b66e280 commit 2eda0f8
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 16 deletions.
1 change: 1 addition & 0 deletions sale_exception_product_sale_manufactured_for/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Contributors
- `Trobz <https://trobz.com>`__:

- Son Ho <[email protected]>
- Nhan Tran <[email protected]>

Other credits
-------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"summary": "The partner set in the sales order can order only if he/she "
"has a commercial entity that is listed as one of the partners "
"for which the products can be manufactured for.",
"version": "14.0.1.1.0",
"version": "18.0.1.0.0",
"category": "Sales",
"website": "https://github.com/OCA/sale-workflow",
"author": "Camptocamp, Odoo Community Association (OCA)",
Expand Down
24 changes: 14 additions & 10 deletions sale_exception_product_sale_manufactured_for/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright 2021 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
from odoo import models
from odoo.tools import SQL


class SaleOrder(models.Model):
Expand All @@ -20,16 +21,19 @@ def exception_partner_can_order_manufactured_for(self):
commercial_entity = self.partner_id.commercial_partner_id

self.env.cr.execute(
"""
SELECT rel.product_id, ARRAY_AGG(rel.partner_id)
FROM sale_order_line sol
JOIN product_product prod ON (sol.product_id = prod.id)
JOIN product_product_manuf_for_partner_rel rel ON (rel.product_id = prod.id)
WHERE sol.display_type IS NULL
AND sol.order_id = %s
GROUP BY rel.product_id
""",
(self.id,),
SQL(
"""
SELECT rel.product_id, ARRAY_AGG(rel.partner_id)
FROM sale_order_line sol
JOIN product_product prod ON (sol.product_id = prod.id)
JOIN product_product_manuf_for_partner_rel rel
ON (rel.product_id = prod.id)
WHERE sol.display_type IS NULL
AND sol.order_id = %s
GROUP BY rel.product_id
""",
(self.id,),
),
)
for _, allowed_partner_ids in self.env.cr.fetchall():
# The product has limitations but the partner doesn't have
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
- [Camptocamp](https://www.camptocamp.com):
- [Camptocamp](https://www.camptocamp.com):
- Carlos Serra-Toro \<<[email protected]>\>
- Simone Orsi \<<[email protected]>\>
- Thierry Ducrest \<<[email protected]>\>

- [Trobz](https://trobz.com):
- [Trobz](https://trobz.com):
- Son Ho \<<[email protected]>\>
- Nhan Tran \<<[email protected]>\>
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ <h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
</li>
<li><a class="reference external" href="https://trobz.com">Trobz</a>:<ul>
<li>Son Ho &lt;<a class="reference external" href="mailto:sonhd&#64;trobz.com">sonhd&#64;trobz.com</a>&gt;</li>
<li>Nhan Tran &lt;<a class="reference external" href="mailto:nhant&#64;trobz.com">nhant&#64;trobz.com</a>&gt;</li>
</ul>
</li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# Copyright 2021 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

from odoo.tests import SavepointCase
from odoo.addons.base.tests.common import BaseCommon


class TestSaleException(SavepointCase):
class TestSaleException(BaseCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))

cls.exception = cls.env.ref(
"sale_exception_product_sale_manufactured_for.exception_partner_can_order"
Expand Down

0 comments on commit 2eda0f8

Please sign in to comment.