Skip to content

Commit

Permalink
[FIX] sale_order_line_input: New id for the _get_lang method
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pilarvargas-tecnativa committed Sep 26, 2024
1 parent f559bb0 commit 5bdc440
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions sale_order_line_input/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions sale_order_line_input/tests/test_sale_order_line_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 5bdc440

Please sign in to comment.