project and employee forecast domain updated
This commit is contained in:
parent
ec53a365d7
commit
bcddf6cc3c
|
@ -15,6 +15,11 @@ class Project(models.Model):
|
|||
raise UserError(_('You cannot delete a project containing plannings. You can either delete all the project\'s forecasts and then delete the project or simply deactivate the project.'))
|
||||
return super(Project, self).unlink()
|
||||
|
||||
def action_view_project_forecast_action_from_project(self):
|
||||
action = self.env["ir.actions.actions"]._for_xml_id("project_forecast.project_forecast_action_from_project")
|
||||
action['context'] = {'default_project_id': self.id}
|
||||
return action
|
||||
|
||||
|
||||
class Task(models.Model):
|
||||
_inherit = 'project.task'
|
||||
|
|
|
@ -50,7 +50,7 @@ class PlanningShift(models.Model):
|
|||
else:
|
||||
self.task_id.project_id = self.project_id
|
||||
|
||||
@api.onchange('employee_id')
|
||||
"""@api.onchange('employee_id')
|
||||
def _onchange_employee_id(self):
|
||||
domain = []
|
||||
if self.employee_id and not self.employee_id.user_id:
|
||||
|
@ -74,13 +74,30 @@ class PlanningShift(models.Model):
|
|||
result = {
|
||||
'domain': {'project_id': domain},
|
||||
}
|
||||
return result
|
||||
return result"""
|
||||
|
||||
@api.onchange('project_id')
|
||||
def _onchange_project_id(self):
|
||||
domain = [] if not self.project_id else [('project_id', '=', self.project_id.id)]
|
||||
manager_id = []
|
||||
user_ids = []
|
||||
consul_project_ids = []
|
||||
if self.project_id:
|
||||
consul_ids = self.env['project.sale.line.employee.map'].search([('project_id', '=', self.project_id.id)])
|
||||
consul_project_ids = [val.employee_id.id for val in consul_ids]
|
||||
print("consul_project_ids", consul_project_ids)
|
||||
if self.project_id and self.project_id.user_id:
|
||||
manager_id = self.env['hr.employee'].search([('user_id', '=', self.project_id.user_id.id)]).ids
|
||||
print("manager_id", manager_id)
|
||||
if self.project_id and self.project_id.privacy_visibility in ('employees', 'portal'):
|
||||
user_ids = self.env['hr.employee'].search([('user_id', '!=', False)]).ids
|
||||
if self.project_id and self.project_id.privacy_visibility == 'followers':
|
||||
print("project_all_emp_ids", self.project_id.allowed_internal_user_ids, self.project_id.allowed_internal_user_ids.ids)
|
||||
user_ids = self.env['hr.employee'].search([('user_id', 'in', self.project_id.allowed_internal_user_ids.ids)]).ids
|
||||
project_all_emp_ids = manager_id + user_ids + consul_project_ids
|
||||
print("project_all_emp_idsproject_all_emp_ids", project_all_emp_ids, domain)
|
||||
result = {
|
||||
'domain': {'task_id': domain},
|
||||
'domain': {'task_id': domain, 'employee_id': [('id', 'in', project_all_emp_ids)]},
|
||||
}
|
||||
if self.project_id != self.task_id.project_id:
|
||||
# reset task when changing project
|
||||
|
|
|
@ -7,9 +7,11 @@
|
|||
<field name="model">planning.slot</field>
|
||||
<field name="inherit_id" ref="planning.planning_view_tree"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='role_id']" position="after">
|
||||
<xpath expr="//field[@name='employee_id']" position="before">
|
||||
<field name="project_id"/> <!-- optional="hide" -->
|
||||
<field name="task_id"/>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='employee_id']" position="after">
|
||||
<field name="budgeted_hours"/>
|
||||
</xpath>
|
||||
</field>
|
||||
|
@ -20,11 +22,13 @@
|
|||
<field name="model">planning.slot</field>
|
||||
<field name="inherit_id" ref="planning.planning_view_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='role_id']" position="after">
|
||||
<xpath expr="//field[@name='employee_id']" position="before">
|
||||
<field name="project_id" context="{'default_allow_forecast': True}"/>
|
||||
<field name="budgeted_hours"/>
|
||||
<field name="task_id" attrs="{'invisible': [('project_id', '=', False)]}"/>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='employee_id']" position="after">
|
||||
<field name="budgeted_hours"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<field name="allow_forecast"/>
|
||||
</xpath>
|
||||
<xpath expr="//div[hasclass('o_project_kanban_boxes')]" position="inside">
|
||||
<a t-if="record.allow_forecast.raw_value" class="o_project_kanban_box" name="%(project_forecast_action_from_project)d" type="action">
|
||||
<a t-if="record.allow_forecast.raw_value" class="o_project_kanban_box" name="action_view_project_forecast_action_from_project" type="object">
|
||||
<div>
|
||||
<span class="o_label">Planning</span>
|
||||
</div>
|
||||
|
@ -43,8 +43,8 @@
|
|||
<field name="allow_forecast"/>
|
||||
</xpath>
|
||||
<div name="button_box" position="inside">
|
||||
<button class="oe_stat_button" type="action" attrs="{'invisible':[('allow_forecast', '=', False)]}"
|
||||
name="%(project_forecast_action_from_project)d" icon="fa-tasks">
|
||||
<button class="oe_stat_button" type="object" attrs="{'invisible':[('allow_forecast', '=', False)]}"
|
||||
name="action_view_project_forecast_action_from_project" icon="fa-tasks">
|
||||
<span>Planning</span>
|
||||
</button>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue