-
-
Notifications
You must be signed in to change notification settings - Fork 411
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
05c7d54
commit 7fe7e25
Showing
12 changed files
with
253 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import models | ||
from . import wizard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright 2024 INVITU SARL | ||
# License AGPL-3 or later (https://www.gnu.org/licenses/agpl.html). | ||
{ | ||
"name": "CRM Lead Approval", | ||
"summary": "This module allows to approve or not a lead.", | ||
"version": "17.0.1.0.0", | ||
"author": "INVITU SARL, Odoo Community Association (OCA)", | ||
"license": "AGPL-3", | ||
"website": "https://github.com/OCA/crm", | ||
"depends": [ | ||
"crm", | ||
], | ||
"data": [ | ||
"security/ir.model.access.csv", | ||
"views/res_config_settings.xml", | ||
"views/crm_lead_views.xml", | ||
"wizard/approval_wizard_views.xml", | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from . import crm_lead | ||
from . import res_config_settings | ||
from . import res_company |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from odoo import fields, models | ||
|
||
|
||
class CrmLead(models.Model): | ||
_inherit = "crm.lead" | ||
_description = "Crm leads approval" | ||
|
||
approval = fields.Selection( | ||
[ | ||
("none", "None"), | ||
("done", "Approve"), | ||
("normal", "Reserved"), | ||
("blocked", "Disapprove"), | ||
], | ||
default="none", | ||
tracking=True, | ||
) | ||
approval_comment = fields.Text(string="Observation", tracking=True) | ||
to_be_approved = fields.Boolean( | ||
string="To be approved", compute="_compute_approve", help="Help note" | ||
) | ||
|
||
def _compute_approve(self): | ||
for record in self: | ||
record.to_be_approved = ( | ||
record.team_id in self.env.company.approval_team_ids | ||
or record.tag_ids in self.env.company.approval_tag_ids | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from odoo import fields, models | ||
|
||
|
||
class ResCompany(models.Model): | ||
_inherit = "res.company" | ||
|
||
approval_team_ids = fields.Many2many("crm.team", string="Authorized Sales Teams") | ||
approval_tag_ids = fields.Many2many("crm.tag", string="Authorized Tags") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from odoo import fields, models | ||
|
||
|
||
class ResConfigSettings(models.TransientModel): | ||
_inherit = "res.config.settings" | ||
|
||
approval_team_ids = fields.Many2many( | ||
"crm.team", | ||
string="Authorized Sales Teams", | ||
readonly=False, | ||
related="company_id.approval_team_ids", | ||
) | ||
approval_tag_ids = fields.Many2many( | ||
"crm.tag", | ||
string="Authorized CRM Tags", | ||
readonly=False, | ||
related="company_id.approval_tag_ids", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink | ||
access_crm_approval_wizard,access_crm_approval_wizard,model_crm_approval_wizard,base.group_user,1,1,1,1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<odoo> | ||
<record id="view_crm_lead_form_approval" model="ir.ui.view"> | ||
<field name="name">view.crm.lead.form.approval</field> | ||
<field name="model">crm.lead</field> | ||
<field name="inherit_id" ref="crm.crm_lead_view_form" /> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//header" position="inside"> | ||
<field name="to_be_approved" invisible="1" /> | ||
<button | ||
name="%(action_crm_approval_wizard)d" | ||
string="Approve/Refuse" | ||
type="action" | ||
class="btn-primary" | ||
readonly="1" | ||
invisible="not to_be_approved or type == 'lead'" | ||
/> | ||
</xpath> | ||
<xpath expr="//sheet/field[@name='active']" position="after"> | ||
<field | ||
name="approval" | ||
widget="state_selection" | ||
readonly="1" | ||
invisible="not to_be_approved or type == 'lead'" | ||
/> | ||
</xpath> | ||
</field> | ||
</record> | ||
|
||
<record id="view_crm_lead_approval_kanban" model="ir.ui.view"> | ||
<field name="name">view.crm.lead.approval.kanban</field> | ||
<field name="model">crm.lead</field> | ||
<field name="inherit_id" ref="crm.crm_case_kanban_view_leads" /> | ||
<field name="priority" eval="100" /> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//div/field[@name='user_id']" position="after"> | ||
<field name="to_be_approved" invisible="1" /> | ||
<field | ||
name="approval" | ||
widget="state_selection" | ||
readonly="1" | ||
invisible="not to_be_approved" | ||
/> | ||
</xpath> | ||
</field> | ||
</record> | ||
|
||
<record id="view_crm_lead_tree_approval" model="ir.ui.view"> | ||
<field name="name">view.crm.lead.tree.approval</field> | ||
<field name="model">crm.lead</field> | ||
<field name="inherit_id" ref="crm.crm_case_tree_view_oppor" /> | ||
<field name="priority" eval="100" /> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//field[@name='name']" position="after"> | ||
<field name="to_be_approved" invisible="1" /> | ||
<field | ||
name="approval" | ||
optional="show" | ||
widget="state_selection" | ||
nolabel="1" | ||
readonly="1" | ||
width="40px" | ||
invisible="not to_be_approved" | ||
/> | ||
</xpath> | ||
</field> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<odoo> | ||
<record id="res_config_settings_approved_teams" model="ir.ui.view"> | ||
<field name="name">res.config.settings.view.approved.teams</field> | ||
<field name="model">res.config.settings</field> | ||
<field name="priority" eval="100" /> | ||
<field name="inherit_id" ref="base.res_config_settings_view_form" /> | ||
<field name="arch" type="xml"> | ||
<xpath | ||
expr="//block[@name='convert_visitor_setting_container']" | ||
position="before" | ||
> | ||
<block> | ||
<setting | ||
help="Approve Sales Teams to see the approval button in the lead." | ||
> | ||
<field name="approval_team_ids" widget="many2many_tags" /> | ||
</setting> | ||
<setting help="Approve CRM Tags"> | ||
<field name="approval_tag_ids" widget="many2many_tags" /> | ||
</setting> | ||
</block> | ||
</xpath> | ||
</field> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import approval_wizard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from markupsafe import Markup | ||
|
||
from odoo import fields, models | ||
from odoo.tools.mail import is_html_empty | ||
|
||
|
||
class CrmApprovalWizard(models.TransientModel): | ||
_name = "crm.approval.wizard" | ||
_description = "CRM Approval Wizard" | ||
|
||
lead_id = fields.Many2one("crm.lead", string="Lead", required=True) | ||
approval_comment = fields.Html(string="Observation", sanitize=True) | ||
|
||
def action_set_favorable(self): | ||
self._update_lead_approval("done") | ||
|
||
def action_set_reserve(self): | ||
self._update_lead_approval("normal") | ||
|
||
def action_set_defavorable(self): | ||
self._update_lead_approval("blocked") | ||
|
||
def _update_lead_approval(self, status): | ||
self.ensure_one() | ||
self.lead_id.approval = status | ||
if not is_html_empty(self.approval_comment): | ||
self.lead_id._track_set_log_message( | ||
Markup('<div style="margin-bottom: 4px;"><p>%s:</p>%s<br /></div>') | ||
% ("Observation", self.approval_comment) | ||
) | ||
return {"type": "ir.actions.act_window_close"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<odoo> | ||
<record id="view_crm_approval_wizard_form" model="ir.ui.view"> | ||
<field name="name">view.crm.approval.wizard.form</field> | ||
<field name="model">crm.approval.wizard</field> | ||
<field name="arch" type="xml"> | ||
<form string="Approval wizard"> | ||
<sheet> | ||
<group> | ||
<field name="lead_id" readonly="1" /> | ||
<field | ||
name="approval_comment" | ||
options="{'collaborative': true}" | ||
/> | ||
</group> | ||
</sheet> | ||
<footer> | ||
<button | ||
name="action_set_favorable" | ||
string="Approve" | ||
type="object" | ||
class="btn-success" | ||
/> | ||
<button | ||
name="action_set_reserve" | ||
string="Reserved" | ||
type="object" | ||
class="btn-primary" | ||
/> | ||
<button | ||
name="action_set_defavorable" | ||
string="Disapprove" | ||
type="object" | ||
class="btn-danger" | ||
/> | ||
<button string="Cancel" class="btn-secondary" special="cancel" /> | ||
</footer> | ||
</form> | ||
</field> | ||
</record> | ||
|
||
<record id="action_crm_approval_wizard" model="ir.actions.act_window"> | ||
<field name="name">Approval</field> | ||
<field name="res_model">crm.approval.wizard</field> | ||
<field name="view_mode">form</field> | ||
<field name="target">new</field> | ||
<field name="context">{'default_lead_id': active_id}</field> | ||
</record> | ||
</odoo> |