File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed
Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -69,6 +69,26 @@ def _compute_first_recurring_next_date(
6969 max_date_end = False ,
7070 )
7171
72+ def _get_analytic_distribution_arguments (self ):
73+ self .ensure_one ()
74+ partner_categ_ids = self .contract_id .partner_id .category_id .ids
75+ return {
76+ "product_id" : self .product_id .id ,
77+ "product_categ_id" : self .product_id .categ_id .id ,
78+ "partner_id" : self .contract_id .partner_id .id ,
79+ "partner_category_id" : partner_categ_ids ,
80+ "company_id" : self .company_id .id ,
81+ }
82+
83+ @api .depends ("contract_id.partner_id" , "product_id" )
84+ def _compute_analytic_distribution (self ):
85+ for line in self :
86+ if not line .display_type :
87+ distribution = line .env [
88+ "account.analytic.distribution.model"
89+ ]._get_distribution (line ._get_analytic_distribution_arguments ())
90+ line .analytic_distribution = distribution or line .analytic_distribution
91+
7292 @api .constrains ("recurring_next_date" , "date_start" )
7393 def _check_recurring_next_date_start_date (self ):
7494 for line in self :
Original file line number Diff line number Diff line change @@ -1593,3 +1593,20 @@ def test_analytic_account(self):
15931593 # Case 4: two contract lines, each one with one analytic account
15941594 new_contract_line .analytic_distribution = {self .analytic_account_2 .id : 100 }
15951595 self .assertFalse (self .contract .group_id )
1596+
1597+ def test_analytic_distribution (self ):
1598+ # Create an analytic distribution model for product 1
1599+ analytic_plan = self .env ["account.analytic.plan" ].create ({"name" : "Plan" })
1600+ analytic_account = self .env ["account.analytic.account" ].create (
1601+ {"name" : "Test" , "plan_id" : analytic_plan .id }
1602+ )
1603+ self .env ["account.analytic.distribution.model" ].create (
1604+ {
1605+ "product_id" : self .product_1 .id ,
1606+ "analytic_distribution" : {str (analytic_account .id ): 100 },
1607+ }
1608+ )
1609+ new_contract_line = self .env ["contract.line" ].create (self .line_vals )
1610+ self .assertEqual (
1611+ new_contract_line .analytic_distribution , {str (analytic_account .id ): 100 }
1612+ )
You can’t perform that action at this time.
0 commit comments