[IMP] hr_timesheet: set favorite project in timesheet

If the last five timesheets belong to the same project then that project is considered a
favorite project.
Currently, this feature is only in the timesheet's grid. Now done in all view.

task-2861376

Part-of: odoo/odoo#94144
This commit is contained in:
Kartik Chavda
2022-08-04 18:35:11 +02:00
committed by Prakash Prajapati
parent 29bf004bc1
commit ad1b64ab02
@@ -12,6 +12,13 @@ from odoo.osv import expression
class AccountAnalyticLine(models.Model):
_inherit = 'account.analytic.line'
@api.model
def _get_favorite_project_id(self):
last_timesheet_ids = self.search([('user_id', '=', self._uid), ('project_id', '!=', False)], limit=5)
if len(last_timesheet_ids) == 5 and len(last_timesheet_ids.project_id) == 1:
return last_timesheet_ids.project_id.id
return False
@api.model
def default_get(self, field_list):
result = super(AccountAnalyticLine, self).default_get(field_list)
@@ -19,6 +26,10 @@ class AccountAnalyticLine(models.Model):
result['encoding_uom_id'] = self.env.company.timesheet_encode_uom_id.id
if not self.env.context.get('default_employee_id') and 'employee_id' in field_list and result.get('user_id'):
result['employee_id'] = self.env['hr.employee'].search([('user_id', '=', result['user_id']), ('company_id', '=', result.get('company_id', self.env.company.id))], limit=1).id
if not self._context.get('default_project_id') and 'project_id' in field_list:
favorite_project_id = self._get_favorite_project_id()
if favorite_project_id:
result['project_id'] = favorite_project_id
return result
def _domain_project_id(self):