customize onchange method for show projects in timesheet

This commit is contained in:
pawan.sharma 2022-10-07 18:18:21 +05:30
parent a867e52859
commit 342041ab85
1 changed files with 19 additions and 12 deletions

View File

@ -27,8 +27,9 @@ class AccountAnalyticLine(models.Model):
def _domain_project_id(self):
today = fields.Date.today()
#domain = [('allow_timesheets', '=', True), ('is_sub_project', '=', False)]
domain = [('allow_timesheets', '=', True), ('is_sub_project', '=', False),('date', '>=', today),('date_start', '<=', today)]
# domain = [('allow_timesheets', '=', True), ('is_sub_project', '=', False)]
domain = [('allow_timesheets', '=', True), ('is_sub_project', '=', False), ('date', '>=', today),
('date_start', '<=', today)]
if not self.user_has_groups('hr_timesheet.group_timesheet_manager'):
return expression.AND([domain,
['|', ('privacy_visibility', '!=', 'followers'),
@ -42,7 +43,6 @@ class AccountAnalyticLine(models.Model):
result['employee_id'] = self.env['hr.employee'].search([('user_id', '=', self.env.user.id)], limit=1).id
return result
project_id = fields.Many2one('project.project', 'Project', compute='_compute_project_id', store=True,
readonly=False,
domain=_domain_project_id)
@ -57,7 +57,7 @@ class AccountAnalyticLine(models.Model):
string='Sub Project')
active_project = fields.Boolean(related='project_id.active', store=True)
pricing_type = fields.Selection(related='project_id.pricing_type', store=True)
project_type= fields.Selection(related='project_id.project_type', store=True)
project_type = fields.Selection(related='project_id.project_type', store=True)
@api.onchange('project_id')
def _onchange_sub_project_id(self):
@ -84,26 +84,34 @@ class AccountAnalyticLine(models.Model):
if self.employee_id and self.employee_id.user_id and self.employee_id.user_id.id in project_manager_grp:
all_projects = self.env['project.project'].search([('allow_timesheets', '=', True),
('is_sub_project', '=', False),
('date', '>=', today),('date_start', '<=', today)]).ids
('date', '>=', today), ('date_start', '<=', today)]).ids
domain = [('id', 'in', all_projects)]
else:
if self.employee_id and self.employee_id.user_id and self.employee_id.user_id.id in project_user_grp:
manager_id = self.env['project.project'].search(
[('user_id', '=', self.employee_id.user_id.id), ('allow_timesheets', '=', True),
('date', '>=', today),('date_start', '<=', today),
('is_sub_project', '=', False)]).ids
('is_sub_project', '=', False),('pricing_type', '=', 'fixed_rate')]).ids
emp_project_ids = self.env['project.project'].search(
[('privacy_visibility', 'in', ('employees', 'portal')), ('allow_timesheets', '=', True),
('date', '>=', today),('date_start', '<=', today),
('is_sub_project', '=', False)]).ids
('is_sub_project', '=', False),('pricing_type', '=', 'fixed_rate')]).ids
project_ids = self.env['project.project'].search(
[('privacy_visibility', '=', 'followers'), ('allow_timesheets', '=', True),
('date', '>=', today),('date_start', '<=', today),
('is_sub_project', '=', False),
('allowed_internal_user_ids', 'in', self.employee_id.user_id.id)]).ids
consul_ids = self.env['project.sale.line.employee.map'].search([('employee_id', '=', self.employee_id.id)])
# consul_project_ids = [val.project_id.id for val in consul_ids]
consul_project_ids = [val.project_id.id for val in consul_ids if val.project_id.is_sub_project == False]
('allowed_internal_user_ids', 'in', self.employee_id.user_id.id),('pricing_type', '=', 'fixed_rate')]).ids
consul_ids = self.env['project.sale.line.employee.map'].search(
[('employee_id', '=', self.employee_id.id)])
consul_project_ids = []
for rec in consul_ids:
if rec.project_id.pricing_type != 'fixed_rate' and rec.project_id.allow_timesheets == True and rec.project_id.is_sub_project == False:
if rec.start_date and rec.end_date:
if rec.start_date <= today <= rec.end_date:
consul_project_ids.append(rec.project_id.id)
elif rec.start_date:
if rec.start_date <= today:
consul_project_ids.append(rec.project_id.id)
emp_all_project_ids = manager_id + emp_project_ids + project_ids + consul_project_ids
domain = [('id', 'in', list(set(emp_all_project_ids)))]
result = {
@ -186,7 +194,6 @@ class AccountAnalyticLine(models.Model):
raise ValidationError(_("End time cannot be earlier than Start time"))
self.unit_amount = res"""
# @api.onchange('start_time', 'end_time')
# def _onchange_start_end_time(self):
# if self.start_time > 0: