diff --git a/addons/mrp_subcontracting_purchase/tests/test_mrp_subcontracting_purchase.py b/addons/mrp_subcontracting_purchase/tests/test_mrp_subcontracting_purchase.py index fe36bb7f15b..592107d31e4 100644 --- a/addons/mrp_subcontracting_purchase/tests/test_mrp_subcontracting_purchase.py +++ b/addons/mrp_subcontracting_purchase/tests/test_mrp_subcontracting_purchase.py @@ -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)])) diff --git a/addons/stock/models/stock_orderpoint.py b/addons/stock/models/stock_orderpoint.py index 6f2f5632c0e..6ea867efccf 100644 --- a/addons/stock/models/stock_orderpoint.py +++ b/addons/stock/models/stock_orderpoint.py @@ -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)