[IMP] sale_team: add favorite mechanism on sales team
Currently default displayed sales team in dashboard are the one current user is member of. However as an user can be member of only one sales team it is not very easy to manipulate. This commit improves that behavior by adding a favorite mechanism. Users can favorite several sales team. Those are displayed in the dashboard allowing users to decide which sales team to display independently of being a member of the team or not. Dashboard now also display a search bar in order to be able to change the default behavior and choose other filters if necessary. A security rule is updated as salesmen should be able to read several sales team from now on.
This commit is contained in:
committed by
Thibault Delavallée
parent
33401e891b
commit
00e277fc4f
@@ -37,6 +37,9 @@ class CrmTeam(models.Model):
|
||||
team_id = default_team_id
|
||||
return team_id
|
||||
|
||||
def _get_default_favorite_user_ids(self):
|
||||
return [(6, 0, [self.env.uid])]
|
||||
|
||||
name = fields.Char('Sales Channel', required=True, translate=True)
|
||||
active = fields.Boolean(default=True, help="If the active field is set to false, it will allow you to hide the sales channel without removing it.")
|
||||
company_id = fields.Many2one('res.company', string='Company',
|
||||
@@ -46,6 +49,14 @@ class CrmTeam(models.Model):
|
||||
string="Currency", readonly=True)
|
||||
user_id = fields.Many2one('res.users', string='Channel Leader')
|
||||
member_ids = fields.One2many('res.users', 'sale_team_id', string='Channel Members')
|
||||
favorite_user_ids = fields.Many2many(
|
||||
'res.users', 'team_favorite_user_rel', 'team_id', 'user_id',
|
||||
string='Favorite Members',
|
||||
default=_get_default_favorite_user_ids)
|
||||
is_favorite = fields.Boolean(
|
||||
string='Show on dashboard',
|
||||
compute='_compute_is_favorite', inverse='_set_is_favorite',
|
||||
help="Favorite teams to display them in the dashboard and access them easily.")
|
||||
reply_to = fields.Char(string='Reply-To',
|
||||
help="The email address put in the 'Reply-To' of all emails sent by Odoo about cases in this sales channel")
|
||||
color = fields.Integer(string='Color Index', help="The color of the channel", default=1)
|
||||
@@ -80,6 +91,10 @@ class CrmTeam(models.Model):
|
||||
team.dashboard_graph_type = 'line'
|
||||
team.dashboard_graph_data = json.dumps(team._get_graph())
|
||||
|
||||
def _compute_is_favorite(self):
|
||||
for team in self:
|
||||
team.is_favorite = self.env.user in team.favorite_user_ids
|
||||
|
||||
def _graph_get_dates(self, today):
|
||||
""" return a coherent start and end date for the dashboard graph according to the graph settings.
|
||||
"""
|
||||
@@ -259,4 +274,26 @@ class CrmTeam(models.Model):
|
||||
|
||||
@api.model
|
||||
def create(self, values):
|
||||
return super(CrmTeam, self.with_context(mail_create_nosubscribe=True)).create(values)
|
||||
team = super(CrmTeam, self.with_context(mail_create_nosubscribe=True)).create(values)
|
||||
if values.get('member_ids'):
|
||||
team._add_members_to_favorites()
|
||||
return team
|
||||
|
||||
@api.multi
|
||||
def write(self, values):
|
||||
res = super(CrmTeam, self).write(values)
|
||||
if values.get('member_ids'):
|
||||
self._add_members_to_favorites()
|
||||
return res
|
||||
|
||||
@api.multi
|
||||
def toggle_favorite(self):
|
||||
sudoed_self = self.sudo()
|
||||
to_fav = sudoed_self.filtered(lambda team: self.env.user not in team.favorite_user_ids)
|
||||
to_fav.write({'favorite_user_ids': [(4, self.env.uid)]})
|
||||
(sudoed_self - to_fav).write({'favorite_user_ids': [(3, self.env.uid)]})
|
||||
return True
|
||||
|
||||
def _add_members_to_favorites(self):
|
||||
for team in self:
|
||||
team.favorite_user_ids = [(4, member.id) for member in team.member_ids]
|
||||
|
||||
@@ -22,14 +22,6 @@
|
||||
<field name="users" eval="[(4, ref('base.user_root'))]"/>
|
||||
</record>
|
||||
|
||||
|
||||
<record id="crm_rule_own_salesteam" model="ir.rule">
|
||||
<field name="name">Own Salesteam</field>
|
||||
<field ref="sales_team.model_crm_team" name="model_id"/>
|
||||
<field name="domain_force">[('member_ids', 'in', user.id)]</field>
|
||||
<field name="groups" eval="[(4, ref('sales_team.group_sale_salesman'))]"/>
|
||||
</record>
|
||||
|
||||
<record id="crm_rule_all_salesteam" model="ir.rule">
|
||||
<field name="name">All Salesteam</field>
|
||||
<field ref="sales_team.model_crm_team" name="model_id"/>
|
||||
|
||||
@@ -227,7 +227,7 @@ var SalesTeamDashboardView = KanbanView.extend({
|
||||
}),
|
||||
display_name: _lt('Dashboard'),
|
||||
icon: 'fa-dashboard',
|
||||
searchview_hidden: true,
|
||||
searchview_hidden: false,
|
||||
});
|
||||
|
||||
view_registry.add('sales_team_dashboard', SalesTeamDashboardView);
|
||||
|
||||
@@ -11,6 +11,19 @@
|
||||
@media (min-width: @screen-sm-min) {
|
||||
min-width: 450px;
|
||||
}
|
||||
.o_dashboard_star {
|
||||
font-size: 12px;
|
||||
|
||||
&.fa-star-o {
|
||||
color: @odoo-main-color-muted;
|
||||
&:hover {
|
||||
color: gold;
|
||||
}
|
||||
}
|
||||
&.fa-star {
|
||||
color: gold;
|
||||
}
|
||||
}
|
||||
.o_kanban_card_upper_content {
|
||||
margin-bottom: @odoo-horizontal-padding*2 + @o-kanban-progressbar-height + 85px;
|
||||
}
|
||||
@@ -194,4 +207,11 @@
|
||||
&.o_kanban_nocontent .o_sales_dashboard {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
&.o_kanban_grouped {
|
||||
.o-flex-flow(row, wrap);
|
||||
.o_kanban_record {
|
||||
min-width: inherit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
<menuitem action="base.action_res_bank_form" id="menu_action_res_bank_form" parent="menu_config_bank_accounts" sequence="1" groups="base.group_no_one"/>
|
||||
<menuitem action="base.action_res_partner_bank_account_form" id="menu_action_res_partner_bank_form" parent="menu_config_bank_accounts" groups="base.group_no_one" sequence="2"/>
|
||||
|
||||
|
||||
|
||||
<!-- Cateamions Search view -->
|
||||
<record id="crm_team_salesteams_search" model="ir.ui.view">
|
||||
@@ -34,7 +33,7 @@
|
||||
<field name="model">crm.team</field>
|
||||
<field name="arch" type="xml">
|
||||
<search string="Salesteams Search">
|
||||
<filter name="personal" string="My Salesteams" domain="['|', ('member_ids', '=', uid), ('user_id', '=', uid)]"/>
|
||||
<filter name="my_favorites" string="My Favorites" domain="[('favorite_user_ids', 'in', uid)]"/>
|
||||
<separator/>
|
||||
<filter string="Archived" name="inactive" domain="[('active','=',False)]"/>
|
||||
<field name="name"/>
|
||||
@@ -52,7 +51,7 @@
|
||||
<field name="res_model">crm.team</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">kanban,form</field>
|
||||
<field name="context">{}</field>
|
||||
<field name="context">{'search_default_my_favorites': 1}</field>
|
||||
<field name="view_id" ref="crm_team_salesteams_search"/>
|
||||
<field name="help" type="html">
|
||||
<p class="oe_view_nocontent_create">
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
<field name="color"/>
|
||||
<field name="dashboard_graph_type"/>
|
||||
<field name="currency_id"/>
|
||||
<field name="is_favorite"/>
|
||||
<templates>
|
||||
<t t-name="kanban-box">
|
||||
<div>
|
||||
@@ -67,6 +68,15 @@
|
||||
<a type="edit">Settings</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb16">
|
||||
<div class="col-xs-6">
|
||||
<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"/>
|
||||
<l t-if="record.is_favorite.raw_value"> Remove from My Favorites</l>
|
||||
<l t-elif="!record.is_favorite.raw_value"> Add to My Favorites</l>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
|
||||
Reference in New Issue
Block a user