Skip to content

Commit 5bdc440

Browse files
[FIX] sale_order_line_input: New id for the _get_lang method
When a line is defined in the sales order it calculates the name of the description with the language of the order using the new id of the new order being created. If this is done from the order lines view there is no order created and that is why you need to create a new id to avoid the error in the parent method.
1 parent f559bb0 commit 5bdc440

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

sale_order_line_input/models/sale_order.py

+9
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ def _compute_force_company_id(self):
2424
for line in self:
2525
line.force_company_id = line.order_id.company_id or self.env.company
2626

27+
def _compute_name(self):
28+
# A NewId is needed to set the product for the parent method to set
29+
# the language correctly. Empty id leads to error in ‘_get_lang’.
30+
for line in self:
31+
if not line.order_id and line.product_id:
32+
SaleOrder = self.env["sale.order"]
33+
line.order_id = SaleOrder.new({})
34+
return super()._compute_name()
35+
2736
@api.onchange("force_company_id")
2837
def _onchange_force_company_id(self):
2938
"""Assign company_id because is used in domains as partner,

sale_order_line_input/tests/test_sale_order_line_input.py

+9
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,12 @@ def test_sale_order_create_and_show(self):
2929
action_dict = line.action_sale_order_form()
3030
self.assertEqual(action_dict["res_id"], line.order_id.id)
3131
self.assertEqual(action_dict["res_model"], "sale.order")
32+
33+
def test_sale_order_line_compute_name(self):
34+
# Ensure that when calculating the line name, the new sales order id has
35+
# already been created as it is done in the order form view.
36+
line_form = Form(
37+
self.env["sale.order.line"],
38+
view="sale_order_line_input.view_sales_order_line_input_tree",
39+
)
40+
line_form.product_id = self.product

0 commit comments

Comments
 (0)