[IMP] project: favorite
A favorite system is introduced in project model. It uses a many2many between users and projects. This allow users to favorite a project and see them by default in their project dashboard. The new default fitler when seeing projects is now favorited projects.
This commit is contained in:
committed by
Thibault Delavallée
parent
783f246bde
commit
dc7aca3ca6
@@ -157,6 +157,19 @@ class project(osv.osv):
|
||||
'context': "{'default_res_model': '%s','default_res_id': %d}" % (self._name, res_id)
|
||||
}
|
||||
|
||||
def _get_favorite(self, cr, uid, ids, name, args, context=None):
|
||||
return dict((project.id, uid in project.favorite_user_ids.ids) for project in self.browse(cr, uid, ids, context=context))
|
||||
|
||||
def _set_favorite(self, cr, uid, ids, field_name, field_value, args, context=None):
|
||||
if field_value:
|
||||
self.write(cr, uid, ids, {'favorite_user_ids': [(4, uid)]}, context=context)
|
||||
else:
|
||||
self.write(cr, uid, ids, {'favorite_user_ids': [(3, uid)]}, context=context)
|
||||
return True
|
||||
|
||||
def _get_default_favorite_user_ids(self, cr, uid, context=None):
|
||||
return [(6, 0, [uid])]
|
||||
|
||||
# Lambda indirection method to avoid passing a copy of the overridable method when declaring the field
|
||||
_alias_models = lambda self, *args, **kwargs: self._get_alias_models(*args, **kwargs)
|
||||
_visibility_selection = lambda self, *args, **kwargs: self._get_visibility_selection(*args, **kwargs)
|
||||
@@ -169,6 +182,13 @@ class project(osv.osv):
|
||||
help="Link this project to an analytic account if you need financial management on projects. "
|
||||
"It enables you to connect projects with budgets, planning, cost and revenue analysis, timesheets on projects, etc.",
|
||||
ondelete="cascade", required=True, auto_join=True),
|
||||
'favorite_user_ids': fields.many2many(
|
||||
'res.users', 'project_favorite_user_rel', 'project_id', 'user_id',
|
||||
string='Members'),
|
||||
'is_favorite': fields.function(
|
||||
_get_favorite, fnct_inv=_set_favorite, type="boolean",
|
||||
string='Show Project on dashboard',
|
||||
help="Whether this project should be displayed on the dashboard or not"),
|
||||
'label_tasks': fields.char('Use Tasks as', help="Gives label to tasks on project's kanban view."),
|
||||
'tasks': fields.one2many('project.task', 'project_id', "Task Activities"),
|
||||
'resource_calendar_id': fields.many2one('resource.calendar', 'Working Time', help="Timetable working hours to adjust the gantt diagram report", states={'close':[('readonly',True)]} ),
|
||||
@@ -208,6 +228,7 @@ class project(osv.osv):
|
||||
_order = "sequence, name, id"
|
||||
_defaults = {
|
||||
'active': True,
|
||||
'favorite_user_ids': _get_default_favorite_user_ids,
|
||||
'type': 'contract',
|
||||
'label_tasks': 'Tasks',
|
||||
'state': 'open',
|
||||
@@ -331,6 +352,17 @@ class project(osv.osv):
|
||||
tasks.write({'active': vals['active']})
|
||||
return res
|
||||
|
||||
def toggle_favorite(self, cr, uid, ids, context=None):
|
||||
favorite_project_ids = []
|
||||
not_fav_project_ids = []
|
||||
for project in self.browse(cr, uid, ids, context=context):
|
||||
if uid in project.favorite_user_ids.ids:
|
||||
favorite_project_ids.append(project.id)
|
||||
else:
|
||||
not_fav_project_ids.append(project.id)
|
||||
self.write(cr, uid, favorite_project_ids, {'is_favorite': False}, context=context)
|
||||
self.write(cr, uid, not_fav_project_ids, {'is_favorite': True}, context=context)
|
||||
|
||||
|
||||
class task(osv.osv):
|
||||
_name = "project.task"
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
<field name="alias_name"/>
|
||||
<field name="alias_domain"/>
|
||||
<field name="doc_count"/>
|
||||
<field name="is_favorite"/>
|
||||
<templates>
|
||||
<t t-name="kanban-box">
|
||||
<div t-attf-class="#{kanban_color(record.color.raw_value)} oe_kanban_global_click">
|
||||
@@ -44,6 +45,9 @@
|
||||
<div t-if="widget.editable" class="o_project_kanban_colorpicker">
|
||||
<ul class="oe_kanban_colorpicker" data-field="color"/>
|
||||
</div>
|
||||
<div>
|
||||
<a type="object" name="toggle_favorite"><i t-attf-class="fa o_dashboard_star #{record.is_favorite.raw_value ? 'fa-star' : 'fa-star-o'}" title="Click to add/remove from favorite"/> Favorite</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="o_project_kanban_manage">
|
||||
<a class="o_kanban_manage_toggle_button" href="#">More <i class="fa fa-caret-down"/></a>
|
||||
|
||||
@@ -157,6 +157,7 @@
|
||||
<field name="arch" type="xml">
|
||||
<search string="Search Project">
|
||||
<field name="name" string="Project Name"/>
|
||||
<filter string="My Projects" name="my_projects" domain="[('favorite_user_ids', 'in', uid)]"/>
|
||||
<filter string="Open" name="Current" domain="[('state', '=','open')]"/>
|
||||
<filter string="Pending" name="Pending" domain="[('state', '=','pending')]"/>
|
||||
<separator/>
|
||||
@@ -198,7 +199,7 @@
|
||||
<field name="domain">[]</field>
|
||||
<field name="view_mode">kanban,form</field>
|
||||
<field name="search_view_id" ref="view_project_project_filter"/>
|
||||
<field name="context">{'search_default_Current': 1}</field>
|
||||
<field name="context">{'search_default_my_projects': 1}</field>
|
||||
<field name="help" type="html">
|
||||
<p class="oe_view_nocontent_create">
|
||||
Create a new project.
|
||||
|
||||
@@ -29,6 +29,20 @@
|
||||
}
|
||||
}
|
||||
|
||||
.o_dashboard_star {
|
||||
font-size: 12px;
|
||||
|
||||
&.fa-star-o {
|
||||
color: @odoo-main-color-muted;
|
||||
&:hover {
|
||||
color: gold;
|
||||
}
|
||||
}
|
||||
&.fa-star {
|
||||
color: gold;
|
||||
}
|
||||
}
|
||||
|
||||
.o_project_kanban_boxes {
|
||||
width: 30%;
|
||||
.o-flex(0, 0, auto);
|
||||
|
||||
Reference in New Issue
Block a user