From d697ebd8234ff0ea8ad7334ffc10032d4d50edac Mon Sep 17 00:00:00 2001 From: Marie Lejeune Date: Thu, 4 Dec 2025 11:46:23 +0100 Subject: [PATCH] [IMP] contract_brand: Add unit test for the following case: Ensure analytic distribution models applied on products & brands are combined --- contract_brand/tests/test_contract.py | 38 +++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/contract_brand/tests/test_contract.py b/contract_brand/tests/test_contract.py index edd75439e..69e7cf9f9 100644 --- a/contract_brand/tests/test_contract.py +++ b/contract_brand/tests/test_contract.py @@ -18,6 +18,15 @@ def setUpClass(cls): "plan_id": cls.analytic_plan.id, } ) + cls.analytic_plan2 = cls.env["account.analytic.plan"].create( + {"name": "analytic plan 2"} + ) + cls.analytic_account2 = cls.env["account.analytic.account"].create( + { + "name": "analytic account 2", + "plan_id": cls.analytic_plan2.id, + } + ) def test_contract_create_branded_move(self): """It should create a branded move based on the contract brand""" @@ -39,3 +48,32 @@ def test_contract_analytic_account_onchange_brand(self): self.contract.brand_id = self.brand_id for line in self.contract.contract_line_ids: self.assertEqual(line.analytic_distribution, analytic_distribution) + + def test_contract_analytic_distribution_combined(self): + """ + Analytic distribution model for the product + analytic on the brand + -> Combine both + """ + contract_line = self.contract.contract_line_ids[0] + product = contract_line.product_id + self.env["account.analytic.distribution.model"].create( + { + "product_id": product.id, + "analytic_distribution": {str(self.analytic_account.id): 100}, + } + ) + contract_line._compute_analytic_distribution() + self.assertEqual( + contract_line.analytic_distribution, {str(self.analytic_account.id): 100} + ) + self.env["account.analytic.distribution.model"].create( + { + "brand_id": self.brand_id.id, + "analytic_distribution": {str(self.analytic_account2.id): 100}, + } + ) + self.contract.brand_id = self.brand_id + self.assertEqual( + contract_line.analytic_distribution, + {str(self.analytic_account.id): 100, str(self.analytic_account2.id): 100}, + )