Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][FIX] added case when resupply from another warehouse #229

Merged
Merged
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
2 changes: 1 addition & 1 deletion ddmrp/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"name": "DDMRP",
"summary": "Demand Driven Material Requirements Planning",
"version": "14.0.1.14.0",
"version": "14.0.1.14.1",
"license": "LGPL-3",
"development_status": "Beta",
"author": "ForgeFlow, " "Odoo Community Association (OCA)",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from odoo import SUPERUSER_ID, api


def migrate(cr, version):
env = api.Environment(cr, SUPERUSER_ID, {})
buffers = env["stock.buffer"].search(
[("buffer_profile_id.item_type", "=", "distributed")]
)
if buffers:
buffers._calc_distributed_source_location()
22 changes: 21 additions & 1 deletion ddmrp/models/stock_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1742,7 +1742,6 @@ def _values_source_location_from_route(self):

def _source_location_from_route(self, route=None):
"""Return the replenishment source location for distributed buffers

If no route is passed, it follows the source location of the rules of
all the routes it finds until it can no longer find a path.
If a route is passed, it stops at the final source location of the
Expand All @@ -1756,6 +1755,27 @@ def _source_location_from_route(self, route=None):
)
if rule.procure_method == "make_to_stock":
return rule.location_src_id
elif rule.procure_method == "make_to_order":
# If resupply from another warehouse, this rule can't be retrieved by
# method _get_rule, because that we try to get this rule bases on previous rule
pull_rule = self.env["stock.rule"].search(
ChrisOForgeFlow marked this conversation as resolved.
Show resolved Hide resolved
[
("action", "in", ("pull", "pull_push")),
("route_id", "=", rule.route_id.id),
("location_id", "=", rule.location_src_id.id),
]
)
if pull_rule:
if pull_rule.procure_method in ("make_to_stock", "mts_else_mto"):
return pull_rule.location_src_id
elif pull_rule.procure_method == "make_to_order":
current_location = pull_rule.location_src_id
rule_values.update(
{
"warehouse_id": pull_rule.location_src_id.get_warehouse(),
}
)
continue
current_location = rule.location_src_id

def action_dummy(self):
Expand Down
9 changes: 9 additions & 0 deletions ddmrp/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,23 @@ def setUpClass(cls):
cls.partner_model = cls.env["res.partner"]
cls.supinfo_model = cls.env["product.supplierinfo"]
cls.pol_model = cls.env["purchase.order.line"]
cls.wh_model = cls.env["stock.warehouse"]

# Refs
cls.main_company = cls.env.ref("base.main_company")
cls.warehouse = cls.env.ref("stock.warehouse0")
cls.warehouse2 = cls.wh_model.create(
{
"partner_id": cls.env.ref("base.main_partner").id,
"name": "Warehouse 2",
"code": "WH2",
}
)
cls.stock_location = cls.env.ref("stock.stock_location_stock")
cls.location_shelf1 = cls.env.ref("stock.stock_location_components")
cls.supplier_location = cls.env.ref("stock.stock_location_suppliers")
cls.customer_location = cls.env.ref("stock.stock_location_customers")
cls.inter_wh = cls.env.ref("stock.stock_location_inter_wh")
cls.inventory_location = cls.env["stock.location"].search(
[("usage", "=", "inventory"), ("company_id", "=", cls.main_company.id)],
limit=1,
Expand Down
54 changes: 54 additions & 0 deletions ddmrp/tests/test_ddmrp.py
Original file line number Diff line number Diff line change
Expand Up @@ -998,3 +998,57 @@ def test_43_get_product_sellers(self):
seller2.date_end = today
seller.date_end = seller3.date_end = yesterday
self.assertEqual(self.buffer_purchase._get_product_sellers(), seller2)

def test_44_resupply_from_another_warehouse(self):
route = self.env["stock.location.route"].create(
{
"name": "Warehouse 2: Supply from Warehouse",
"product_categ_selectable": True,
"product_selectable": True,
"warehouse_selectable": True,
"rule_ids": [
(
0,
0,
{
"name": "Warehouse: Stock → Inter-warehouse transit",
"action": "pull",
"picking_type_id": self.ref("stock.picking_type_internal"),
"location_src_id": self.warehouse.lot_stock_id.id,
"location_id": self.inter_wh.id,
"procure_method": "make_to_stock",
},
),
(
0,
0,
{
"name": "Warehouse2: Inter-warehouse transit → Stock",
"action": "pull",
"picking_type_id": self.ref("stock.picking_type_internal"),
"location_src_id": self.inter_wh.id,
"location_id": self.warehouse2.lot_stock_id.id,
"procure_method": "make_to_order",
},
),
],
}
)
self.product_purchased.route_ids |= route
buffer_distributed = self.bufferModel.create(
{
"buffer_profile_id": self.buffer_profile_distr.id,
"product_id": self.product_purchased.id,
"location_id": self.warehouse2.lot_stock_id.id,
"warehouse_id": self.warehouse2.id,
"qty_multiple": 1.0,
"adu_calculation_method": self.adu_fixed.id,
"adu_fixed": 4.0,
"lead_days": 10.0,
"order_spike_horizon": 10.0,
}
)
self.assertEqual(
buffer_distributed.distributed_source_location_id,
self.warehouse.lot_stock_id,
)