diff --git a/sale_order_line_input/models/sale_order.py b/sale_order_line_input/models/sale_order.py index 49ee0c2253b..1359bb1681c 100644 --- a/sale_order_line_input/models/sale_order.py +++ b/sale_order_line_input/models/sale_order.py @@ -24,6 +24,15 @@ def _compute_force_company_id(self): for line in self: line.force_company_id = line.order_id.company_id or self.env.company + def _compute_name(self): + # A NewId is needed to set the product for the parent method to set + # the language correctly. Empty id leads to error in ‘_get_lang’. + for line in self: + if not line.order_id and line.product_id: + SaleOrder = self.env["sale.order"] + line.order_id = SaleOrder.new({}) + return super()._compute_name() + @api.onchange("force_company_id") def _onchange_force_company_id(self): """Assign company_id because is used in domains as partner, diff --git a/sale_order_line_input/tests/test_sale_order_line_input.py b/sale_order_line_input/tests/test_sale_order_line_input.py index 9626c1da9d5..ac3cc2317bc 100644 --- a/sale_order_line_input/tests/test_sale_order_line_input.py +++ b/sale_order_line_input/tests/test_sale_order_line_input.py @@ -29,3 +29,12 @@ def test_sale_order_create_and_show(self): action_dict = line.action_sale_order_form() self.assertEqual(action_dict["res_id"], line.order_id.id) self.assertEqual(action_dict["res_model"], "sale.order") + + def test_sale_order_line_compute_name(self): + # Ensure that when calculating the line name, the new sales order id has + # already been created as it is done in the order form view. + line_form = Form( + self.env["sale.order.line"], + view="sale_order_line_input.view_sales_order_line_input_tree", + ) + line_form.product_id = self.product