diff --git a/sales_team_parent/__init__.py b/sales_team_parent/__init__.py new file mode 100644 index 000000000..8f99694e2 --- /dev/null +++ b/sales_team_parent/__init__.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Cybrosys Technologies Pvt. Ltd. +# Copyright (C) 2016-TODAY Cybrosys Technologies(). +# Author: Cybrosys Technologies() +# you can modify it under the terms of the GNU LESSER +# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. +# +# It is forbidden to publish, distribute, sublicense, or sell copies +# of the Software or modified copies of the Software. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. +# +# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE +# GENERAL PUBLIC LICENSE (LGPL v3) along with this program. +# If not, see . +# +############################################################################## + +import models diff --git a/sales_team_parent/__openerp__.py b/sales_team_parent/__openerp__.py new file mode 100644 index 000000000..32113b8c6 --- /dev/null +++ b/sales_team_parent/__openerp__.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Cybrosys Technologies Pvt. Ltd. +# Copyright (C) 2016-TODAY Cybrosys Technologies(). +# Author: Cybrosys Technologies() +# you can modify it under the terms of the GNU LESSER +# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. +# +# It is forbidden to publish, distribute, sublicense, or sell copies +# of the Software or modified copies of the Software. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. +# +# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE +# GENERAL PUBLIC LICENSE (LGPL v3) along with this program. +# If not, see . +# +############################################################################## +{ + 'name': 'Parent Team & Targets', + 'version': '9.0.1.0.0', + 'category': 'Sales', + 'summary': 'Sales Team Targets and Parent Teams', + 'author': 'Cybrosys Techno Solutions', + 'company': 'Cybrosys Techno Solutions', + 'depends': ['crm', 'sale'], + 'images': ['static/description/banner.jpg'], + 'website': 'http://www.cybrosys.com', + 'data': [ + 'views/parent_team.xml', + 'views/sales_man_target.xml', + 'views/sales_team_target.xml', + 'security/ir.model.access.csv', + ], + 'installable': True, + 'auto_install': False, +} \ No newline at end of file diff --git a/sales_team_parent/models/__init__.py b/sales_team_parent/models/__init__.py new file mode 100644 index 000000000..8437100f2 --- /dev/null +++ b/sales_team_parent/models/__init__.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Cybrosys Technologies Pvt. Ltd. +# Copyright (C) 2016-TODAY Cybrosys Technologies(). +# Author: Cybrosys Technologies() +# you can modify it under the terms of the GNU LESSER +# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. +# +# It is forbidden to publish, distribute, sublicense, or sell copies +# of the Software or modified copies of the Software. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. +# +# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE +# GENERAL PUBLIC LICENSE (LGPL v3) along with this program. +# If not, see . +# +############################################################################## + +import crm_target +import crm_target_team diff --git a/sales_team_parent/models/crm_target.py b/sales_team_parent/models/crm_target.py new file mode 100644 index 000000000..d3ba43dde --- /dev/null +++ b/sales_team_parent/models/crm_target.py @@ -0,0 +1,131 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Cybrosys Technologies Pvt. Ltd. +# Copyright (C) 2016-TODAY Cybrosys Technologies(). +# Author: Cybrosys Technologies() +# you can modify it under the terms of the GNU LESSER +# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. +# +# It is forbidden to publish, distribute, sublicense, or sell copies +# of the Software or modified copies of the Software. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. +# +# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE +# GENERAL PUBLIC LICENSE (LGPL v3) along with this program. +# If not, see . +# +############################################################################## +from datetime import datetime +from dateutil import relativedelta +from openerp import models, fields, api +from openerp.tools.translate import _ + + +class CrmTeam(models.Model): + _name = "crm.target" + + def get_currency(self): + return self.env.user.company_id.currency_id.id + + name = fields.Char(string='Name') + user_id = fields.Many2one('res.users', 'Sales Person', required=True) + sales_team = fields.Many2one('crm.team', string='Sales Team') + target_amount = fields.Float('Target') + date_from = fields.Date("Starting date", required=True) + date_to = fields.Date("Ending date", required=True) + duration = fields.Integer(default=1) + currency_id = fields.Many2one('res.currency', store=True, string='Currency', readonly=True, default=lambda self: self.get_currency()) + + @api.onchange('user_id') + def onchange_salesman(self): + team_ids = self.env['crm.team'].search([]) + dates = fields.Date + + for team_id in team_ids: + for member_id in team_id.member_ids: + if self.user_id == member_id: + self.sales_team = team_id.id + + @api.onchange('date_from', 'date_to') + def get_duration(self): + if self.date_from and self.date_to: + r = relativedelta.relativedelta(datetime.strptime(self.date_to, "%Y-%m-%d"), datetime.strptime(self.date_from, "%Y-%m-%d")) + + t_day = datetime.strptime(self.date_to, "%Y-%m-%d").day + t_month = datetime.strptime(self.date_to, "%Y-%m-%d").month + t_year = datetime.strptime(self.date_to, "%Y-%m-%d").year + + f_day = datetime.strptime(self.date_from, "%Y-%m-%d").day + f_month = datetime.strptime(self.date_from, "%Y-%m-%d").month + f_year = datetime.strptime(self.date_from, "%Y-%m-%d").year + if t_year < f_year: + self.date_from = None + self.date_to = None + return { + 'warning': { + 'title': _('Warning!'), + 'message': _('Please check the date'), + } + } + elif t_year == f_year and t_month < f_month: + self.date_to = None + self.date_from = None + return { + 'warning': { + 'title': _('Warning!'), + 'message': _('Please check the date'), + } + } + elif t_year == f_year and t_month == f_month and t_day < f_day: + self.date_to = None + self.date_from = None + return { + 'warning': { + 'title': _('Warning!'), + 'message': _('Please check the date'), + } + } + self.duration = r.months if r.months > 0 else 1 + + def action_your_target(self, cr, uid, context=None): + tree_res = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'sales_team_parent', 'sales_target_tree_view') + x = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'sales_team_parent', 'action_crm_sales_target_act') + + tree_id = tree_res and tree_res[1] or False + form_res = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'sales_team_parent', 'sales_target_form_view') + form_id = form_res and form_res[1] or False + + user_obj = self.pool.get('res.users') + + u_id = user_obj.browse(cr, uid, uid, context=context) + obj_target = self.pool.get('crm.target').search(cr, uid, [], context=context) + + if u_id.has_group('base.group_sale_salesman_all_leads') and u_id.has_group( + 'base.group_sale_salesman') and u_id.has_group('base.group_sale_manager'): + obj_target_list = obj_target + + else: + obj_target_list = [] + if obj_target: + for obj in obj_target: + if self.pool.get('crm.target').browse(cr, uid, [obj]).user_id.id == uid: + obj_target_list.append(obj) + + return { + 'model': 'ir.actions.act_window', + 'name': 'Target', + 'type': 'ir.actions.act_window', + 'view_type': 'form', + 'view_mode': 'form,tree', + 'res_model': 'crm.target', + 'views': [(tree_id, 'tree'), (form_id, 'form')], + 'domain': [('id', 'in', obj_target_list)], + 'id': x[1], + } + + diff --git a/sales_team_parent/models/crm_target_team.py b/sales_team_parent/models/crm_target_team.py new file mode 100644 index 000000000..24fa0e592 --- /dev/null +++ b/sales_team_parent/models/crm_target_team.py @@ -0,0 +1,59 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Cybrosys Technologies Pvt. Ltd. +# Copyright (C) 2016-TODAY Cybrosys Technologies(). +# Author: Cybrosys Technologies() +# you can modify it under the terms of the GNU LESSER +# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. +# +# It is forbidden to publish, distribute, sublicense, or sell copies +# of the Software or modified copies of the Software. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. +# +# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE +# GENERAL PUBLIC LICENSE (LGPL v3) along with this program. +# If not, see . +# +############################################################################## + +from openerp import models, fields, api + + +class CrmTeam(models.Model): + _inherit = 'crm.team' + + def get_currency(self): + return self.env.user.company_id.currency_id.id + + team_target = fields.Float(string='Team Target', compute="compute_team_target") + parent_team = fields.Many2one('crm.team', string='Parent Team', copy=False) + currency_id = fields.Many2one('res.currency', store=True, string='Currency', readonly=True, default=lambda self: self.get_currency()) + + @api.one + def compute_team_target(self): + total = 0 + childs = self.get_childs(self.id) + childs += self + for team in childs: + for member_id in team.member_ids: + target = team.env['crm.target'].search([('user_id', '=', member_id.id)]) + if target: + for t in target: + total += t.target_amount + + team.team_target = total + return + + def get_childs(self, team_id): + child_teams = self.search([('parent_team.id', '=', team_id)]) + if child_teams: + for team in child_teams: + child_teams += self.get_childs(team.id) + return child_teams + + diff --git a/sales_team_parent/security/ir.model.access.csv b/sales_team_parent/security/ir.model.access.csv new file mode 100644 index 000000000..db393ff46 --- /dev/null +++ b/sales_team_parent/security/ir.model.access.csv @@ -0,0 +1,3 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_crm_target_sale_salesman,crm.target,model_crm_target,base.group_sale_salesman_all_leads,1,0,0,0 +access_crm_target_sale_manager,crm.target.manager,model_crm_target,base.group_sale_salesman,1,0,0,0 diff --git a/sales_team_parent/static/description/banner.jpg b/sales_team_parent/static/description/banner.jpg new file mode 100644 index 000000000..69220ab26 Binary files /dev/null and b/sales_team_parent/static/description/banner.jpg differ diff --git a/sales_team_parent/static/description/cybro_logo.png b/sales_team_parent/static/description/cybro_logo.png new file mode 100644 index 000000000..bb309114c Binary files /dev/null and b/sales_team_parent/static/description/cybro_logo.png differ diff --git a/sales_team_parent/static/description/icon.png b/sales_team_parent/static/description/icon.png new file mode 100644 index 000000000..87dc94805 Binary files /dev/null and b/sales_team_parent/static/description/icon.png differ diff --git a/sales_team_parent/static/description/index.html b/sales_team_parent/static/description/index.html new file mode 100644 index 000000000..38376f8af --- /dev/null +++ b/sales_team_parent/static/description/index.html @@ -0,0 +1,103 @@ +
+
+

