Browse Source

New CRM Addon

pull/81/head
SHEREEF PT 9 years ago
parent
commit
d4339b6b9d
  1. 2
      colour_code_project/__openerp__.py
  2. 2
      colour_code_project/__openerp__.py~
  3. 23
      crm_drag_back_permission/__init__.py
  4. 43
      crm_drag_back_permission/__openerp__.py
  5. 25
      crm_drag_back_permission/models/__init__.py
  6. 158
      crm_drag_back_permission/models/update_kanban_record.py
  7. 4
      crm_drag_back_permission/security/ir.model.access.csv
  8. BIN
      crm_drag_back_permission/static/description/banner.jpg
  9. BIN
      crm_drag_back_permission/static/description/icon.png
  10. BIN
      crm_drag_back_permission/static/description/image2.png
  11. BIN
      crm_drag_back_permission/static/description/image3.png
  12. BIN
      crm_drag_back_permission/static/description/image5.png
  13. 83
      crm_drag_back_permission/static/description/index.html
  14. 20
      crm_drag_back_permission/static/src/js/hide_stage.js
  15. 124
      crm_drag_back_permission/views/crm_lead_update.xml
  16. 21
      crm_drag_back_permission/views/crm_sales_team.xml
  17. 12
      crm_drag_back_permission/views/templates.xml

2
colour_code_project/__openerp__.py

@ -23,7 +23,7 @@
{
'name': "Automatic Colour Code for Task",
'summary': """Automatic Colour Code for Task Based on Project""",
'author': "Cybrosys Technologies",
'author': "Cybrosys Techno Solutions",
'website': "http://www.cybrosys.com",
'category': 'Project',
'version': '0.2',

2
colour_code_project/__openerp__.py~

@ -23,7 +23,7 @@
{
'name': "Automatic Colour Code for Task",
'summary': """Automatic Colour Code for Task Based on Project""",
'author': "Nilmar Shereef",
'author': "Cybrosys Technologies",
'website': "http://www.cybrosys.com",
'category': 'Project',
'version': '0.2',

23
crm_drag_back_permission/__init__.py

@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Cybrosys Technologies Pvt. Ltd.
# Copyright (C) 2009-TODAY Cybrosys Technologies(<http://www.cybrosys.com>).
# Author: Nilmar Shereef(<http://www.cybrosys.com>)
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
import models

43
crm_drag_back_permission/__openerp__.py

@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Cybrosys Technologies Pvt. Ltd.
# Copyright (C) 2009-TODAY Cybrosys Technologies(<http://www.cybrosys.com>).
# Author: Nilmar Shereef(<http://www.cybrosys.com>)
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'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,
}

25
crm_drag_back_permission/models/__init__.py

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Cybrosys Technologies Pvt. Ltd.
# Copyright (C) 2009-TODAY Cybrosys Technologies(<http://www.cybrosys.com>).
# Author: Nilmar Shereef(<http://www.cybrosys.com>)
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
import update_kanban_record

158
crm_drag_back_permission/models/update_kanban_record.py

@ -0,0 +1,158 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Cybrosys Technologies Pvt. Ltd.
# Copyright (C) 2009-TODAY Cybrosys Technologies(<http://www.cybrosys.com>).
# Author: Nilmar Shereef(<http://www.cybrosys.com>)
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp 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')
current_lead = fields.Boolean(string="current lead", compute='get_lead')
def on_change_user(self, cr, uid, ids, user_id, context=None):
""" When changing the user, also set a team_id or restrict team id
to the ones user_id is member of. """
if not context:
context = {}
if user_id and context.get('team_id'):
team = self.pool['crm.team'].browse(cr, uid, context['team_id'], context=context)
if user_id in team.member_ids.ids:
return {}
temp = self.pool['crm.team']._get_default_team_id(cr, uid, context=context, user_id=user_id)
u_id = self.pool.get('res.users').browse(cr, uid, [user_id], 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'):
team_id = temp
elif u_id.has_group('base.group_sale_salesman_all_leads') and u_id.has_group('base.group_sale_salesman'):
team_id = self.pool.get('crm.team').search(cr, uid, [('user_id.id', '=', user_id)], context=context, limit=1)[0]
elif u_id.has_group('base.group_sale_salesman'):
team_id = u_id.sale_team_id.id
return {'value': {'team_id': team_id}}
@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('base.group_sale_manager'):
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, cr, uid, context=None):
tree_res = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'crm',
'crm_case_tree_view_oppor')
x = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'crm_drag_back_permission', 'action_waiting_approval_window')
tree_id = tree_res and tree_res[1] or False
form_res = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'crm',
'crm_case_form_view_leads')
form_id = form_res and form_res[1] or False
approval_stage = self.pool.get('crm.lead')
approvals = approval_stage.search(cr, uid, [('stage_id.type', '=', "approval")])
user_obj = self.pool.get('res.users')
u_id = user_obj.browse(cr, uid, 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'):
object_list = approvals
elif u_id.has_group('base.group_sale_salesman_all_leads') and u_id.has_group('base.group_sale_salesman'):
teams = self.pool.get('crm.team').search(cr, uid, [('user_id.id', '=', uid)])
object_list = []
if approvals:
for obj in approvals:
if self.pool.get('crm.lead').browse(cr, uid, [obj]).team_id.id in teams:
object_list.append(obj)
elif u_id.has_group('base.group_sale_salesman'):
object_list = []
if approvals:
for obj in approvals:
if self.pool.get('crm.lead').browse(cr, uid, [obj]).user_id.id == uid:
object_list.append(obj)
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.")

4
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,base.group_sale_salesman,1,1,1,1
access_crm_stage_head,crm.stage,model_crm_stage,base.group_sale_salesman_all_leads,1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_crm_stage crm.stage model_crm_stage base.group_sale_salesman 1 1 1 1
3 access_crm_stage_head crm.stage model_crm_stage base.group_sale_salesman_all_leads 1 1 1 1

BIN
crm_drag_back_permission/static/description/banner.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 120 KiB

BIN
crm_drag_back_permission/static/description/icon.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

BIN
crm_drag_back_permission/static/description/image2.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

BIN
crm_drag_back_permission/static/description/image3.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

BIN
crm_drag_back_permission/static/description/image5.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

83
crm_drag_back_permission/static/description/index.html

@ -0,0 +1,83 @@
<section class="oe_container">
<div class="oe_row oe_spaced">
<h2 class="oe_slogan">CRM Kanban Drag Back</h2>
<h3 class="oe_slogan">Permission for Back Drag in CRM Kanban view</h3>
<h4 class="oe_slogan">Author : Cybrosys Techno Solutions , www.cybrosys.com</h4>
</div>
<div class="oe_row oe_spaced">
<div>
This module restricts some users to drag leads backwards in sales pipeline without permission.
</div>
</div>
<div class="oe_row oe_spaced">
<div class="oe_span12">
<div class="oe_demo oe_picture oe_screenshot">
<img src="image2.png">
</div>
</div>
<div class="oe_span12">
<p class='oe_mt32'>
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.
</p>
</div>
</div>
</section>
<section>
<div class="oe_row oe_spaced">
<div class="oe_span12">
<p class='oe_mt32'>
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.
</p>
<div class="oe_span12">
<div class="oe_demo oe_picture oe_screenshot">
<img src="image3.png">
</div>
</div>
</div>
</div>
</section>
<section>
<div class="oe_row oe_spaced">
<div class="oe_span12">
<p class='oe_mt32'>
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.
</p>
</div>
<div class="oe_span12">
<div class="oe_demo oe_picture oe_screenshot">
<img src="image5.png">
</div>
</div>
</div>
</section>
<section class="oe_container oe_dark">
<h2 class="oe_slogan">Need Any Help?</h2>
<div class="oe_slogan">
<a class="btn btn-primary btn-lg mt8"
style="color: #FFFFFF !important;" href="http://www.cybrosys.com"><i
class="fa fa-envelope"></i> Email </a> <a
class="btn btn-primary btn-lg mt8" style="color: #FFFFFF !important;"
href="http://www.cybrosys.com/contact/"><i
class="fa fa-phone"></i> Contact Us </a> <a
class="btn btn-primary btn-lg mt8" style="color: #FFFFFF !important;"
href="http://www.cybrosys.com/odoo-customization-and-installation/"><i
class="fa fa-check-square"></i> Request Customization </a>
</div>
</section>

20
crm_drag_back_permission/static/src/js/hide_stage.js

@ -0,0 +1,20 @@
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);
var self = 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");
}
}
},
});
});

124
crm_drag_back_permission/views/crm_lead_update.xml

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8" ?>
<openerp>
<data>
<record id="crm_case_form_view_lead_updated" model="ir.ui.view">
<field name="name">Leads updated</field>
<field name="model">crm.lead</field>
<field name="inherit_id" ref="crm.crm_case_form_view_leads" />
<field name="arch" type="xml">
<xpath expr="//field[@name='partner_id']" position="after">
<field name="stage_previous" invisible="1" />
<field name="stage_next" invisible="1" />
<field name="stage_type" invisible="1" />
</xpath>
<xpath expr="//field[@name='stage_id']" position="replace">
<field name="stage_id" widget="statusbar" clickable="True"
options="{'fold_field': 'fold'}"
domain="['&amp;', ('team_ids', '=', team_id), '|', ('type', '=', type), ('type', '=', 'both')]"
attrs="{'invisible': [('stage_type','=','approval')]}"/>
</xpath>
<xpath expr="//form/header" position="inside">
<button name="approve_oppor" string="Approve" groups="base.group_sale_manager,base.group_sale_salesman_all_leads"
type="object" class="oe_highlight o_wow" attrs="{'invisible': [('stage_type','!=','approval')]}"/>
<button name="decline_oppor" string="Decline" groups="base.group_sale_manager,base.group_sale_salesman_all_leads"
type="object" class="oe_highlight o_wow" attrs="{'invisible': [('stage_type','!=','approval')]}"/>
</xpath>
<xpath expr="//form/header/button[1]" position="attributes">
<attribute name="attrs">{'invisible': [('stage_type','=','approval')]}</attribute>
</xpath><xpath expr="//form/header/button[2]" position="attributes">
<attribute name="attrs">{'invisible': [('stage_type','=','approval')]}</attribute>
</xpath>
<xpath expr="//group[1]/group[2]" position="before">
<group>
<field name="previous" />
<field name="next_stage"/>
</group>
</xpath>
<xpath expr="//field[@name='team_id']" position="replace">
<field name="team_id" widget="selection" />
</xpath>
</field>
</record>
<record id="crm_case_form_view_opport_updated" model="ir.ui.view">
<field name="name">Opportunity updated</field>
<field name="model">crm.lead</field>
<field name="inherit_id" ref="crm.crm_case_form_view_oppor" />
<field name="arch" type="xml">
<xpath expr="//field[@name='partner_id']" position="after">
<field name="stage_previous" invisible="1" />
<field name="stage_next" invisible="1" />
<field name="stage_type" invisible="1" />
</xpath>
<xpath expr="//field[@name='user_id']" position="attributes">
<attribute name="required">1</attribute>
</xpath>
<xpath expr="//field[@name='stage_id']" position="replace">
<field name="stage_id" widget="statusbar" clickable="True"
options="{'fold_field': 'fold'}"
domain="['&amp;', ('team_ids', '=', team_id), '|', ('type', '=', type), ('type', '=', 'both')]"
attrs="{'invisible': [('stage_type','=','approval')]}"/>
</xpath>
<xpath expr="//form/header" position="inside">
<button name="approve_oppor" string="Approve" groups="base.group_sale_manager,base.group_sale_salesman_all_leads"
type="object" class="oe_highlight o_wow" attrs="{'invisible': [('stage_type','!=','approval')]}"/>
<button name="decline_oppor" string="Decline" groups="base.group_sale_manager,base.group_sale_salesman_all_leads"
type="object" class="oe_highlight o_wow" attrs="{'invisible': [('stage_type','!=','approval')]}" />
</xpath>
<xpath expr="//form/header/button[1]" position="attributes">
<attribute name="attrs">{'invisible': [('stage_type','=','approval')]}</attribute>
</xpath><xpath expr="//form/header/button[2]" position="attributes">
<attribute name="attrs">{'invisible': [('stage_type','=','approval')]}</attribute>
</xpath>
<xpath expr="//group[1]/group[2]" position="before">
<group>
<field name="previous" />
<field name="next_stage"/>
</group>
</xpath>
<xpath expr="//field[@name='team_id']" position="replace">
<field name="team_id" widget="selection" />
</xpath>
</field>
</record>
<record id="crm_case_stage_updated" model="ir.ui.view">
<field name="name">Stages Updated</field>
<field name="model">crm.stage</field>
<field name="inherit_id" ref="crm.crm_stage_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='on_change']" position="after">
<field name="stage_order" />
</xpath>
</field>
</record>
<record id="action_waiting_approval_window" model="ir.actions.act_window">
<field name="name">Waiting</field>
<field name="res_model">crm.lead</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>
<record id="action_waiting_approval" model="ir.actions.server">
<field name="name">Waiting</field>
<field name="type">ir.actions.server</field>
<field name="res_model">crm.lead</field>
<field name="model_id" ref="model_crm_lead"/>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="state">code</field>
<field name="code">action = self.get_approvals(cr, uid, context=context)</field>
</record>
<menuitem name="Waiting for approval" id="waiting_approval" action="action_waiting_approval" parent="base.menu_sales" />
</data>
</openerp>

21
crm_drag_back_permission/views/crm_sales_team.xml

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="base.group_sale_manager" model="res.groups">
<field name="name">CEO/Head of Business strategy</field>
<field name="implied_ids" eval="[(4, ref('base.group_sale_salesman'))]"/>
</record>
<record id="base.group_sale_salesman_all_leads" model="res.groups">
<field name="name">Head Of Sales</field>
<field name="category_id" ref="base.module_category_sales_management"/>
<field name="implied_ids" eval="[(4, ref('base.group_sale_salesman'))]"/>
<field name="comment">the user will have access to all records of everyone in the sales application.</field>
</record>
<record id="base.group_sale_salesman" model="res.groups">
<field name="name">SalesPerson</field>
<field name="category_id" ref="base.module_category_sales_management"/>
<field name="implied_ids" eval="[(4, ref('base.group_user'))]"/>
<field name="comment">the user will have access to his own data in the sales application.</field>
</record>
</data>
</openerp>

12
crm_drag_back_permission/views/templates.xml

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="assets_backend" name="hide_stage_kanban" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/crm_drag_back_permission/static/src/js/hide_stage.js"></script>
</xpath>
</template>
</data>
</openerp>
Loading…
Cancel
Save