diff --git a/crm_drag_back_permission/__init__.py b/crm_drag_back_permission/__init__.py new file mode 100644 index 000000000..b2462eb50 --- /dev/null +++ b/crm_drag_back_permission/__init__.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Cybrosys Technologies Pvt. Ltd. +# Copyright (C) 2009-TODAY Cybrosys Technologies(). +# Author: Nilmar Shereef() +# 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/crm_drag_back_permission/__manifest__.py b/crm_drag_back_permission/__manifest__.py new file mode 100644 index 000000000..532a9c574 --- /dev/null +++ b/crm_drag_back_permission/__manifest__.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Cybrosys Technologies Pvt. Ltd. +# Copyright (C) 2009-TODAY Cybrosys Technologies(). +# Author: Nilmar Shereef() +# 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': 'CRM Kanban Drag Back Permission', + 'version': '0.2', + 'category': 'CRM', + 'sequence': 6, + 'summary': 'Permission for Drag Back in CRM', + 'author': 'Cybrosys Techno Solutions', + 'company': 'Cybrosys Techno Solutions', + 'depends': ['crm', 'sale', 'sales_team'], + 'website': 'http://www.cybrosys.com', + 'images': ['static/description/banner.jpg'], + 'data': [ + 'views/crm_sales_team.xml', + 'views/crm_lead_update.xml', + 'views/templates.xml', + 'security/ir.model.access.csv', + + ], + 'installable': True, + 'auto_install': False, +} diff --git a/crm_drag_back_permission/models/__init__.py b/crm_drag_back_permission/models/__init__.py new file mode 100644 index 000000000..f65017551 --- /dev/null +++ b/crm_drag_back_permission/models/__init__.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Cybrosys Technologies Pvt. Ltd. +# Copyright (C) 2009-TODAY Cybrosys Technologies(). +# Author: Nilmar Shereef() +# 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 update_kanban_record + + diff --git a/crm_drag_back_permission/models/update_kanban_record.py b/crm_drag_back_permission/models/update_kanban_record.py new file mode 100644 index 000000000..d05c4ede0 --- /dev/null +++ b/crm_drag_back_permission/models/update_kanban_record.py @@ -0,0 +1,141 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Cybrosys Technologies Pvt. Ltd. +# Copyright (C) 2009-TODAY Cybrosys Technologies(). +# Author: Nilmar Shereef() +# 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 StageChange(models.Model): + _inherit = 'crm.lead' + + stage_previous = fields.Integer(string="Previous stage", default=False) + stage_next = fields.Integer(string="Next stage", default=False) + stage_type = fields.Char() + new_stage_id = fields.Selection([('previous', 'Previous'), ('current', 'Current'), ('next', 'Next')], readonly=True) + previous = fields.Char(string="Previous Stage", compute='get_previous_stage') + next_stage = fields.Char(string="Next Stage", compute='get_next_stage') + + + @api.one + def get_previous_stage(self): + self.previous = self.env['crm.stage'].search([('id', '=', self.stage_previous)]).name + + @api.one + def get_next_stage(self): + self.next_stage = self.env['crm.stage'].search([('id', '=', self.stage_next)]).name + + @api.one + def approve_oppor(self): + self.write({'stage_id': self.env['crm.stage'].browse([self.stage_next]).id, 'stage_previous': self.stage_id.id, 'stage_next': 0, 'new_stage_id': ''}) + return + + @api.one + def decline_oppor(self): + self.write({'stage_id': self.env['crm.stage'].browse([self.stage_previous]).id, 'stage_previous': self.stage_id.id, 'stage_next': 0, 'new_stage_id': ''}) + return + + @api.multi + def write(self, vals): + if not vals.get('stage_previous') and vals.get('stage_id'): + last_stage = self.browse(self.ids).stage_id + if self.env['crm.stage'].browse([vals['stage_id']]).stage_order < last_stage.stage_order \ + and not self.env['res.users'].browse(self._uid).has_group('sales_team.group_sale_manager') \ + and not self.env['res.users'].browse(self._uid).has_group('sales_team.group_sale_salesman_all_leads'): + vals['stage_previous'] = last_stage.id + vals['stage_next'] = vals['stage_id'] + vals['stage_type'] = "approval" + vals['new_stage_id'] = 'current' + + to_approve = self.env['crm.stage'].search([('type', '=', 'approval'), ('name', '=', 'Waiting for approval')]) + if to_approve: + vals['stage_id'] = to_approve.id + else: + values = { + 'name': "Waiting for approval", + 'type': "approval", + 'stage_order': -1, + } + result = self.env['crm.stage'].create(values) + vals['stage_id'] = result.id + + elif vals.get('stage_id'): + vals['stage_type'] = "" + + res = super(StageChange, self).write(vals) + return res + + def get_approvals(self, context=None): + object_list = [] + tree_res = self.env['ir.model.data'].get_object_reference('crm', 'crm_case_tree_view_oppor') + x = self.env['ir.model.data'].get_object_reference('crm_drag_back_permission', 'action_waiting_approval_window') + tree_id = tree_res and tree_res[1] or False + form_res = self.env['ir.model.data'].get_object_reference('crm', 'crm_case_form_view_leads') + form_id = form_res and form_res[1] or False + approval_stage = self.env['crm.lead'] + approvals = approval_stage.search([('stage_id.type', '=', "approval")]) + user_obj = self.env['res.users'] + u_id = user_obj.browse([self._uid]) + 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'): + for i in approvals: + object_list.append(i.id) + elif u_id.has_group('sales_team.group_sale_salesman_all_leads') and u_id.has_group('sales_team.group_sale_salesman'): + teams = self.env['crm.team'].search([('user_id.id', '=', self._uid)]) + team_ids = [] + for i in teams: + team_ids.append(i.id) + object_list = [] + if approvals: + for obj in approvals: + if obj.team_id.id in team_ids: + object_list.append(obj.id) + elif u_id.has_group('sales_team.group_sale_salesman'): + object_list = [] + if approvals: + for obj in approvals: + if obj.user_id.id == self._uid: + object_list.append(obj.id) + return { + 'model': 'ir.actions.act_window', + 'name': 'Waiting Approval', + 'type': 'ir.actions.act_window', + 'view_type': 'form', + 'view_mode': 'form,tree', + 'res_model': 'crm.lead', + 'views': [(tree_id, 'tree'), (form_id, 'form')], + 'domain': [('id', 'in', object_list)], + 'id': x[1], + } + + +class NewStage(models.Model): + _inherit = 'crm.stage' + + stage_order = fields.Integer(string='Order') + type = fields.Selection([('lead', 'Lead'), ('opportunity', 'Opportunity'), ('both', 'Both'), ('approval', '')], + string='Type', required=True, + help="This field is used to distinguish stages related to Leads from stages related to " + "Opportunities or to specify stages available for both types.") + + + + + diff --git a/crm_drag_back_permission/security/ir.model.access.csv b/crm_drag_back_permission/security/ir.model.access.csv new file mode 100644 index 000000000..22a50073e --- /dev/null +++ b/crm_drag_back_permission/security/ir.model.access.csv @@ -0,0 +1,4 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_crm_stage,crm.stage,model_crm_stage,sales_team.group_sale_salesman,1,1,1,1 +access_crm_stage_head,crm.stage,model_crm_stage,sales_team.group_sale_salesman_all_leads,1,1,1,1 + diff --git a/crm_drag_back_permission/static/description/banner.jpg b/crm_drag_back_permission/static/description/banner.jpg new file mode 100644 index 000000000..590a4015d Binary files /dev/null and b/crm_drag_back_permission/static/description/banner.jpg differ diff --git a/crm_drag_back_permission/static/description/icon.png b/crm_drag_back_permission/static/description/icon.png new file mode 100644 index 000000000..c2fcd1632 Binary files /dev/null and b/crm_drag_back_permission/static/description/icon.png differ diff --git a/crm_drag_back_permission/static/description/image1.png b/crm_drag_back_permission/static/description/image1.png new file mode 100644 index 000000000..0cf22d44f Binary files /dev/null and b/crm_drag_back_permission/static/description/image1.png differ diff --git a/crm_drag_back_permission/static/description/image2.png b/crm_drag_back_permission/static/description/image2.png new file mode 100644 index 000000000..dd1b40710 Binary files /dev/null and b/crm_drag_back_permission/static/description/image2.png differ diff --git a/crm_drag_back_permission/static/description/image3.png b/crm_drag_back_permission/static/description/image3.png new file mode 100644 index 000000000..082e2aba3 Binary files /dev/null and b/crm_drag_back_permission/static/description/image3.png differ diff --git a/crm_drag_back_permission/static/description/image4.png b/crm_drag_back_permission/static/description/image4.png new file mode 100644 index 000000000..7656a24ed Binary files /dev/null and b/crm_drag_back_permission/static/description/image4.png differ diff --git a/crm_drag_back_permission/static/description/image5.png b/crm_drag_back_permission/static/description/image5.png new file mode 100644 index 000000000..cfabec583 Binary files /dev/null and b/crm_drag_back_permission/static/description/image5.png differ diff --git a/crm_drag_back_permission/static/description/index.html b/crm_drag_back_permission/static/description/index.html new file mode 100644 index 000000000..cab5dea54 --- /dev/null +++ b/crm_drag_back_permission/static/description/index.html @@ -0,0 +1,96 @@ +
+
+

