mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
Improve code after reviews
* performance (less queries executed) * disable tracking in tests (faster) * use with_user instead of sudo * the double for loop in _compute_route_ids actually generates one more query as the simple one in this commit (thanks to the cache) * extract a method * the parent locations can be found using 'parent_of' which will use the parent_path under the hood (example: 1/7/8 will return locations 1, 7, 8) [UPD] Update stock_orderpoint_route.pot
This commit is contained in:
committed by
Dũng (Trần Đình)
parent
2d09392b16
commit
a53fd653c3
29
stock_orderpoint_route/i18n/stock_orderpoint_route.pot
Normal file
29
stock_orderpoint_route/i18n/stock_orderpoint_route.pot
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
# Translation of Odoo Server.
|
||||||
|
# This file contains the translation of the following modules:
|
||||||
|
# * stock_orderpoint_route
|
||||||
|
#
|
||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: Odoo Server 13.0\n"
|
||||||
|
"Report-Msgid-Bugs-To: \n"
|
||||||
|
"Last-Translator: \n"
|
||||||
|
"Language-Team: \n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: \n"
|
||||||
|
"Plural-Forms: \n"
|
||||||
|
|
||||||
|
#. module: stock_orderpoint_route
|
||||||
|
#: model:ir.model.fields,field_description:stock_orderpoint_route.field_stock_warehouse_orderpoint__route_ids
|
||||||
|
msgid "Allowed routes"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#. module: stock_orderpoint_route
|
||||||
|
#: model:ir.model,name:stock_orderpoint_route.model_stock_warehouse_orderpoint
|
||||||
|
msgid "Minimum Inventory Rule"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#. module: stock_orderpoint_route
|
||||||
|
#: model:ir.model.fields,field_description:stock_orderpoint_route.field_stock_warehouse_orderpoint__route_id
|
||||||
|
msgid "Route"
|
||||||
|
msgstr ""
|
||||||
@@ -20,33 +20,32 @@ class StockWarehouseOrderpoint(models.Model):
|
|||||||
@api.depends("product_id", "warehouse_id", "warehouse_id.route_ids", "location_id")
|
@api.depends("product_id", "warehouse_id", "warehouse_id.route_ids", "location_id")
|
||||||
def _compute_route_ids(self):
|
def _compute_route_ids(self):
|
||||||
route_obj = self.env["stock.location.route"]
|
route_obj = self.env["stock.location.route"]
|
||||||
for wh in self.mapped("warehouse_id"):
|
for record in self:
|
||||||
wh_routes = wh.route_ids
|
wh_routes = record.warehouse_id.route_ids
|
||||||
for record in self.filtered(lambda r: r.warehouse_id == wh):
|
routes = route_obj.browse()
|
||||||
routes = route_obj.browse()
|
if record.product_id:
|
||||||
if record.product_id:
|
routes += record.product_id.mapped(
|
||||||
routes += record.product_id.mapped(
|
"route_ids"
|
||||||
"route_ids"
|
) | record.product_id.mapped("categ_id").mapped("total_route_ids")
|
||||||
) | record.product_id.mapped("categ_id").mapped("total_route_ids")
|
if record.warehouse_id:
|
||||||
if record.warehouse_id:
|
routes |= wh_routes
|
||||||
routes |= wh_routes
|
parents = record.get_parents()
|
||||||
parents = record.get_parents()
|
record.route_ids = self._get_location_routes_of_parents(routes, parents)
|
||||||
record.route_ids = routes.filtered(
|
|
||||||
lambda route: any(
|
def _get_location_routes_of_parents(self, routes, parents):
|
||||||
p.location_id in parents
|
return routes.filtered(
|
||||||
for p in route.rule_ids.filtered(
|
lambda route: any(
|
||||||
lambda rule: rule.action in ("pull", "pull_push")
|
p.location_id in parents
|
||||||
).mapped("location_src_id")
|
for p in route.rule_ids.filtered(
|
||||||
)
|
lambda rule: rule.action in ("pull", "pull_push")
|
||||||
)
|
).mapped("location_src_id")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
def get_parents(self):
|
def get_parents(self):
|
||||||
location = self.location_id
|
return self.env["stock.location"].search(
|
||||||
result = location
|
[("id", "parent_of", self.location_id.id)]
|
||||||
while location.location_id:
|
)
|
||||||
location = location.location_id
|
|
||||||
result |= location
|
|
||||||
return result
|
|
||||||
|
|
||||||
def _prepare_procurement_values(self, product_qty, date=False, group=False):
|
def _prepare_procurement_values(self, product_qty, date=False, group=False):
|
||||||
res = super()._prepare_procurement_values(product_qty, date=date, group=group)
|
res = super()._prepare_procurement_values(product_qty, date=date, group=group)
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ class TestStockOrderpointRoute(common.SavepointCase):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
super().setUpClass()
|
super().setUpClass()
|
||||||
|
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
|
||||||
|
|
||||||
# common models
|
# common models
|
||||||
cls.orderpoint_model = cls.env["stock.warehouse.orderpoint"]
|
cls.orderpoint_model = cls.env["stock.warehouse.orderpoint"]
|
||||||
@@ -99,7 +100,7 @@ class TestStockOrderpointRoute(common.SavepointCase):
|
|||||||
def _create_user(cls, name, group_ids, company_ids):
|
def _create_user(cls, name, group_ids, company_ids):
|
||||||
return (
|
return (
|
||||||
cls.env["res.users"]
|
cls.env["res.users"]
|
||||||
.with_context({"no_reset_password": True})
|
.with_context(no_reset_password=True)
|
||||||
.create(
|
.create(
|
||||||
{
|
{
|
||||||
"name": name,
|
"name": name,
|
||||||
@@ -136,7 +137,7 @@ class TestStockOrderpointRoute(common.SavepointCase):
|
|||||||
"location_id": self.warehouse.lot_stock_id.id,
|
"location_id": self.warehouse.lot_stock_id.id,
|
||||||
}
|
}
|
||||||
|
|
||||||
orderpoint = self.orderpoint_model.sudo(self.stock_manager).create(vals)
|
orderpoint = self.orderpoint_model.with_user(self.stock_manager).create(vals)
|
||||||
self.assertIn(self.route, orderpoint.route_ids)
|
self.assertIn(self.route, orderpoint.route_ids)
|
||||||
self.assertIn(self.route2, orderpoint.route_ids)
|
self.assertIn(self.route2, orderpoint.route_ids)
|
||||||
orderpoint.route_id = self.route.id
|
orderpoint.route_id = self.route.id
|
||||||
@@ -161,7 +162,7 @@ class TestStockOrderpointRoute(common.SavepointCase):
|
|||||||
"location_id": self.warehouse.lot_stock_id.id,
|
"location_id": self.warehouse.lot_stock_id.id,
|
||||||
}
|
}
|
||||||
|
|
||||||
orderpoint = self.orderpoint_model.sudo(self.stock_manager).create(vals)
|
orderpoint = self.orderpoint_model.with_user(self.stock_manager).create(vals)
|
||||||
self.assertIn(self.route, orderpoint.route_ids)
|
self.assertIn(self.route, orderpoint.route_ids)
|
||||||
self.assertIn(self.route2, orderpoint.route_ids)
|
self.assertIn(self.route2, orderpoint.route_ids)
|
||||||
orderpoint.route_id = self.route2.id
|
orderpoint.route_id = self.route2.id
|
||||||
|
|||||||
Reference in New Issue
Block a user