@@ -100,7 +100,7 @@ def _search_is_project_overtime(self, operator, value):
100
100
@api .constrains ('allow_timesheets' , 'account_id' )
101
101
def _check_allow_timesheet (self ):
102
102
for project in self :
103
- if project .allow_timesheets and not project .account_id :
103
+ if project .allow_timesheets and not project .account_id and not project . is_template :
104
104
project_plan , _other_plans = self .env ['account.analytic.plan' ]._get_all_plans ()
105
105
raise ValidationError (_ (
106
106
"To use the timesheets feature, you need an analytic account for your project. Please set one up in the plan '%(plan_name)s' or turn off the timesheets feature." ,
@@ -135,12 +135,12 @@ def create(self, vals_list):
135
135
""" Create an analytic account if project allow timesheet and don't provide one
136
136
Note: create it before calling super() to avoid raising the ValidationError from _check_allow_timesheet
137
137
"""
138
- defaults = self .default_get (['allow_timesheets' , 'account_id' ])
138
+ defaults = self .default_get (['allow_timesheets' , 'account_id' , 'is_template' ])
139
139
analytic_accounts_vals = [
140
140
vals for vals in vals_list
141
141
if (
142
142
vals .get ('allow_timesheets' , defaults .get ('allow_timesheets' )) and
143
- not vals .get ('account_id' , defaults .get ('account_id' ))
143
+ not vals .get ('account_id' , defaults .get ('account_id' )) and not vals . get ( 'is_template' , defaults . get ( 'is_template' ))
144
144
)
145
145
]
146
146
@@ -153,7 +153,7 @@ def create(self, vals_list):
153
153
def write (self , values ):
154
154
# create the AA for project still allowing timesheet
155
155
if values .get ('allow_timesheets' ) and not values .get ('account_id' ):
156
- project_wo_account = self .filtered (lambda project : not project .account_id )
156
+ project_wo_account = self .filtered (lambda project : not project .account_id and not project . is_template )
157
157
if project_wo_account :
158
158
project_wo_account ._create_analytic_account ()
159
159
return super ().write (values )
@@ -171,7 +171,7 @@ def _compute_display_name(self):
171
171
172
172
@api .model
173
173
def _init_data_analytic_account (self ):
174
- self .search ([('account_id' , '=' , False ), ('allow_timesheets' , '=' , True )])._create_analytic_account ()
174
+ self .search ([('account_id' , '=' , False ), ('allow_timesheets' , '=' , True ), ( 'is_template' , '=' , False ) ])._create_analytic_account ()
175
175
176
176
@api .ondelete (at_uninstall = False )
177
177
def _unlink_except_contains_entries (self ):
@@ -283,3 +283,8 @@ def action_view_tasks(self):
283
283
action = super ().action_view_tasks ()
284
284
action ['context' ]['allow_timesheets' ] = self .allow_timesheets
285
285
return action
286
+
287
+ def action_create_from_template (self , values = None ):
288
+ project = super ().action_create_from_template (values )
289
+ project ._create_analytic_account ()
290
+ return project
0 commit comments