[FIX] hr_timesheet: create project with allow_timesheet checked by default

The default value when creating a project is true for 'allow_timesheet'
field. This will automatically create an Analytic Account (if not
provided). However, the old onchange reset the allow_timesheet to false
if no AA was given, which is a contraction with the expected behavior
on project creation. But, we might want to uncheck 'allow_timesheet'
when we remove the AA on an existing project (Users can not log
timesheets without an active analytic account).
This commit fixes the erasing default value on creation by checking
the record is currently existing in the database.

Task #1886691
This commit is contained in:
jem-odoo
2018-09-19 11:35:06 +02:00
parent 8e875f58cf
commit a2456b20e9
+1 -1
View File
@@ -22,7 +22,7 @@ class Project(models.Model):
@api.onchange('analytic_account_id')
def _onchange_analytic_account(self):
if not self.analytic_account_id:
if not self.analytic_account_id and self._origin:
self.allow_timesheets = False
@api.constrains('allow_timesheets', 'analytic_account_id')