[FIX] stock: support no rules for the product
Currently traceback appears if no rules are available on the product. (Steps to reproduce: install sale and stock, but not purchase, go to the product and click "Replenish") Index is out of range because route_ids is an empty list. This fix will allow route_ids to be empty. opw-3637054 closes odoo/odoo#146250 Signed-off-by: William Henrotin (whe) <whe@odoo.com>
This commit is contained in:
@@ -66,3 +66,12 @@ class TestStockReplenish(TestStockCommon):
|
||||
self.assertEqual(fields.Datetime.from_string('2023-01-01 00:00:00'), wizard._values['date_planned'])
|
||||
wizard.route_id = route_delay
|
||||
self.assertEqual(fields.Datetime.from_string('2023-01-07 00:00:00'), wizard._values['date_planned'])
|
||||
|
||||
def test_replenish_no_routes(self):
|
||||
product = self.env['product.template'].create({
|
||||
'name': 'Brand new product',
|
||||
'type': 'product',
|
||||
})
|
||||
self.assertEqual(len(product.route_ids), 0)
|
||||
wizard = Form(self.env['product.replenish'].with_context(default_product_tmpl_id=product.id))
|
||||
self.assertEqual(wizard._values['quantity'], 1)
|
||||
|
||||
@@ -85,7 +85,8 @@ class ProductReplenish(models.TransientModel):
|
||||
if 'route_id' in fields and 'route_id' not in res and product_tmpl_id:
|
||||
res['route_id'] = self.env['stock.route'].search(self._get_route_domain(product_tmpl_id), limit=1).id
|
||||
if not res['route_id']:
|
||||
res['route_id'] = product_tmpl_id.route_ids.filtered(lambda r: r.company_id == self.env.company or not r.company_id)[0].id
|
||||
if product_tmpl_id.route_ids:
|
||||
res['route_id'] = product_tmpl_id.route_ids.filtered(lambda r: r.company_id == self.env.company or not r.company_id)[0].id
|
||||
return res
|
||||
|
||||
def _get_date_planned(self, route_id, **kwargs):
|
||||
|
||||
Reference in New Issue
Block a user