Skip to content

Commit

Permalink
Merge PR OCA#3326 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by pedrobaeza
  • Loading branch information
OCA-git-bot committed Sep 26, 2024
2 parents f559bb0 + 5bdc440 commit c32ae31
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 c32ae31

Please sign in to comment.