Parent Team

+

..Parent Team and Targets..

+

Cybrosys Technologies , www.cybrosys.com

+
+

+ This module by Cybrosys Technologies introduces the parent team - child team concept. We can also assign + targets to each salesperson. +

+
+
+ +
+
+

Features

+
+

+ ☛ Create parent team or child team for an existing sales team. +

+

+ ☛ Admin can assign targets to salesperson. +

+

+ ☛ View team target. +

+
+
+
+ +
+
+
+

Create parent team.

+
+ +
+

+ Go to Sales -> Configuration -> Sales Team. Select a team and assign a parent for that team. The parent-child relation + between sales teams will be useful in many situations. For example, the leader of parent team has power over it's child teams. + The parent team leader will be able to access his child team's targets. +

+
+
+
+ +
+
+
+

Assign target to salesperson.

+
+ +
+

+ Go to Sales -> Configuration -> Salesman Target and assign targets to salesperson. Only administrator can + assign targets. Salesperson can view his targets only. + Head of sale can view all the targets of his team members and admin can see all the targets.

+

+ We can assign time duration for each target. When we enter the starting date and ending date of a target, + if it is not valid, the system will take care of it and informs us. The targets will always be in company currency. +

+
+
+
+
+
+
+

Team target.

+
+ +
+

