Skip to content

Commit c32ae31

Browse files
committed
Merge PR #3326 into 16.0
Signed-off-by pedrobaeza
2 parents f559bb0 + 5bdc440 commit c32ae31

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)