diff --git a/sales_team_parent/__init__.py b/sales_team_parent/__init__.py new file mode 100644 index 000000000..4d1233fc2 --- /dev/null +++ b/sales_team_parent/__init__.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Cybrosys Technologies Pvt. Ltd. +# Copyright (C) 2017-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/__manifest__.py b/sales_team_parent/__manifest__.py new file mode 100644 index 000000000..5d08a0072 --- /dev/null +++ b/sales_team_parent/__manifest__.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Cybrosys Technologies Pvt. Ltd. +# Copyright (C) 2017-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': '10.0.1.0.0', + 'category': 'Sales', + 'summary': 'Sales Team Targets and Parent Teams', + 'author': 'Cybrosys Techno Solutions', + 'company': 'Cybrosys Techno Solutions', + 'website': 'http://www.cybrosys.com', + 'depends': ['crm', 'sale'], + 'images': ['static/description/banner.jpg'], + '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..48b8ea6e3 --- /dev/null +++ b/sales_team_parent/models/__init__.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Cybrosys Technologies Pvt. Ltd. +# Copyright (C) 2017-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..a41d765fc --- /dev/null +++ b/sales_team_parent/models/crm_target.py @@ -0,0 +1,133 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Cybrosys Technologies Pvt. Ltd. +# Copyright (C) 2017-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 odoo import models, fields, api +from odoo.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', required=True) + 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): + tree_res = self.env['ir.model.data'].get_object_reference('sales_team_parent', 'sales_target_tree_view') + x = self.env['ir.model.data'].get_object_reference('sales_team_parent', 'action_crm_sales_target_act') + + tree_id = tree_res and tree_res[1] or False + form_res = self.env['ir.model.data'].get_object_reference('sales_team_parent', 'sales_target_form_view') + form_id = form_res and form_res[1] or False + + user_obj = self.env['res.users'] + + u_id = user_obj.browse([self._uid]) + obj_target = self.env['crm.target'].search([]) + + if u_id.has_group('sales_team.group_sale_salesman_all_leads') and u_id.has_group( + 'sales_team.group_sale_salesman') and u_id.has_group('sales_team.group_sale_manager'): + obj_target_list = obj_target.ids + + else: + obj_target_list = [] + if obj_target: + for obj in obj_target.ids: + print obj + if self.env['crm.target'].browse([obj]).user_id.id == self._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..5bce926d2 --- /dev/null +++ b/sales_team_parent/models/crm_target_team.py @@ -0,0 +1,59 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Cybrosys Technologies Pvt. Ltd. +# Copyright (C) 2017-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 odoo 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..d7c46e8ed --- /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,sales_team.group_sale_salesman_all_leads,1,0,0,0 +access_crm_target_sale_manager,crm.target.manager,model_crm_target,sales_team.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..e074951f2 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..83ce65e7d 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..c057590b3 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..a414795d3 --- /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..fb55620ef --- /dev/null +++ b/sales_team_parent/views/sales_man_target.xml @@ -0,0 +1,76 @@ + + + + + crm.target.form + crm.target + +
+ +
+
+ + + + + + + + + + + + + + + + + +
+
+
+
+ + + crm.target.tree + crm.target + + + + + + + + + + + + + + + Target + crm.target + form + tree,form + + + + + Targets + ir.actions.server + crm.target + + form + tree,form + code + action = model.action_your_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..e93dcae7e --- /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