+ The total team target will be the sum of targets of it's members and it's child teams. +

+
+
+
+ +
+

Need Any Help?

+ +
diff --git a/sales_team_parent/static/description/parent-team.png b/sales_team_parent/static/description/parent-team.png new file mode 100644 index 000000000..09762ce4a Binary files /dev/null and b/sales_team_parent/static/description/parent-team.png differ diff --git a/sales_team_parent/static/description/salesman-target.png b/sales_team_parent/static/description/salesman-target.png new file mode 100644 index 000000000..2f8735226 Binary files /dev/null and b/sales_team_parent/static/description/salesman-target.png differ diff --git a/sales_team_parent/static/description/team-target.png b/sales_team_parent/static/description/team-target.png new file mode 100644 index 000000000..ac682fcc6 Binary files /dev/null and b/sales_team_parent/static/description/team-target.png differ diff --git a/sales_team_parent/views/parent_team.xml b/sales_team_parent/views/parent_team.xml new file mode 100644 index 000000000..09bda13b3 --- /dev/null +++ b/sales_team_parent/views/parent_team.xml @@ -0,0 +1,16 @@ + + + + + crm.team.form + crm.team + + + + + + + + + + \ No newline at end of file diff --git a/sales_team_parent/views/sales_man_target.xml b/sales_team_parent/views/sales_man_target.xml new file mode 100644 index 000000000..61f1f2956 --- /dev/null +++ b/sales_team_parent/views/sales_man_target.xml @@ -0,0 +1,75 @@ + + + + + Target + crm.target + form + tree,form + + + + + Targets + ir.actions.server + crm.target + + form + tree,form + code + action = self.action_your_target(cr, uid, context=context) + + + + + + + crm.target.tree + crm.target + + + + + + + + + + + + + + crm.target.form + crm.target + +
+ +
+
+ + + + + + + + + + + + + + + + + +
+
+
+
+
+
\ No newline at end of file diff --git a/sales_team_parent/views/sales_team_target.xml b/sales_team_parent/views/sales_team_target.xml new file mode 100644 index 000000000..348f11c92 --- /dev/null +++ b/sales_team_parent/views/sales_team_target.xml @@ -0,0 +1,16 @@ + + + + + crm.team.target.form + crm.team + + + + + + + + + + \ No newline at end of file