CRM Kanban Drag Back

+

Permission for Back Drag in CRM Kanban view

+

Author : Cybrosys Techno Solutions , www.cybrosys.com

+
+
+
+ This module restricts some users to drag leads backwards in sales pipeline without permission. +
+
+ +
+
+
+ +
+
+
+

+ Go to Configuration -> Sales Teams, and enable the 'Leads' option for the teams you want to use. +

+
+
+
+ +
+
+
+

+ Go to Configuration -> Stages, and set an 'order'(integer value) for each stage you want to use in the pipeline. + The drag back is working based on this 'order' field value. When a user tries to drag a lead from one stage to another, + we will check the 'order' of those two stages. + If the movement is from a stage with higher order value to a stage with lower order value, it will be considered + as a back drag. +

+
+
+
+ +
+
+
+

+ When a salesperson tries to perform a back drag, the lead will go to a new stage, 'Waiting for Approval'. + From this stage, the Administrator or the Head of Sales of team which the lead belongs to, can + approve the lead to the stage requested by the user or decline the lead back to it's previous stage. + The salesperson can't move the lead from this stage. +

+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+

+ In the 'Waiting for Approval' stage, a lead will be visible only to the administrator, + the user to which the lead is assigned to and the head of sales of team that the lead belongs to. + When we select a lead in the 'Waiting for Approval' stage, we can see the stages, the lead comes from and where the lead is headed to. +

+
+
+
+ +
+
+
+
+ +
+

Need Any Help?

+ +
+ + + diff --git a/crm_drag_back_permission/static/src/js/hide_stage.js b/crm_drag_back_permission/static/src/js/hide_stage.js new file mode 100644 index 000000000..66ba8c346 --- /dev/null +++ b/crm_drag_back_permission/static/src/js/hide_stage.js @@ -0,0 +1,19 @@ +odoo.define('crm_drag_back_permission',function(require) { + +var kanbanview = require('web_kanban.KanbanView'); +var Model = require('web.Model'); +kanbanview.include({ +render: function () { + this._super(this); + + for (var key in this.widgets) { + + if (this.widgets[key]['title'] == 'Waiting for approval'){ + var test = this.widgets[key].$el + test.css("display", "None"); + } + + } + }, +}); +}); \ No newline at end of file diff --git a/crm_drag_back_permission/views/crm_lead_update.xml b/crm_drag_back_permission/views/crm_lead_update.xml new file mode 100644 index 000000000..f132b55b3 --- /dev/null +++ b/crm_drag_back_permission/views/crm_lead_update.xml @@ -0,0 +1,116 @@ + + + + + Leads updated + crm.lead + + + + + + + + + 1 + + + +