Skip to content

Commit

Permalink
[IMP]sale_teams: sale channels add toggle favorite button and sale da…
Browse files Browse the repository at this point in the history
…shboard search view
  • Loading branch information
sah-odoo authored and atp-odoo committed Mar 24, 2017
1 parent f4cba34 commit f78a42e
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 5 deletions.
42 changes: 41 additions & 1 deletion addons/sales_team/models/crm_team.py
Expand Up @@ -35,6 +35,9 @@ def _get_default_team_id(self, user_id=None):
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',
Expand Down Expand Up @@ -68,6 +71,14 @@ def _get_default_team_id(self, user_id=None):
('year', 'This Year'),
], string='Period', default='month', help="The time period this channel's dashboard graph will consider.")

favorite_user_ids = fields.Many2many(
'res.users', 'team_favorite_user_rel', 'team_id', 'user_id',
default=_get_default_favorite_user_ids,
string='Favorite Members')

is_favorite = fields.Boolean(compute='_compute_is_favorite', string='Show team on dashboard',
help="Whether this team should be displayed on the dashboard or not")

@api.depends('dashboard_graph_group', 'dashboard_graph_model', 'dashboard_graph_period')
def _compute_dashboard_graph(self):
for team in self.filtered('dashboard_graph_model'):
Expand All @@ -78,6 +89,10 @@ def _compute_dashboard_graph(self):
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.
"""
Expand Down Expand Up @@ -234,6 +249,20 @@ def _compute_dashboard_button_name(self):
for team in self:
team.dashboard_button_name = _("Big Pretty Button :)") # placeholder

@api.multi
def toggle_favorite(self):
favorite_team = not_fav_team = self.env['crm.team'].sudo()
for team in self:
if self.env.user in team.favorite_user_ids:
favorite_team |= team
else:
not_fav_team |= team

# team User has no write access for team.
not_fav_team.write({'favorite_user_ids': [(4, self.env.uid)]})
favorite_team.write({'favorite_user_ids': [(3, self.env.uid)]})


def action_primary_channel_button(self):
""" skeleton function to be overloaded
It will return the adequate action depending on the sales channel's options
Expand All @@ -247,4 +276,15 @@ def _onchange_team_type(self):

@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.favorite_user_ids = [(4, member.id) for member in team.member_ids]
return team

@api.multi
def write(self, values):
res = super(CrmTeam, self).write(values)
if values.get('member_ids'):
for team in self:
team.favorite_user_ids = [(4, member.id) for member in team.member_ids]
return res
2 changes: 1 addition & 1 deletion addons/sales_team/static/src/js/sales_team_dashboard.js
Expand Up @@ -17,7 +17,7 @@ var _lt = core._lt;
var SalesTeamDashboardView = KanbanView.extend({
display_name: _lt('Dashboard'),
icon: 'fa-dashboard',
searchview_hidden: true,
searchview_hidden: false,
events: {
'click .o_dashboard_action': 'on_dashboard_action_clicked',
'click .o_target_to_set': 'on_dashboard_target_clicked',
Expand Down
20 changes: 20 additions & 0 deletions addons/sales_team/static/src/less/sales_team_dashboard.less
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
}
}
5 changes: 2 additions & 3 deletions addons/sales_team/views/crm_team_views.xml
Expand Up @@ -26,15 +26,14 @@
<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">
<field name="name">Case Teams - Search</field>
<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"/>
Expand All @@ -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">
Expand Down
10 changes: 10 additions & 0 deletions addons/sales_team/views/sales_team_dashboard.xml
Expand Up @@ -10,6 +10,7 @@
<field name="member_ids"/>
<field name="color"/>
<field name="currency_id"/>
<field name="is_favorite"/>
<templates>
<t t-name="kanban-box">
<div t-attf-class="#{kanban_color(record.color.raw_value)}">
Expand Down Expand Up @@ -66,6 +67,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>
Expand Down

0 comments on commit f78a42e

Please sign in to comment.