diff --git a/addons/purchase_stock/i18n/purchase_stock.pot b/addons/purchase_stock/i18n/purchase_stock.pot index 9dfa2a2a7fe..d2fb4ea04ea 100644 --- a/addons/purchase_stock/i18n/purchase_stock.pot +++ b/addons/purchase_stock/i18n/purchase_stock.pot @@ -228,6 +228,15 @@ msgstr "" msgid "Exception(s):" msgstr "" +#. module: purchase_stock +#: code:addons/purchase_stock/models/purchase.py:0 +#, python-format +msgid "" +"For the product %s, the warehouse of the operation type (%s) is inconsistent" +" with the location (%s) of the reordering rule (%s). Change the operation " +"type or cancel the request for quotation." +msgstr "" + #. module: purchase_stock #: model:ir.model.fields,field_description:purchase_stock.field_purchase_order_line__forecasted_issue msgid "Forecasted Issue" diff --git a/addons/purchase_stock/models/purchase.py b/addons/purchase_stock/models/purchase.py index 15aa91778ae..23737273c4a 100644 --- a/addons/purchase_stock/models/purchase.py +++ b/addons/purchase_stock/models/purchase.py @@ -274,7 +274,7 @@ class PurchaseOrderLine(models.Model): qty_received_method = fields.Selection(selection_add=[('stock_moves', 'Stock Moves')]) move_ids = fields.One2many('stock.move', 'purchase_line_id', string='Reservation', readonly=True, copy=False) - orderpoint_id = fields.Many2one('stock.warehouse.orderpoint', 'Orderpoint') + orderpoint_id = fields.Many2one('stock.warehouse.orderpoint', 'Orderpoint', copy=False) move_dest_ids = fields.One2many('stock.move', 'created_purchase_line_id', 'Downstream Moves') product_description_variants = fields.Char('Custom Description') propagate_cancel = fields.Boolean('Propagate cancellation', default=True) @@ -468,8 +468,15 @@ class PurchaseOrderLine(models.Model): res.append(extra_move_vals) return res + def _check_orderpoint_picking_type(self): + warehouse_loc = self.order_id.picking_type_id.warehouse_id.view_location_id + if self.orderpoint_id and not warehouse_loc.parent_path in self.orderpoint_id.location_id.parent_path: + raise UserError(_('For the product %s, the warehouse of the operation type (%s) is inconsistent with the location (%s) of the reordering rule (%s). Change the operation type or cancel the request for quotation.', + self.product_id.display_name, self.order_id.picking_type_id.display_name, self.orderpoint_id.location_id.display_name, self.orderpoint_id.display_name)) + def _prepare_stock_move_vals(self, picking, price_unit, product_uom_qty, product_uom): self.ensure_one() + self._check_orderpoint_picking_type() product = self.product_id.with_context(lang=self.order_id.dest_address_id.lang or self.env.user.lang) date_planned = self.date_planned or self.order_id.date_planned return { diff --git a/addons/purchase_stock/tests/test_reordering_rule.py b/addons/purchase_stock/tests/test_reordering_rule.py index b5f7d40bb4b..e7c404f51db 100644 --- a/addons/purchase_stock/tests/test_reordering_rule.py +++ b/addons/purchase_stock/tests/test_reordering_rule.py @@ -7,6 +7,7 @@ from datetime import timedelta as td from odoo import SUPERUSER_ID from odoo.tests import Form from odoo.tests.common import TransactionCase +from odoo.exceptions import UserError class TestReorderingRule(TransactionCase): @@ -38,6 +39,7 @@ class TestReorderingRule(TransactionCase): """ warehouse_1 = self.env['stock.warehouse'].search([('company_id', '=', self.env.user.id)], limit=1) warehouse_1.write({'reception_steps': 'two_steps'}) + warehouse_2 = self.env['stock.warehouse'].create({'name': 'WH 2', 'code': 'WH2', 'company_id': self.env.company.id, 'partner_id': self.env.company.partner_id.id, 'reception_steps': 'one_step'}) # create reordering rule orderpoint_form = Form(self.env['stock.warehouse.orderpoint']) @@ -64,6 +66,12 @@ class TestReorderingRule(TransactionCase): purchase_order = self.env['purchase.order'].search([('partner_id', '=', self.partner.id)]) self.assertTrue(purchase_order, 'No purchase order created.') + # Check the picking type on the purchase order + purchase_order.picking_type_id = warehouse_2.in_type_id + with self.assertRaises(UserError): + purchase_order.button_confirm() + purchase_order.picking_type_id = warehouse_1.in_type_id + # On the po generated, the source document should be the name of the reordering rule self.assertEqual(order_point.name, purchase_order.origin, 'Source document on purchase order should be the name of the reordering rule.') self.assertEqual(purchase_order.order_line.product_qty, 10)