Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 4 additions & 1 deletion sale_purchase_force_vendor/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ Usage
1. Go to *Sale -> Orders -> Quotations* and create a new Quotation.
2. Create a new line with the following options:

- \`Route\`: MTO.
- \`Route\`: Any MTO-like route, i.e. a route that will trigger a buy
rule.
- \`Vendor\`: Vendor B.

3. Confirm sale order.
Expand Down Expand Up @@ -96,6 +97,8 @@ Contributors
- Víctor Martínez
- Pedro M. Baeza

- Marie Lejeune marie.lejeune@acsone.eu

Maintainers
-----------

Expand Down
5 changes: 4 additions & 1 deletion sale_purchase_force_vendor/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
"website": "https://github.com/OCA/purchase-workflow",
"author": "Tecnativa, Odoo Community Association (OCA)",
"license": "AGPL-3",
"depends": ["sale_purchase_stock"],
"depends": [
"sale_order_line_chained_move",
"sale_purchase_stock",
],
"installable": True,
"data": [
"views/res_config_settings_view.xml",
Expand Down
9 changes: 6 additions & 3 deletions sale_purchase_force_vendor/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ def _prepare_procurement_values(self):
res = super()._prepare_procurement_values()
# Get all chained moves to get sale line
moves = self.browse(list(self._rollup_move_dests({self.id})))
move_sale = moves.filtered("sale_line_id")[:1]
if move_sale.sale_line_id.vendor_id:
res_order_line = move_sale.sale_line_id._prepare_procurement_values(
move_sale = moves.filtered(lambda x: x.sale_line_id or x.related_sale_line_id)[
:1
]
related_sale = move_sale.sale_line_id or move_sale.related_sale_line_id
if related_sale.vendor_id:
res_order_line = related_sale._prepare_procurement_values(
group_id=move_sale.group_id
)
res.update({"supplierinfo_id": res_order_line["supplierinfo_id"]})
Expand Down
2 changes: 2 additions & 0 deletions sale_purchase_force_vendor/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
- [Tecnativa](https://www.tecnativa.com):
- Víctor Martínez
- Pedro M. Baeza

- Marie Lejeune <marie.lejeune@acsone.eu>
2 changes: 1 addition & 1 deletion sale_purchase_force_vendor/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
1. Go to *Sale -\> Orders -\> Quotations* and create a new Quotation.
2. Create a new line with the following options:
- \`Route\`: MTO.
- \`Route\`: Any MTO-like route, i.e. a route that will trigger a buy rule.
- \`Vendor\`: Vendor B.
3. Confirm sale order.
4. A new purchase order will have been created to Vendor B.
Expand Down
4 changes: 3 additions & 1 deletion sale_purchase_force_vendor/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,8 @@ <h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
<ol class="arabic simple">
<li>Go to <em>Sale -&gt; Orders -&gt; Quotations</em> and create a new Quotation.</li>
<li>Create a new line with the following options:<ul>
<li>`Route`: MTO.</li>
<li>`Route`: Any MTO-like route, i.e. a route that will trigger a buy
rule.</li>
<li>`Vendor`: Vendor B.</li>
</ul>
</li>
Expand Down Expand Up @@ -446,6 +447,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<li>Pedro M. Baeza</li>
</ul>
</li>
<li>Marie Lejeune <a class="reference external" href="mailto:marie.lejeune&#64;acsone.eu">marie.lejeune&#64;acsone.eu</a></li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Copyright 2022 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo.addons.sale_order_line_chained_move.tests.test_chained_move import (
TestSaleChainedMove as TestSaleOrderLineChainedMoveBase,
)

from .common import TestSalePurchaseForceVendorBase


Expand Down Expand Up @@ -31,3 +35,54 @@ def test_misc_not_force_vendor_restrict(self):
self.sale_order.action_confirm()
self.assertEqual(self.sol_a.vendor_id_domain, [])
self.assertEqual(self.sol_b.vendor_id_domain, [])


class TestSalePurchaseForceVendorChainedMove(TestSaleOrderLineChainedMoveBase):
"""
This class makes a test with another route than the default Odoo MTO route.
It uses the route defined in sale_order_line_chained_move, which is a
3-steps delivery: Pick/Pack/Ship.
"""

def test_force_vendor_on_mto_like_route(self):
"""
Test that the vendor is correctly forced on a PO even on a more
complicated MTO-like route.
We configure the rules of the route as following:
Out -> Customer: pull; make_to_order
Pack -> Out: pull; make_to_order
Stock -> Pack: pull; make_to_order
In Stock: buy route
The 3 first rules are defined in sale_order_line_chained_move test class.
We add the buy route in this test.
"""
self.stock_out_rule.procure_method = "make_to_order"
self.env["stock.rule"].create(
{
"name": "Buy",
"route_id": self.route.id,
"action": "buy",
"location_dest_id": self.env.ref("stock.stock_location_stock").id,
"picking_type_id": self.env.ref("stock.picking_type_in").id,
}
)
vendor_a = self.env["res.partner"].create({"name": "Test Vendor A"})
vendor_b = self.env["res.partner"].create({"name": "Test Vendor B"})
self.product1.seller_ids = [
(0, 0, {"partner_id": vendor_a.id, "min_qty": 1, "price": 10}),
(0, 0, {"partner_id": vendor_b.id, "min_qty": 1, "price": 20}),
]
so = self.env["sale.order"].create(
{
"partner_id": self.env["res.partner"]
.create({"name": "Test Customer"})
.id,
"order_line": [
(0, 0, {"product_id": self.product1.id, "vendor_id": vendor_b.id})
],
}
)
so.action_confirm()
po = so._get_purchase_orders()
self.assertEqual(len(po), 1, "A purchase order should have been created")
self.assertEqual(po.partner_id, vendor_b)