Skip to content

Commit

Permalink
[FIX] sale_order_type: Empty analytic account when sale order is dupl…
Browse files Browse the repository at this point in the history
…icated.
  • Loading branch information
sergio-teruel committed Sep 13, 2024
1 parent 5fcfa07 commit 024440e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
7 changes: 7 additions & 0 deletions sale_order_type/models/sale.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ def _prepare_invoice(self):
res["sale_type_id"] = self.type_id.id
return res

def copy_data(self, default=None):
vals_list = super().copy_data(default)
if self.type_id.analytic_account_id:
for vals in vals_list:
vals["analytic_account_id"] = self.type_id.analytic_account_id.id
return vals_list


class SaleOrderLine(models.Model):
_inherit = "sale.order.line"
Expand Down
21 changes: 21 additions & 0 deletions sale_order_type/tests/test_sale_order_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ def setUp(self):
self.immediate_payment = self.env.ref("account.account_payment_term_immediate")
self.sale_pricelist = self.env.ref("product.list0")
self.free_carrier = self.env.ref("account.incoterm_FCA")
self.analytic_account = self.env["account.analytic.account"].create(
{
"name": "Test AA",
"code": "TESTSALE_REINVOICE",
"company_id": self.partner_child_1.company_id.id,
"partner_id": self.partner_child_1.id,
}
)
self.sale_type = self.sale_type_model.create(
{
"name": "Test Sale Order Type",
Expand All @@ -68,6 +76,7 @@ def setUp(self):
"pricelist_id": self.sale_pricelist.id,
"incoterm_id": self.free_carrier.id,
"quotation_validity_days": 10,
"analytic_account_id": self.analytic_account.id,
}
)
self.sale_type_quot = self.sale_type_model.create(
Expand Down Expand Up @@ -265,3 +274,15 @@ def test_sequence_default(self):
name = order.name
order.type_id = self.sale_type_sequence_default
self.assertEqual(name, order.name, "The sequence shouldn't change!")

def test_sale_copy_function(self):
"""
Test when duplicating the sale order the account analytic account is set.
"""
order = self.create_sale_order()
order.onchange_partner_id()
order.onchange_type_id()
new_order = order.copy()
self.assertEqual(
new_order.analytic_account_id.id, order.type_id.analytic_account_id.id
)

0 comments on commit 024440e

Please sign in to comment.