[FIX] stock: set location as replenishment posible without warehouse

Steps to reproduce:

- Install purchase, inventory and manufacturing.
- Now create a subcontractor, with it's corresponding location, it's set
by default.
- Go to this new location and set it as replenishment location.
- Now create a Request for Quotation using this subcontractor.
- We will receive a traceback whent trying to access replenishment.

Issue:

We got a traceback caused by the fact that we are trying to set
as replenishment location, a location that doesn't have a warehouse.

Solution:

We need to add the handling of this case, so we won't always need
a warehouse for the orderpoint.

opw-3164276

closes odoo/odoo#121065

X-original-commit: 874e42463c2077980b9b4ce3903030c980285d51
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
This commit is contained in:
Maruan Aguerdouh (magm)
2023-05-11 18:25:26 +02:00
parent 77daee9178
commit c50ae28374
2 changed files with 53 additions and 3 deletions
@@ -184,3 +184,53 @@ class MrpSubcontractingPurchaseTest(TestMrpSubcontractingCommon):
self.assertEqual(self.finished2.qty_available, 7.0)
self.assertEqual(po.order_line.qty_received, 10.0)
def test_orderpoint_warehouse_not_required(self):
"""
The user creates a subcontracted bom for the product,
then we create a po for the subcontracted bom we are gonna get
orderpoints for the components without warehouse.Notice this is
when our subcontracting location is also a replenish location.
The test ensure that we can get those orderpoints without warehouse.
"""
product = self.env['product.product'].create({
'name': 'Product',
'detailed_type': 'product',
})
component = self.env['product.product'].create({
'name': 'Component',
'detailed_type': 'product',
})
subcontractor = self.env['res.partner'].create({
'name': 'Subcontractor',
'property_stock_subcontractor': self.env.company.subcontracting_location_id.id,
})
self.env.company.subcontracting_location_id.replenish_location = True
self.env['mrp.bom'].create({
'product_tmpl_id': product.product_tmpl_id.id,
'product_qty': 1,
'product_uom_id': product.uom_id.id,
'type': 'subcontract',
'subcontractor_ids': [(subcontractor.id)],
'bom_line_ids': [(0, 0, {
'product_id': component.id,
'product_qty': 1,
'product_uom_id': component.uom_id.id,
})],
})
po = self.env['purchase.order'].create({
'partner_id': subcontractor.id,
'order_line': [(0, 0, {
'product_id': product.id,
'product_qty': 1,
'product_uom': product.uom_id.id,
'name': product.name,
'price_unit': 1,
})],
})
po.button_confirm()
self.env['stock.warehouse.orderpoint']._get_orderpoint_action()
self.assertTrue(self.env['stock.warehouse.orderpoint'].search([('product_id', '=', component.id)]))
+3 -3
View File
@@ -416,11 +416,11 @@ class StockWarehouseOrderpoint(models.Model):
orderpoint.qty_forecast += product_qty
else:
orderpoint_values = self.env['stock.warehouse.orderpoint']._get_orderpoint_values(product, location_id)
warehouse_id = self.env['stock.location'].browse(location_id).warehouse_id
location = self.env['stock.location'].browse(location_id)
orderpoint_values.update({
'name': _('Replenishment Report'),
'warehouse_id': warehouse_id.id,
'company_id': warehouse_id.company_id.id,
'warehouse_id': location.warehouse_id.id or self.env['stock.warehouse'].search([('company_id', '=', location.company_id.id)]).id,
'company_id': location.company_id.id,
})
orderpoint_values_list.append(orderpoint_values)