[IMP] mrp, stock: default route on orderpoints

Set a default route on orderpoint created by the replenishment report.
First it select the first route on the product if it exists (it's
uselss since it's a preferred route on the report but it's used for
clarity). If the product has no route then it tries to guess it
with vendor pricelist or BoM on the product.

Task: 2161378
This commit is contained in:
Arnold Moyaux
2020-04-22 07:58:04 +00:00
parent 943da6df0f
commit fc692354b6
4 changed files with 37 additions and 1 deletions
+1
View File
@@ -14,6 +14,7 @@ from . import mrp_workorder
from . import product
from . import res_company
from . import stock_move
from . import stock_orderpoint
from . import stock_picking
from . import stock_production_lot
from . import stock_rule
+9
View File
@@ -24,3 +24,12 @@ class StockWarehouseOrderpoint(models.Model):
}
}
return super()._get_replenishment_order_notification()
def _set_default_route_id(self):
route_id = self.env['stock.rule'].search([
('action', '=', 'manufacture')
]).route_id
orderpoint_wh_bom = self.filtered(lambda o: o.product_id.bom_ids)
if route_id and orderpoint_wh_bom:
orderpoint_wh_bom.route_id = route_id[0].id
return super()._set_default_route_id()
+9
View File
@@ -206,6 +206,15 @@ class Orderpoint(models.Model):
res[orderpoint.id] += product_uom_qty
return res
def _set_default_route_id(self):
route_id = self.env['stock.rule'].search([
('action', '=', 'buy')
]).route_id
orderpoint_wh_supplier = self.filtered(lambda o: o.product_id.seller_ids)
if route_id and orderpoint_wh_supplier:
orderpoint_wh_supplier.route_id = route_id[0].id
return super()._set_default_route_id()
class ProductionLot(models.Model):
_inherit = 'stock.production.lot'
+18 -1
View File
@@ -236,6 +236,22 @@ class StockWarehouseOrderpoint(models.Model):
qty_to_order += orderpoint.qty_multiple - remainder
orderpoint.qty_to_order = qty_to_order
def _set_default_route_id(self):
""" Write the `route_id` field on `self`. This method is intendend to be called on the
orderpoints generated when openning the replenish report.
"""
self = self.filtered(lambda o: not o.route_id)
rules_groups = self.env['stock.rule'].read_group([
('route_id.product_selectable', '!=', False),
('location_id', 'in', self.location_id.ids),
('action', 'in', ['pull_push', 'pull'])
], ['location_id', 'route_id'], ['location_id', 'route_id'], lazy=False)
for g in rules_groups:
if not g.get('route_id'):
continue
orderpoints = self.filtered(lambda o: o.location_id == g['location_id'])
orderpoints.route_id = g['route_id']
def _get_product_context(self):
"""Used to call `virtual_available` when running an orderpoint."""
self.ensure_one()
@@ -319,7 +335,8 @@ class StockWarehouseOrderpoint(models.Model):
orderpoints = self.env['stock.warehouse.orderpoint'].with_user(SUPERUSER_ID).create(orderpoint_values_list)
for orderpoint in orderpoints:
orderpoint.route_id = orderpoint._get_default_route_id()
orderpoint.route_id = orderpoint.product_id.route_ids[:1]
orderpoints.filtered(lambda o: not o.route_id)._set_default_route_id()
return action
@api.model