Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15.0][FIX] sale_order_type: Empty analytic account when sale order is duplicated #3312

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
)
Loading