-
-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] stock_buffer_route: Do not consider other locations Buy routes
Considering all buy routes should not be the default behaviour. If this is needed should be in a customized module.
- Loading branch information
1 parent
ebe311d
commit 4382fd6
Showing
5 changed files
with
90 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
from . import mrp_production | ||
from . import purchase_order | ||
from . import stock_buffer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Copyright 2023 ForgeFlow S.L. (https://www.forgeflow.com) | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). | ||
|
||
from odoo import models | ||
|
||
|
||
class MrpProduction(models.Model): | ||
_inherit = "mrp.production" | ||
|
||
def _get_domain_buffer_link_alternative(self, warehouse_level=False): | ||
self.ensure_one() | ||
if not warehouse_level: | ||
locations = self.env["stock.location"].search( | ||
[("id", "child_of", [self.location_dest_id.id])] | ||
) | ||
return [ | ||
("product_id", "=", self.product_id.id), | ||
("company_id", "=", self.company_id.id), | ||
("item_type_alternative", "=", "manufactured"), | ||
("location_id", "in", locations.ids), | ||
] | ||
else: | ||
return [ | ||
("product_id", "=", self.product_id.id), | ||
("company_id", "=", self.company_id.id), | ||
("item_type_alternative", "=", "manufactured"), | ||
("warehouse_id", "=", self.picking_type_id.warehouse_id.id), | ||
] | ||
|
||
def _find_buffer_link(self): | ||
res = super()._find_buffer_link() | ||
buffer_model = self.env["stock.buffer"] | ||
for rec in self.filtered(lambda r: not r.buffer_id): | ||
domain = rec._get_domain_buffer_link_alternative() | ||
buffer = buffer_model.search(domain, limit=1) | ||
if not buffer: | ||
domain = rec._get_domain_buffer_link_alternative(warehouse_level=True) | ||
buffer = buffer_model.search(domain, limit=1) | ||
rec.buffer_id = buffer | ||
if buffer: | ||
rec._calc_execution_priority() | ||
return res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Copyright 2023 ForgeFlow S.L. (https://www.forgeflow.com) | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). | ||
|
||
from odoo import models | ||
|
||
|
||
class PurchaseOrderLine(models.Model): | ||
_inherit = "purchase.order.line" | ||
|
||
def _get_domain_buffer_link_alternative(self): | ||
self.ensure_one() | ||
if not self.product_id: | ||
# Return impossible domain -> no buffer. | ||
return [(0, "=", 1)] | ||
return [ | ||
("product_id", "=", self.product_id.id), | ||
("company_id", "=", self.order_id.company_id.id), | ||
("item_type_alternative", "=", "purchased"), | ||
("warehouse_id", "=", self.order_id.picking_type_id.warehouse_id.id), | ||
] | ||
|
||
def _find_buffer_link(self): | ||
res = super()._find_buffer_link() | ||
buffer_model = self.env["stock.buffer"] | ||
move_model = self.env["stock.move"] | ||
for rec in self.filtered(lambda r: not r.buffer_ids): | ||
mto_move = move_model.search( | ||
[("created_purchase_line_id", "=", rec.id)], limit=1 | ||
) | ||
if mto_move: | ||
# MTO lines are not accounted in MTS stock buffers. | ||
continue | ||
domain = rec._get_domain_buffer_link_alternative() | ||
buffer = buffer_model.search(domain, limit=1) | ||
if buffer: | ||
rec.buffer_ids = buffer | ||
rec._calc_execution_priority() | ||
return res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters