Skip to content

Commit

Permalink
[IMP] sale_purchase_force_vendor: propagate on stock rules
Browse files Browse the repository at this point in the history
See related issue OCA#2574
  • Loading branch information
marielejeune committed Feb 18, 2025
1 parent f13a5f6 commit fee4373
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 15 deletions.
16 changes: 8 additions & 8 deletions sale_purchase_force_vendor/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,18 @@ To configure this module, you need to:
5. Go to *Sale -> Products -> Products*.
6. Create a new product with the following options:

- [Puchase tab] \`Vendors\`: Set different vendors (Vendor A +
Vendor B).
- [Iventory tab] \`Routes\`: Buy and MTO
- [Puchase tab] \`Vendors\`: Set different vendors (Vendor A + Vendor
B).
- [Iventory tab] \`Routes\`: Buy and MTO

Usage
=====

1. Go to *Sale -> Orders -> Quotations* and create a new Quotation.
2. Create a new line with the following options:

- \`Route\`: MTO.
- \`Vendor\`: Vendor B.
- \`Route\`: MTO.
- \`Vendor\`: Vendor B.

3. Confirm sale order.
4. A new purchase order will have been created to Vendor B.
Expand Down Expand Up @@ -91,10 +91,10 @@ Authors
Contributors
------------

- `Tecnativa <https://www.tecnativa.com>`__:
- `Tecnativa <https://www.tecnativa.com>`__:

- Víctor Martínez
- Pedro M. Baeza
- Víctor Martínez
- Pedro M. Baeza

Maintainers
-----------
Expand Down
36 changes: 31 additions & 5 deletions sale_purchase_force_vendor/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,48 @@
# Copyright 2022 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import models
from odoo import api, fields, models


class StockMove(models.Model):
_inherit = "stock.move"

propagated_sale_line_id = fields.Many2one(
comodel_name="sale.order.line",
string="Propagated SOL",
compute="_compute_propagated_sale_line_id",
store=True,
help="Propagate the sale order line on the chained moves "
"to get it on the purchase move and "
"be able to retrieve the forced vendor",
)

@api.depends("sale_line_id")
def _compute_propagated_sale_line_id(self):
for rec in self:
rec.propagated_sale_line_id = rec.sale_line_id

def _prepare_procurement_values(self):
"""Inject the preferred vendor in case of an MTO that first creates the OUT
move.
"""
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(
group_id=move_sale.group_id
# Propagate the sale line from the dest moves
if any(m.propagated_sale_line_id for m in moves.move_dest_ids):
moves.write(
{
"propagated_sale_line_id": moves.move_dest_ids.mapped(
"propagated_sale_line_id"
)[0].id
}
)
move_sale = moves.filtered("propagated_sale_line_id")[:1]
if move_sale.propagated_sale_line_id.vendor_id:
res_order_line = (
move_sale.propagated_sale_line_id._prepare_procurement_values(
group_id=move_sale.group_id
)
)
res.update({"supplierinfo_id": res_order_line["supplierinfo_id"]})
return res
4 changes: 2 additions & 2 deletions sale_purchase_force_vendor/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,8 @@ <h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
“Unarchived” MTO route.</li>
<li>Go to <em>Sale -&gt; Products -&gt; Products</em>.</li>
<li>Create a new product with the following options:<ul>
<li>[Puchase tab] `Vendors`: Set different vendors (Vendor A +
Vendor B).</li>
<li>[Puchase tab] `Vendors`: Set different vendors (Vendor A + Vendor
B).</li>
<li>[Iventory tab] `Routes`: Buy and MTO</li>
</ul>
</li>
Expand Down

0 comments on commit fee4373

Please sign in to comment.