Merge branch 'develop' into 'main'
feat: Добавлен модуль CRM See merge request productteam/talismanplatform/modules/odoo_17.0.1/crm!1
This commit is contained in:
commit
70240a47fd
128
README.md
128
README.md
|
@ -1,93 +1,97 @@
|
|||
# crm
|
||||
Odoo CRM
|
||||
--------
|
||||
|
||||
Boost sales productivity, improve win rates, grow revenue with the Odoo
|
||||
<a href="https://www.odoo.com/app/crm">Open Source CRM</a>.
|
||||
|
||||
Manage your sales funnel with no effort. Attract leads, follow-up on phone
|
||||
calls and meetings. Analyse the quality of your leads to make informed
|
||||
decisions and save time by integrating emails directly into the application.
|
||||
|
||||
## Getting started
|
||||
Your Sales Funnel, The Way You Like It
|
||||
--------------------------------------
|
||||
|
||||
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
|
||||
Track your opportunities pipeline with the revolutionary kanban view. Work
|
||||
inside your sales funnel and get instant visual information about next actions,
|
||||
new messages, top opportunities and expected revenues.
|
||||
|
||||
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
|
||||
Lead Management Made Easy
|
||||
-------------------------
|
||||
|
||||
## Add your files
|
||||
Create leads automatically from incoming emails. Analyse leads efficiency and
|
||||
compare performance by campaigns, channels or Sales Team.
|
||||
|
||||
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
|
||||
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
|
||||
Find duplicates, merge leads and assign them to the right salesperson in one
|
||||
operation. Spend less time on administration and more time on qualifying leads.
|
||||
|
||||
```
|
||||
cd existing_repo
|
||||
git remote add origin https://gitlab.ispras.ru/productteam/talismanplatform/modules/odoo_17.0.1/crm.git
|
||||
git branch -M main
|
||||
git push -uf origin main
|
||||
```
|
||||
Organize Your Opportunities
|
||||
---------------------------
|
||||
|
||||
## Integrate with your tools
|
||||
Get your opportunities organized to stay focused on the best deals. Manage all
|
||||
your customer interactions from the opportunity like emails, phone calls,
|
||||
internal notes, meetings and quotations.
|
||||
|
||||
- [ ] [Set up project integrations](https://gitlab.ispras.ru/productteam/talismanplatform/modules/odoo_17.0.1/crm/-/settings/integrations)
|
||||
Follow opportunities that interest you to get notified upon specific events:
|
||||
deal won or lost, stage changed, new customer demand, etc.
|
||||
|
||||
## Collaborate with your team
|
||||
Email Integration and Automation
|
||||
--------------------------------
|
||||
|
||||
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
|
||||
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
|
||||
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
|
||||
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
|
||||
- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
|
||||
Work with the email applications you already use every day. Whether your
|
||||
company uses Microsoft Outlook or Gmail, no one needs to change the way they
|
||||
work, so everyone stays productive.
|
||||
|
||||
## Test and Deploy
|
||||
Route, sort and filter incoming emails automatically. Odoo CRM handles incoming
|
||||
emails and route them to the right opportunities or Sales Team. New leads are
|
||||
created on the fly and interested salespersons are notified automatically.
|
||||
|
||||
Use the built-in continuous integration in GitLab.
|
||||
Collaborative Agenda
|
||||
--------------------
|
||||
|
||||
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
|
||||
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
|
||||
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
|
||||
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
|
||||
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
|
||||
Schedule your meetings and phone calls using the integrated calendar. You can
|
||||
see your agenda and your colleagues' in one view. As a manager, it's easy to
|
||||
see what your team is busy with.
|
||||
|
||||
***
|
||||
Lead Automation and Marketing Campaigns
|
||||
---------------------------------------
|
||||
|
||||
# Editing this README
|
||||
Drive performance by automating tasks with Odoo <a href="https://www.odoo.com/app/crm">CRM</a>.
|
||||
|
||||
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
|
||||
Use our marketing campaigns to automate lead acquisition, follow ups and
|
||||
promotions. Define automation rules (e.g. ask a salesperson to call, send an
|
||||
email, ...) based on triggers (no activity since 20 days, answered a
|
||||
promotional email, etc.)
|
||||
|
||||
## Suggestions for a good README
|
||||
Optimize campaigns from lead to close, on every channel. Make smarter decisions
|
||||
about where to invest and show the impact of your marketing activities on your
|
||||
company's bottom line.
|
||||
|
||||
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
|
||||
Customize Your Sales Cycle
|
||||
--------------------------
|
||||
|
||||
## Name
|
||||
Choose a self-explaining name for your project.
|
||||
Customize your sales cycle by configuring sales stages that perfectly fit your
|
||||
sales approach. Control statistics to get accurate forecasts to improve your
|
||||
sales performance at every stage of your customer relationship.
|
||||
|
||||
## Description
|
||||
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
|
||||
Drive Engagement with Gamification
|
||||
----------------------------------
|
||||
|
||||
## Badges
|
||||
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
|
||||
### Leverage your team's natural desire for competition
|
||||
|
||||
## Visuals
|
||||
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
|
||||
Reinforce good habits and improve win rates with real-time recognition and
|
||||
rewards inspired by [game mechanics](http://en.wikipedia.org/wiki/Gamification).
|
||||
Align Sales Teams around clear business objectives with challenges, personal
|
||||
objectives and team leader boards.
|
||||
|
||||
## Installation
|
||||
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
|
||||
### Leaderboards
|
||||
|
||||
## Usage
|
||||
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
|
||||
Promote leaders and competition amongst Sales Team with performance ratios.
|
||||
|
||||
## Support
|
||||
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
|
||||
### Personal Objectives
|
||||
|
||||
## Roadmap
|
||||
If you have ideas for releases in the future, it is a good idea to list them in the README.
|
||||
Assign clear goals to users to align them with the company objectives.
|
||||
|
||||
## Contributing
|
||||
State if you are open to contributions and what your requirements are for accepting them.
|
||||
### Team Targets
|
||||
|
||||
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
|
||||
Compare revenues with forecasts and budgets in real time.
|
||||
|
||||
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
|
||||
|
||||
## Authors and acknowledgment
|
||||
Show your appreciation to those who have contributed to the project.
|
||||
|
||||
## License
|
||||
For open source projects, say how it is licensed.
|
||||
|
||||
## Project status
|
||||
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
|
||||
|
|
8
__init__.py
Normal file
8
__init__.py
Normal file
|
@ -0,0 +1,8 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import controllers
|
||||
from . import models
|
||||
from . import populate
|
||||
from . import report
|
||||
from . import wizard
|
85
__manifest__.py
Normal file
85
__manifest__.py
Normal file
|
@ -0,0 +1,85 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
|
||||
{
|
||||
'name': 'CRM',
|
||||
'version': '1.8',
|
||||
'category': 'Sales/CRM',
|
||||
'sequence': 15,
|
||||
'summary': 'Track leads and close opportunities',
|
||||
'website': 'https://www.odoo.com/app/crm',
|
||||
'depends': [
|
||||
'base_setup',
|
||||
'sales_team',
|
||||
'mail',
|
||||
'calendar',
|
||||
'resource',
|
||||
'utm',
|
||||
'web_tour',
|
||||
'contacts',
|
||||
'digest',
|
||||
'phone_validation',
|
||||
],
|
||||
'data': [
|
||||
'security/crm_security.xml',
|
||||
'security/ir.model.access.csv',
|
||||
|
||||
'data/crm_lead_merge_template.xml',
|
||||
'data/crm_lead_prediction_data.xml',
|
||||
'data/crm_lost_reason_data.xml',
|
||||
'data/crm_stage_data.xml',
|
||||
'data/crm_team_data.xml',
|
||||
'data/digest_data.xml',
|
||||
'data/ir_action_data.xml',
|
||||
'data/ir_cron_data.xml',
|
||||
'data/mail_message_subtype_data.xml',
|
||||
'data/crm_recurring_plan_data.xml',
|
||||
|
||||
'wizard/crm_lead_lost_views.xml',
|
||||
'wizard/crm_lead_to_opportunity_views.xml',
|
||||
'wizard/crm_lead_to_opportunity_mass_views.xml',
|
||||
'wizard/crm_merge_opportunities_views.xml',
|
||||
'wizard/crm_lead_pls_update_views.xml',
|
||||
|
||||
'views/calendar_views.xml',
|
||||
'views/crm_recurring_plan_views.xml',
|
||||
'views/crm_lost_reason_views.xml',
|
||||
'views/crm_stage_views.xml',
|
||||
'views/crm_lead_views.xml',
|
||||
'views/crm_team_member_views.xml',
|
||||
'views/digest_views.xml',
|
||||
'views/mail_activity_plan_views.xml',
|
||||
'views/mail_activity_views.xml',
|
||||
'views/res_config_settings_views.xml',
|
||||
'views/res_partner_views.xml',
|
||||
'views/utm_campaign_views.xml',
|
||||
'report/crm_activity_report_views.xml',
|
||||
'report/crm_opportunity_report_views.xml',
|
||||
'views/crm_team_views.xml',
|
||||
'views/crm_menu_views.xml',
|
||||
'views/crm_helper_templates.xml',
|
||||
],
|
||||
'demo': [
|
||||
'data/crm_team_demo.xml',
|
||||
'data/mail_template_demo.xml',
|
||||
'data/crm_team_member_demo.xml',
|
||||
'data/mail_activity_type_demo.xml',
|
||||
'data/crm_lead_demo.xml',
|
||||
],
|
||||
'installable': True,
|
||||
'application': True,
|
||||
'assets': {
|
||||
'web.assets_backend': [
|
||||
'crm/static/src/**/*',
|
||||
],
|
||||
'web.assets_tests': [
|
||||
'crm/static/tests/tours/**/*',
|
||||
],
|
||||
'web.qunit_suite_tests': [
|
||||
'crm/static/tests/**/*',
|
||||
('remove', 'crm/static/tests/tours/**/*'),
|
||||
],
|
||||
},
|
||||
'license': 'LGPL-3',
|
||||
}
|
2
controllers/__init__.py
Normal file
2
controllers/__init__.py
Normal file
|
@ -0,0 +1,2 @@
|
|||
# -*- coding: utf-8 -*
|
||||
from . import main
|
45
controllers/main.py
Normal file
45
controllers/main.py
Normal file
|
@ -0,0 +1,45 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
import logging
|
||||
|
||||
from odoo.addons.mail.controllers.mail import MailController
|
||||
from odoo import http
|
||||
from odoo.http import request
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class CrmController(http.Controller):
|
||||
|
||||
@http.route('/lead/case_mark_won', type='http', auth='user', methods=['GET'])
|
||||
def crm_lead_case_mark_won(self, res_id, token):
|
||||
comparison, record, redirect = MailController._check_token_and_record_or_redirect('crm.lead', int(res_id), token)
|
||||
if comparison and record:
|
||||
try:
|
||||
record.action_set_won_rainbowman()
|
||||
except Exception:
|
||||
_logger.exception("Could not mark crm.lead as won")
|
||||
return MailController._redirect_to_messaging()
|
||||
return redirect
|
||||
|
||||
@http.route('/lead/case_mark_lost', type='http', auth='user', methods=['GET'])
|
||||
def crm_lead_case_mark_lost(self, res_id, token):
|
||||
comparison, record, redirect = MailController._check_token_and_record_or_redirect('crm.lead', int(res_id), token)
|
||||
if comparison and record:
|
||||
try:
|
||||
record.action_set_lost()
|
||||
except Exception:
|
||||
_logger.exception("Could not mark crm.lead as lost")
|
||||
return MailController._redirect_to_messaging()
|
||||
return redirect
|
||||
|
||||
@http.route('/lead/convert', type='http', auth='user', methods=['GET'])
|
||||
def crm_lead_convert(self, res_id, token):
|
||||
comparison, record, redirect = MailController._check_token_and_record_or_redirect('crm.lead', int(res_id), token)
|
||||
if comparison and record:
|
||||
try:
|
||||
record.convert_opportunity(record.partner_id)
|
||||
except Exception:
|
||||
_logger.exception("Could not convert crm.lead to opportunity")
|
||||
return MailController._redirect_to_messaging()
|
||||
return redirect
|
1310
data/crm_lead_demo.xml
Normal file
1310
data/crm_lead_demo.xml
Normal file
File diff suppressed because it is too large
Load Diff
182
data/crm_lead_merge_template.xml
Normal file
182
data/crm_lead_merge_template.xml
Normal file
|
@ -0,0 +1,182 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
<template id="crm_lead_merge_summary" name="crm_lead_merge_summary">
|
||||
<div class="crm_lead_merge_summary">
|
||||
<t t-foreach="opportunities" t-as="lead">
|
||||
<div>
|
||||
<span>Merged the Lead/Opportunity</span>
|
||||
<span class="fw-bold" t-field="lead.name"/>
|
||||
<span>into this one.</span>
|
||||
</div>
|
||||
<blockquote class="border-start" data-o-mail-quote="1">
|
||||
<div t-if="lead.expected_revenue">
|
||||
<span>Expected Revenues:</span>
|
||||
<span t-if="lead.expected_revenue">
|
||||
<span t-if="lead.company_currency" t-field="lead.expected_revenue"
|
||||
t-options='{"widget": "monetary", "display_currency": lead.company_currency}'/>
|
||||
<span t-else="" t-out="lead.expected_revenue"/>
|
||||
<span t-if="lead.recurring_revenue" groups="crm.group_use_recurring_revenues"> + </span>
|
||||
</span>
|
||||
<span t-if="lead.recurring_revenue" groups="crm.group_use_recurring_revenues">
|
||||
<span t-if="lead.company_currency" t-field="lead.recurring_revenue"
|
||||
t-options='{"widget": "monetary", "display_currency": lead.company_currency}'/>
|
||||
<span t-else="" t-out="lead.recurring_revenue"/>
|
||||
<span t-field="lead.recurring_plan.name"/>
|
||||
</span>
|
||||
</div>
|
||||
<div t-elif="lead.recurring_revenue" groups="crm.group_use_recurring_revenues">
|
||||
<span t-if="lead.company_currency" t-field="lead.recurring_revenue"
|
||||
t-options='{"widget": "monetary", "display_currency": lead.company_currency}'/>
|
||||
<span t-else="" t-out="lead.recurring_revenue"/>
|
||||
<span t-field="lead.recurring_plan.name"/>
|
||||
</div>
|
||||
<div t-if="lead.probability">
|
||||
Probability: <span t-field="lead.probability"/>%
|
||||
</div>
|
||||
<div>
|
||||
Type: <span t-field="lead.type"/>
|
||||
</div>
|
||||
<div t-if="lead.type != 'lead'">
|
||||
Stage: <span t-field="lead.stage_id"/>
|
||||
</div>
|
||||
<div t-if="lead.priority">
|
||||
Priority: <span t-field="lead.priority"/>
|
||||
</div>
|
||||
<div t-if="lead.lost_reason_id">
|
||||
Lost Reason: <span t-field="lead.lost_reason_id"/>
|
||||
</div>
|
||||
<div>
|
||||
Created on: <span t-field="lead.create_date"/>
|
||||
</div>
|
||||
<div t-if="lead.date_automation_last">
|
||||
Last Automation: <span t-field="lead.date_automation_last"/>
|
||||
</div>
|
||||
<div t-if="lead.date_deadline">
|
||||
Expected Closing: <span t-field="lead.date_deadline"/>
|
||||
</div>
|
||||
<div t-if="not is_html_empty(lead.description)">
|
||||
Notes: <span t-field="lead.description"/>
|
||||
</div>
|
||||
<div t-if="lead.lang_id" name="lang_id">
|
||||
Language: <span t-field="lead.lang_id"/>
|
||||
</div>
|
||||
<div t-if="lead.referred" name="referred">
|
||||
Referred By: <span t-field="lead.referred"/>
|
||||
</div>
|
||||
<div t-if="lead.tag_ids" name="tag_ids" class="d-flex flex-row">
|
||||
Tags:
|
||||
<div class="ms-2 d-flex flex-row">
|
||||
<div t-foreach="lead.tag_ids" t-as="tag" t-esc="tag.name"
|
||||
t-attf-class="badge rounded-pill o_tag o_tag_color_#{tag.color} d-inline-block"/>
|
||||
</div>
|
||||
</div>
|
||||
<div t-if="lead.user_id" class="mt-3">
|
||||
Salesperson: <span t-field="lead.user_id"/>
|
||||
</div>
|
||||
<div t-if="lead.team_id">
|
||||
Sales Team: <span t-field="lead.team_id"/>
|
||||
</div>
|
||||
<div name="company" groups="base.group_multi_company">
|
||||
Company: <span t-field="lead.company_id"/>
|
||||
</div>
|
||||
<div>
|
||||
<div class="mt-3"
|
||||
t-if="lead.contact_name or lead.partner_name or lead.phone or lead.mobile or lead.email_from or lead.website">
|
||||
<div class="fw-bold">
|
||||
Contact Details:
|
||||
</div>
|
||||
<div t-if="lead.contact_name">
|
||||
Contact: <span t-field="lead.contact_name"/>
|
||||
</div>
|
||||
<div t-if="lead.partner_name">
|
||||
Company Name: <span t-field="lead.partner_name"/>
|
||||
</div>
|
||||
<div t-if="lead.phone">
|
||||
Phone: <span t-field="lead.phone"/>
|
||||
</div>
|
||||
<div t-if="lead.mobile">
|
||||
Mobile: <span t-field="lead.mobile"/>
|
||||
</div>
|
||||
<div t-if="lead.email_from">
|
||||
Email: <span t-field="lead.email_from"/>
|
||||
</div>
|
||||
<div t-if="lead.email_cc">
|
||||
Email cc: <span t-field="lead.email_cc"/>
|
||||
</div>
|
||||
<div t-if="lead.website">
|
||||
Website: <span t-field="lead.website"/>
|
||||
</div>
|
||||
<div t-if="lead.function">
|
||||
Job Position: <span t-field="lead.function"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-3"
|
||||
t-if="lead.street or lead.street2 or lead.zip or lead.city or lead.state_id or lead.country_id"
|
||||
name="address">
|
||||
<div class="fw-bold">
|
||||
Address:
|
||||
</div>
|
||||
<div t-if="lead.street" t-field="lead.street"/>
|
||||
<div t-if="lead.street2" t-field="lead.street2"/>
|
||||
<div t-if="lead.zip" t-field="lead.zip"/>
|
||||
<div t-if="lead.city" t-field="lead.city"/>
|
||||
<div t-if="lead.state_id" t-field="lead.state_id"/>
|
||||
<div t-if="lead.country_id" t-field="lead.country_id"/>
|
||||
</div>
|
||||
<div class="mt-3" name="marketing"
|
||||
t-if="lead.campaign_id or lead.medium_id or lead.source_id">
|
||||
<div class="fw-bold">
|
||||
Marketing:
|
||||
</div>
|
||||
<div t-if="lead.campaign_id">
|
||||
Campaign: <span t-field="lead.campaign_id"/>
|
||||
</div>
|
||||
<div t-if="lead.medium_id">
|
||||
Medium: <span t-field="lead.medium_id"/>
|
||||
</div>
|
||||
<div t-if="lead.source_id">
|
||||
Source: <span t-field="lead.source_id"/>
|
||||
</div>
|
||||
</div>
|
||||
<t t-set="lead_followers" t-value="merged_followers and merged_followers.get(lead.id)"/>
|
||||
<div class="mt-3 mb-3" name="merged_followers" t-if="lead_followers">
|
||||
<div>
|
||||
The contacts below have been added as followers of this lead
|
||||
because they have been contacted less than 30 days ago on
|
||||
<span class="fw-bold" t-esc="lead.name"/>.
|
||||
</div>
|
||||
<ul>
|
||||
<li t-foreach="lead_followers" t-as="follower">
|
||||
<t t-esc="follower.partner_id.name"/>
|
||||
<t t-if="follower.partner_id.email">
|
||||
(<t t-esc="follower.partner_id.email"/>)
|
||||
</t>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<t t-set="properties" t-value="lead._format_properties()"/>
|
||||
<div t-if="properties" class="mt-3 mb-3">
|
||||
<div class="fw-bold">
|
||||
Properties
|
||||
</div>
|
||||
<ul class="p-0">
|
||||
<li t-foreach="properties" t-as="property"
|
||||
class="d-flex flex-row align-items-center">
|
||||
<t t-esc="property['label']"/>:
|
||||
<div t-if="'values' in property"
|
||||
class="ms-2 d-flex flex-row"> <!-- Tags -->
|
||||
<div t-foreach="property['values']" t-as="tag" t-esc="tag['name']"
|
||||
t-attf-class="badge rounded-pill o_tag o_tag_color_#{tag.get('color', 0)} d-inline-block me-2"/>
|
||||
</div>
|
||||
<div t-else="" class="ms-2" t-esc="property['value']"/>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</blockquote>
|
||||
</t>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
</odoo>
|
47
data/crm_lead_prediction_data.xml
Normal file
47
data/crm_lead_prediction_data.xml
Normal file
|
@ -0,0 +1,47 @@
|
|||
<?xml version="1.0" encoding='UTF-8'?>
|
||||
<odoo>
|
||||
<data noupdate="1">
|
||||
<!-- Lead scoring frequency fields -->
|
||||
<record id="frequency_field_state_id" model="crm.lead.scoring.frequency.field">
|
||||
<field name="field_id" ref="crm.field_crm_lead__state_id"/>
|
||||
</record>
|
||||
<record id="frequency_field_country_id" model="crm.lead.scoring.frequency.field">
|
||||
<field name="field_id" ref="crm.field_crm_lead__country_id"/>
|
||||
</record>
|
||||
<record id="frequency_field_phone_state" model="crm.lead.scoring.frequency.field">
|
||||
<field name="field_id" ref="crm.field_crm_lead__phone_state"/>
|
||||
</record>
|
||||
<record id="frequency_field_email_state" model="crm.lead.scoring.frequency.field">
|
||||
<field name="field_id" ref="crm.field_crm_lead__email_state"/>
|
||||
</record>
|
||||
<record id="frequency_field_source_id" model="crm.lead.scoring.frequency.field">
|
||||
<field name="field_id" ref="crm.field_crm_lead__source_id"/>
|
||||
</record>
|
||||
<record id="frequency_field_lang_id" model="crm.lead.scoring.frequency.field">
|
||||
<field name="field_id" ref="crm.field_crm_lead__lang_id"/>
|
||||
</record>
|
||||
<record id="frequency_field_tag_ids" model="crm.lead.scoring.frequency.field">
|
||||
<field name="field_id" ref="crm.field_crm_lead__tag_ids"/>
|
||||
</record>
|
||||
<record id="crm_pls_fields_param" model="ir.config_parameter">
|
||||
<field name="key">crm.pls_fields</field>
|
||||
<field name="value" eval="'phone_state,email_state'"/>
|
||||
</record>
|
||||
<record id="crm_pls_start_date_param" model="ir.config_parameter">
|
||||
<field name="key">crm.pls_start_date</field>
|
||||
<field name="value" eval="(datetime.now() - timedelta(days=8)).strftime('%Y-%m-%d')"/>
|
||||
</record>
|
||||
</data>
|
||||
|
||||
<record id="website_crm_score_cron" model="ir.cron">
|
||||
<field name="name">Predictive Lead Scoring: Recompute Automated Probabilities</field>
|
||||
<field name="model_id" ref="model_crm_lead"/>
|
||||
<field name="state">code</field>
|
||||
<field name="code">model._cron_update_automated_probabilities()</field>
|
||||
<field name="interval_number">1</field>
|
||||
<field name="interval_type">days</field>
|
||||
<field name="numbercall">-1</field>
|
||||
<field name="active" eval="False"/>
|
||||
<field name="doall" eval="False"/>
|
||||
</record>
|
||||
</odoo>
|
13
data/crm_lost_reason_data.xml
Normal file
13
data/crm_lost_reason_data.xml
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo><data noupdate="1">
|
||||
<!-- opportunities' lost causes -->
|
||||
<record id="lost_reason_1" model="crm.lost.reason">
|
||||
<field name="name">Too expensive</field>
|
||||
</record>
|
||||
<record id="lost_reason_2" model="crm.lost.reason">
|
||||
<field name="name">We don't have people/skills</field>
|
||||
</record>
|
||||
<record id="lost_reason_3" model="crm.lost.reason">
|
||||
<field name="name">Not enough stock</field>
|
||||
</record>
|
||||
</data></odoo>
|
24
data/crm_recurring_plan_data.xml
Normal file
24
data/crm_recurring_plan_data.xml
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo><data noupdate="1">
|
||||
|
||||
<record id="crm_recurring_plan_monthly" model="crm.recurring.plan">
|
||||
<field name="name">Monthly</field>
|
||||
<field name="number_of_months">1</field>
|
||||
</record>
|
||||
|
||||
<record id="crm_recurring_plan_yearly" model="crm.recurring.plan">
|
||||
<field name="name">Yearly</field>
|
||||
<field name="number_of_months">12</field>
|
||||
</record>
|
||||
|
||||
<record id="crm_recurring_plan_over_3_years" model="crm.recurring.plan">
|
||||
<field name="name">Over 3 years</field>
|
||||
<field name="number_of_months">36</field>
|
||||
</record>
|
||||
|
||||
<record id="crm_recurring_plan_over_5_years" model="crm.recurring.plan">
|
||||
<field name="name">Over 5 years </field>
|
||||
<field name="number_of_months">60</field>
|
||||
</record>
|
||||
|
||||
</data></odoo>
|
21
data/crm_stage_data.xml
Normal file
21
data/crm_stage_data.xml
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo noupdate="1">
|
||||
<record model="crm.stage" id="stage_lead1">
|
||||
<field name="name">New</field>
|
||||
<field name="sequence">1</field>
|
||||
</record>
|
||||
<record model="crm.stage" id="stage_lead2">
|
||||
<field name="name">Qualified</field>
|
||||
<field name="sequence">2</field>
|
||||
</record>
|
||||
<record model="crm.stage" id="stage_lead3">
|
||||
<field name="name">Proposition</field>
|
||||
<field name="sequence">3</field>
|
||||
</record>
|
||||
<record model="crm.stage" id="stage_lead4">
|
||||
<field name="name">Won</field>
|
||||
<field name="fold" eval="False"/>
|
||||
<field name="is_won">True</field>
|
||||
<field name="sequence">70</field>
|
||||
</record>
|
||||
</odoo>
|
18
data/crm_team_data.xml
Normal file
18
data/crm_team_data.xml
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo><data noupdate="1">
|
||||
<record id="sales_team.team_sales_department" model="crm.team" forcecreate="False">
|
||||
<field name="alias_name">info</field>
|
||||
</record>
|
||||
|
||||
<record id="sales_team.salesteam_website_sales" model="crm.team" forcecreate="False">
|
||||
<field name="use_opportunities" eval="False"/>
|
||||
</record>
|
||||
|
||||
<record id="sales_team.pos_sales_team" model="crm.team" forcecreate="False">
|
||||
<field name="use_opportunities" eval="False"/>
|
||||
</record>
|
||||
|
||||
<record id="sales_team.ebay_sales_team" model="crm.team" forcecreate="False">
|
||||
<field name="use_opportunities" eval="False"/>
|
||||
</record>
|
||||
</data></odoo>
|
13
data/crm_team_demo.xml
Normal file
13
data/crm_team_demo.xml
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<data noupdate="1">
|
||||
<record id="sales_team.team_sales_department" model="crm.team" forcecreate="False">
|
||||
<field name="assignment_domain">[['probability', '>=', '20']]</field>
|
||||
</record>
|
||||
|
||||
<record id="sales_team.crm_team_1" model="crm.team">
|
||||
<field name="use_leads">True</field>
|
||||
<field name="assignment_domain">[['phone', '!=', False]]</field>
|
||||
</record>
|
||||
</data>
|
||||
</odoo>
|
13
data/crm_team_member_demo.xml
Normal file
13
data/crm_team_member_demo.xml
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo><data noupdate="1">
|
||||
|
||||
<record id="sales_team.crm_team_member_admin_sales" model="crm.team.member">
|
||||
<field name="assignment_max">30</field>
|
||||
<field name="assignment_domain">[['probability', '>=', 20]]</field>
|
||||
</record>
|
||||
<record id="sales_team.crm_team_member_demo_team_1" model="crm.team.member">
|
||||
<field name="assignment_max">45</field>
|
||||
<field name="assignment_domain">[['probability', '>=', 5]]</field>
|
||||
</record>
|
||||
|
||||
</data></odoo>
|
90
data/digest_data.xml
Normal file
90
data/digest_data.xml
Normal file
|
@ -0,0 +1,90 @@
|
|||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<odoo>
|
||||
<data noupdate="1">
|
||||
<record id="digest.digest_digest_default" model="digest.digest">
|
||||
<field name="kpi_crm_lead_created">True</field>
|
||||
<field name="kpi_crm_opportunities_won">True</field>
|
||||
</record>
|
||||
</data>
|
||||
|
||||
<data>
|
||||
<record id="digest_tip_crm_0" model="digest.tip">
|
||||
<field name="name">Tip: Convert incoming emails into opportunities</field>
|
||||
<field name="sequence">200</field>
|
||||
<field name="group_id" ref="sales_team.group_sale_salesman_all_leads"/>
|
||||
<field name="tip_description" type="html">
|
||||
<div>
|
||||
<t t-set="record" t-value="object.env['crm.team'].search([('alias_name', '!=', 'False')], limit=1)" />
|
||||
<p class="tip_title">Tip: Convert incoming emails into opportunities</p>
|
||||
<t t-if="record.alias_email">
|
||||
<p class="tip_content">Did you know emails sent to <t t-out="record.alias_email"></t> generate opportunities in your pipeline?<br/>
|
||||
<a t-attf-href="mailto:{{record.alias_email}}" target="_blank">Try sending an email</a> to your CRM. This email address is configurable by sales team members.</p>
|
||||
</t>
|
||||
<t t-else="">
|
||||
<p class="tip_content">Did you know emails sent to a Sales Team alias generate opportunities in your pipeline?</p>
|
||||
</t>
|
||||
</div>
|
||||
</field>
|
||||
</record>
|
||||
<record id="digest_tip_crm_1" model="digest.tip">
|
||||
<field name="name">Tip: Did you know Odoo has built-in lead mining?</field>
|
||||
<field name="sequence">1500</field>
|
||||
<field name="group_id" ref="sales_team.group_sale_salesman_all_leads"/>
|
||||
<field name="tip_description" type="html">
|
||||
<div>
|
||||
<p class="tip_title">Tip: Did you know Odoo has built-in lead mining?</p>
|
||||
<p class="tip_content">For a sales team, there is nothing worse than being dry on leads. Fortunately, in just a few clicks, you can generate leads specifically targeted to your needs: company size, industry, etc. To help you test the feature, we offer you 200 credits for free.</p>
|
||||
<img src="https://download.odoocdn.com/digests/crm/static/src/img/milk-generate-leads.gif" width="540" class="illustration_border" />
|
||||
</div>
|
||||
</field>
|
||||
</record>
|
||||
<record id="digest_tip_crm_2" model="digest.tip">
|
||||
<field name="name">Tip: Opportunity win rate is predicted with AI</field>
|
||||
<field name="sequence">1700</field>
|
||||
<field name="group_id" ref="sales_team.group_sale_salesman_all_leads"/>
|
||||
<field name="tip_description" type="html">
|
||||
<div>
|
||||
<p class="tip_title">Tip: Opportunity win rate is predicted with AI</p>
|
||||
<p class="tip_content">Odoo's artificial intelligence engine predicts the success rate of each opportunity based on your history. You can always update the success rate manually, but if you let Odoo do the job the score is updated while the opportunity moves forward in your sales cycle.</p>
|
||||
<img src="https://download.odoocdn.com/digests/crm/static/src/img/milk-probability-rate.gif" width="540" class="illustration_border" />
|
||||
</div>
|
||||
</field>
|
||||
</record>
|
||||
<record id="digest_tip_crm_3" model="digest.tip">
|
||||
<field name="name">Tip: Manage your pipeline</field>
|
||||
<field name="sequence">2600</field>
|
||||
<field name="group_id" ref="sales_team.group_sale_salesman_all_leads"/>
|
||||
<field name="tip_description" type="html">
|
||||
<div>
|
||||
<p class="tip_title">Tip: Manage your pipeline</p>
|
||||
<p class="tip_content">A great tip to boost sales efficiency is to always define a next step on each opportunity. To manage ongoing activities, click on any status of the progress bar to filter opportunities based on their next activities' status. Click on the grey area of the progress bar to see all opportunities that have no next activity.</p>
|
||||
<img src="https://download.odoocdn.com/digests/crm/static/src/img/milk-pipeline-progress.gif" width="540" class="illustration_border" />
|
||||
</div>
|
||||
</field>
|
||||
</record>
|
||||
<record id="digest_tip_crm_4" model="digest.tip">
|
||||
<field name="name">Tip: Do not waste time recording customers' data</field>
|
||||
<field name="sequence">2800</field>
|
||||
<field name="group_id" ref="sales_team.group_sale_salesman_all_leads"/>
|
||||
<field name="tip_description" type="html">
|
||||
<div>
|
||||
<p class="tip_title">Tip: Do not waste time recording customers' data</p>
|
||||
<p class="tip_content">Did you know you can search a company by name or VAT number to instantly fill in all its data? Odoo autocompletes everything for you: logo, address, company size, business information, social media accounts, etc.</p>
|
||||
<img src="https://download.odoocdn.com/digests/crm/static/src/img/milk-autofill.gif" width="540" class="illustration_border" />
|
||||
</div>
|
||||
</field>
|
||||
</record>
|
||||
<record id="digest_tip_crm_5" model="digest.tip">
|
||||
<field name="name">Tip: Turn a selection of opportunities into a map</field>
|
||||
<field name="sequence">3000</field>
|
||||
<field name="group_id" ref="sales_team.group_sale_salesman_all_leads"/>
|
||||
<field name="tip_description" type="html">
|
||||
<div>
|
||||
<p class="tip_title">Tip: Turn a selection of opportunities into a map</p>
|
||||
<p class="tip_content">Did you know you can turn a list of opportunities into a map view, using the top-right map icon? A lot of screens in Odoo can be turned into a map: tasks, contacts, delivery orders, etc.</p>
|
||||
<img src="https://download.odoocdn.com/digests/crm/static/src/img/milk-mapview-toggle.gif" width="540" class="illustration_border" />
|
||||
</div>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
</odoo>
|
23
data/ir_action_data.xml
Normal file
23
data/ir_action_data.xml
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
<!--
|
||||
'Mark as Lost' in action dropdown
|
||||
-->
|
||||
<record id="action_your_pipeline" model="ir.actions.server">
|
||||
<field name="name">Crm: My Pipeline</field>
|
||||
<field name="model_id" ref="crm.model_crm_team"/>
|
||||
<field name="state">code</field>
|
||||
<field name="groups_id" eval="[(4, ref('base.group_user'))]"/>
|
||||
<field name="code">action = model.action_your_pipeline()</field>
|
||||
</record>
|
||||
|
||||
<record id="action_opportunity_forecast" model="ir.actions.server">
|
||||
<field name="name">Crm: Forecast</field>
|
||||
<field name="model_id" ref="crm.model_crm_team"/>
|
||||
<field name="state">code</field>
|
||||
<field name="groups_id" eval="[(4, ref('base.group_user'))]"/>
|
||||
<field name="code">action = model.action_opportunity_forecast()</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
15
data/ir_cron_data.xml
Normal file
15
data/ir_cron_data.xml
Normal file
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo><data noupdate="1">
|
||||
<record forcecreate="True" id="ir_cron_crm_lead_assign" model="ir.cron">
|
||||
<field name="name">CRM: Lead Assignment</field>
|
||||
<field name="model_id" ref="crm.model_crm_team"/>
|
||||
<field name="state">code</field>
|
||||
<field name="code">model._cron_assign_leads()</field>
|
||||
<field name="active" eval="False"/>
|
||||
<field name="user_id" ref="base.user_root"/>
|
||||
<field name="interval_number">1</field>
|
||||
<field name="interval_type">days</field>
|
||||
<field name="numbercall">-1</field>
|
||||
<field name="doall" eval="False"/>
|
||||
</record>
|
||||
</data></odoo>
|
30
data/mail_activity_type_demo.xml
Normal file
30
data/mail_activity_type_demo.xml
Normal file
|
@ -0,0 +1,30 @@
|
|||
<?xml version="1.0"?>
|
||||
<odoo>
|
||||
<record id="mail_activity_demo_followup_quote" model="mail.activity.type">
|
||||
<field name="name">Follow-up Quote</field>
|
||||
<field name="icon">fa-file-text-o</field>
|
||||
<field name="res_model">crm.lead</field>
|
||||
<field name="delay_count">30</field>
|
||||
</record>
|
||||
<record id="mail_activity_demo_make_quote" model="mail.activity.type">
|
||||
<field name="name">Make Quote</field>
|
||||
<field name="icon">fa-file-text-o</field>
|
||||
<field name="res_model">crm.lead</field>
|
||||
<field name="delay_count">15</field>
|
||||
</record>
|
||||
|
||||
<record id="mail_activity_demo_call_demo" model="mail.activity.type">
|
||||
<field name="name">Call for Demo</field>
|
||||
<field name="icon">fa-phone</field>
|
||||
<field name="res_model">crm.lead</field>
|
||||
<field name="delay_count">10</field>
|
||||
<field name="category">phonecall</field>
|
||||
</record>
|
||||
|
||||
<record id="mail_activity_type_demo_email_with_template" model="mail.activity.type">
|
||||
<field name="name">Email: Welcome Demo</field>
|
||||
<field name="icon">fa-envelope</field>
|
||||
<field name="res_model">crm.lead</field>
|
||||
<field name="mail_template_ids" eval="[(4, ref('crm.mail_template_demo_crm_lead'))]"/>
|
||||
</record>
|
||||
</odoo>
|
76
data/mail_message_subtype_data.xml
Normal file
76
data/mail_message_subtype_data.xml
Normal file
|
@ -0,0 +1,76 @@
|
|||
<?xml version="1.0"?>
|
||||
<odoo>
|
||||
<data noupdate="1">
|
||||
<!-- CRM-related subtypes for messaging / Chatter -->
|
||||
<record id="mt_lead_create" model="mail.message.subtype">
|
||||
<field name="name">Opportunity Created</field>
|
||||
<field name="hidden" eval="True"/>
|
||||
<field name="res_model">crm.lead</field>
|
||||
<field name="default" eval="False"/>
|
||||
<field name="description">Lead/Opportunity created</field>
|
||||
</record>
|
||||
<record id="mt_lead_stage" model="mail.message.subtype">
|
||||
<field name="name">Stage Changed</field>
|
||||
<field name="res_model">crm.lead</field>
|
||||
<field name="default" eval="False"/>
|
||||
<field name="description">Stage changed</field>
|
||||
</record>
|
||||
<record id="mt_lead_won" model="mail.message.subtype">
|
||||
<field name="name">Opportunity Won</field>
|
||||
<field name="res_model">crm.lead</field>
|
||||
<field name="default" eval="False"/>
|
||||
<field name="description">Opportunity won</field>
|
||||
</record>
|
||||
<record id="mt_lead_lost" model="mail.message.subtype">
|
||||
<field name="name">Opportunity Lost</field>
|
||||
<field name="res_model">crm.lead</field>
|
||||
<field name="default" eval="False"/>
|
||||
<field name="description">Opportunity lost</field>
|
||||
</record>
|
||||
<record id="mt_lead_restored" model="mail.message.subtype">
|
||||
<field name="name">Opportunity Restored</field>
|
||||
<field name="res_model">crm.lead</field>
|
||||
<field name="default" eval="False"/>
|
||||
<field name="description">Opportunity restored</field>
|
||||
</record>
|
||||
<!-- Salesteam-related subtypes for messaging / Chatter -->
|
||||
<record id="mt_salesteam_lead" model="mail.message.subtype">
|
||||
<field name="name">Opportunity Created</field>
|
||||
<field name="sequence">10</field>
|
||||
<field name="res_model">crm.team</field>
|
||||
<field name="default" eval="True"/>
|
||||
<field name="parent_id" ref="mt_lead_create"/>
|
||||
<field name="relation_field">team_id</field>
|
||||
</record>
|
||||
<record id="mt_salesteam_lead_stage" model="mail.message.subtype">
|
||||
<field name="name">Opportunity Stage Changed</field>
|
||||
<field name="sequence">11</field>
|
||||
<field name="res_model">crm.team</field>
|
||||
<field name="parent_id" ref="mt_lead_stage"/>
|
||||
<field name="relation_field">team_id</field>
|
||||
</record>
|
||||
<record id="mt_salesteam_lead_won" model="mail.message.subtype">
|
||||
<field name="name">Opportunity Won</field>
|
||||
<field name="sequence">12</field>
|
||||
<field name="res_model">crm.team</field>
|
||||
<field name="parent_id" ref="mt_lead_won"/>
|
||||
<field name="relation_field">team_id</field>
|
||||
</record>
|
||||
<record id="mt_salesteam_lead_lost" model="mail.message.subtype">
|
||||
<field name="name">Opportunity Lost</field>
|
||||
<field name="sequence">13</field>
|
||||
<field name="res_model">crm.team</field>
|
||||
<field name="default" eval="False"/>
|
||||
<field name="parent_id" ref="mt_lead_lost"/>
|
||||
<field name="relation_field">team_id</field>
|
||||
</record>
|
||||
<record id="mt_salesteam_lead_restored" model="mail.message.subtype">
|
||||
<field name="name">Opportunity Restored</field>
|
||||
<field name="sequence">14</field>
|
||||
<field name="res_model">crm.team</field>
|
||||
<field name="default" eval="False"/>
|
||||
<field name="parent_id" ref="mt_lead_restored"/>
|
||||
<field name="relation_field">team_id</field>
|
||||
</record>
|
||||
</data>
|
||||
</odoo>
|
84
data/mail_template_demo.xml
Normal file
84
data/mail_template_demo.xml
Normal file
|
@ -0,0 +1,84 @@
|
|||
<?xml version="1.0"?>
|
||||
<odoo><data noupdate="1">
|
||||
|
||||
<record id="mail_template_demo_crm_lead" model="mail.template">
|
||||
<field name="name">Welcome Demo</field>
|
||||
<field name="model_id" ref="crm.model_crm_lead"/>
|
||||
<field name="partner_to">{{ object.partner_id != False and object.partner_id.id }}</field>
|
||||
<field name="email_to">{{ (not object.partner_id and object.email_from) }}</field>
|
||||
<field name="body_html" type="html">
|
||||
<table border="0" cellpadding="0" cellspacing="0" style="padding-top: 16px; background-color: #F1F1F1; font-family:Verdana, Arial,sans-serif; color: #454748; width: 100%; border-collapse:separate;"><tr><td align="center">
|
||||
<table border="0" cellpadding="0" cellspacing="0" width="590" style="padding: 24px; background-color: white; color: #454748; border-collapse:separate;">
|
||||
<tbody>
|
||||
<!-- HEADER -->
|
||||
<tr>
|
||||
<td align="center" style="min-width: 590px;">
|
||||
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="background-color: white; padding: 0; border-collapse:separate;">
|
||||
<tr><td valign="middle">
|
||||
<span style="font-size: 10px;">Your Lead/Opportunity</span><br/>
|
||||
<span style="font-size: 20px; font-weight: bold;" t-out="object.name or ''">Interest in your products</span>
|
||||
</td><td valign="middle" align="right">
|
||||
<img t-attf-src="/logo.png?company={{ object.company_id.id }}" style="padding: 0px; margin: 0px; height: 48px;" t-att-alt="object.company_id.name"/>
|
||||
</td></tr>
|
||||
<tr><td colspan="2" style="text-align:center;">
|
||||
<hr width="100%" style="background-color:rgb(204,204,204);border:medium none;clear:both;display:block;font-size:0px;min-height:1px;line-height:0; margin:4px 0px 32px 0px;"/>
|
||||
</td></tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<!-- CONTENT -->
|
||||
<tr>
|
||||
<td style="min-width: 590px;">
|
||||
<table border="0" cellpadding="0" cellspacing="0" width="590" style="min-width: 590px; background-color: white; padding: 0px 8px 0px 8px; border-collapse:separate;">
|
||||
<tr>
|
||||
<td valign="top" style="font-size: 13px;">
|
||||
<div>
|
||||
Hi <t t-out="object.partner_id and object.partner_id.name or ''">Deco Addict</t>,<br/><br/>
|
||||
Welcome to <t t-out="object.company_id.name or ''">My Company (San Francisco)</t>.
|
||||
It's great to meet you! Now that you're on board, you'll discover what <t t-out="object.company_id.name or ''">My Company (San Francisco)</t> has to offer. My name is <t t-out="object.user_id.name or ''">Marc Demo</t> and I'll help you get the most out of Odoo. Could we plan a quick demo soon?<br/>
|
||||
Feel free to reach out at any time!<br/><br/>
|
||||
Best,<br/>
|
||||
<t t-if="object.user_id">
|
||||
<b><t t-out="object.user_id.name or ''">Marc Demo</t></b>
|
||||
<br/>Email: <t t-out="object.user_id.email or ''">mark.brown23@example.com</t>
|
||||
<br/>Phone: <t t-out="object.user_id.phone or ''">+1 650-123-4567</t>
|
||||
</t>
|
||||
<t t-else="">
|
||||
<t t-out="object.company_id.name or ''">My Company (San Francisco)</t>
|
||||
</t>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<!-- FOOTER -->
|
||||
<tr>
|
||||
<td align="center" style="min-width: 590px; padding: 0 8px 0 8px; font-size:11px;">
|
||||
<hr width="100%" style="background-color:rgb(204,204,204);border:medium none;clear:both;display:block;font-size:0px;min-height:1px;line-height:0; margin: 16px 0px 4px 0px;"/>
|
||||
<b t-out="object.company_id.name or ''">My Company (San Francisco)</b><br/>
|
||||
<div style="color: #999999;">
|
||||
<t t-out="object.company_id.phone or ''">+1 650-123-4567</t>
|
||||
<t t-if="object.company_id.email">
|
||||
| <a t-attf-href="'mailto:%s' % {{ object.company_id.email }}" style="text-decoration:none; color: #999999;" t-out="object.company_id.email or ''">info@yourcompany.com</a>
|
||||
</t>
|
||||
<t t-if="object.company_id.website">
|
||||
| <a t-attf-href="'%s' % {{ object.company_id.website }}" style="text-decoration:none; color: #999999;" t-out="object.company_id.website or ''">http://www.example.com</a>
|
||||
</t>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</td></tr>
|
||||
<!-- POWERED BY -->
|
||||
<tr><td align="center" style="min-width: 590px;">
|
||||
Powered by <a target="_blank" href="https://www.odoo.com?utm_source=db&utm_medium=email" style="color: #875A7B;">Odoo</a>
|
||||
</td></tr>
|
||||
</table>
|
||||
</field>
|
||||
<field name="lang">{{ object.partner_id.lang }}</field>
|
||||
<field name="auto_delete" eval="True"/>
|
||||
</record>
|
||||
|
||||
</data></odoo>
|
17
doc/changelog.rst
Normal file
17
doc/changelog.rst
Normal file
|
@ -0,0 +1,17 @@
|
|||
.. _changelog:
|
||||
|
||||
Changelog
|
||||
=========
|
||||
|
||||
`trunk (saas-2)`
|
||||
----------------
|
||||
|
||||
- Stage/state update
|
||||
|
||||
- ``crm.lead``: removed ``state`` field. Added ``date_last_stage_update`` field
|
||||
holding last stage_id modification. Updated reports.
|
||||
- ``crm.case.stage``: removed ``state`` field.
|
||||
|
||||
- ``crm``, ``crm_claim``: removed inheritance from ``base_stage`` class. Missing
|
||||
methods have been added into ``crm`` and ``crm_claim``. Also removed inheritance
|
||||
in ``crm_helpdesk`` because it uses states, not stages.
|
18
doc/index.rst
Normal file
18
doc/index.rst
Normal file
|
@ -0,0 +1,18 @@
|
|||
CRM module documentation
|
||||
========================
|
||||
|
||||
CRM documentation topics
|
||||
'''''''''''''''''''''''''
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
stage_status.rst
|
||||
|
||||
Changelog
|
||||
'''''''''
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
changelog.rst
|
61
doc/stage_status.rst
Normal file
61
doc/stage_status.rst
Normal file
|
@ -0,0 +1,61 @@
|
|||
.. _stage_status:
|
||||
|
||||
Stage and Status
|
||||
================
|
||||
|
||||
.. versionchanged:: 8.0 saas-2 state/stage cleaning
|
||||
|
||||
Stage
|
||||
+++++
|
||||
|
||||
This revision removed the concept of state on crm.lead objects. The ``state``
|
||||
field has been totally removed and replaced by stages, using ``stage_id``. The
|
||||
following models are impacted:
|
||||
|
||||
- ``crm.lead`` now use only stages. However conventions still exist about
|
||||
'New', 'Won' and 'Lost' stages. Those conventions are:
|
||||
|
||||
- ``new``: ``stage_id and stage_id.sequence = 1``
|
||||
- ``won``: ``stage_id and stage_id.probability = 100 and stage_id.on_change = True``
|
||||
- ``lost``: ``stage_id and stage_id.probability = 0 and stage_id.on_change = True
|
||||
and stage_id.sequence != 1``
|
||||
|
||||
- ``crm.case.stage`` do not have any ``state`` field anymore.
|
||||
- ``crm.lead.report`` do not have any ``state`` field anymore.
|
||||
|
||||
By default a newly created lead is in a new stage. It means that it will
|
||||
fetch the stage having ``sequence = 1``. Stage mangement is done using the
|
||||
kanban view or the clikable statusbar. It is not done using buttons anymore.
|
||||
|
||||
Stage analysis
|
||||
++++++++++++++
|
||||
|
||||
Stage analysis can be performed using the newly introduced ``date_last_stage_update``
|
||||
datetime field. This field is updated everytime ``stage_id`` is updated.
|
||||
|
||||
``crm.lead.report`` model also uses the ``date_last_stage_update`` field.
|
||||
This allows to group and analyse the time spend in the various stages.
|
||||
|
||||
Open / Assignment date
|
||||
+++++++++++++++++++++++
|
||||
|
||||
The ``date_open`` field meaning has been updated. It is now set when the ``user_id``
|
||||
(responsible) is set. It is therefore the assignment date.
|
||||
|
||||
Subtypes
|
||||
++++++++
|
||||
|
||||
The following subtypes are triggered on ``crm.lead``:
|
||||
|
||||
- ``mt_lead_create``: new leads. Condition: ``obj.probability == 0 and obj.stage_id
|
||||
and obj.stage_id.sequence == 1``
|
||||
- ``mt_lead_stage``: stage changed. Condition: ``(obj.stage_id and obj.stage_id.sequence != 1)
|
||||
and obj.probability < 100``
|
||||
- ``mt_lead_won``: lead/oportunity is won. condition: `` obj.probability == 100
|
||||
and obj.stage_id and obj.stage_id.on_change``
|
||||
- ``mt_lead_lost``: lead/opportunity is lost. Condition: ``obj.probability == 0
|
||||
and obj.stage_id and obj.stage_id.sequence != 1'``
|
||||
|
||||
|
||||
Those subtypes are also available on the ``crm.case.section`` model and are used
|
||||
for the auto subscription.
|
3806
i18n/af.po
Normal file
3806
i18n/af.po
Normal file
File diff suppressed because it is too large
Load Diff
3802
i18n/am.po
Normal file
3802
i18n/am.po
Normal file
File diff suppressed because it is too large
Load Diff
4291
i18n/ar.po
Normal file
4291
i18n/ar.po
Normal file
File diff suppressed because it is too large
Load Diff
3826
i18n/az.po
Normal file
3826
i18n/az.po
Normal file
File diff suppressed because it is too large
Load Diff
4093
i18n/bg.po
Normal file
4093
i18n/bg.po
Normal file
File diff suppressed because it is too large
Load Diff
3807
i18n/bs.po
Normal file
3807
i18n/bs.po
Normal file
File diff suppressed because it is too large
Load Diff
4257
i18n/ca.po
Normal file
4257
i18n/ca.po
Normal file
File diff suppressed because it is too large
Load Diff
4005
i18n/crm.pot
Normal file
4005
i18n/crm.pot
Normal file
File diff suppressed because it is too large
Load Diff
4322
i18n/cs.po
Normal file
4322
i18n/cs.po
Normal file
File diff suppressed because it is too large
Load Diff
4170
i18n/da.po
Normal file
4170
i18n/da.po
Normal file
File diff suppressed because it is too large
Load Diff
4374
i18n/de.po
Normal file
4374
i18n/de.po
Normal file
File diff suppressed because it is too large
Load Diff
3821
i18n/el.po
Normal file
3821
i18n/el.po
Normal file
File diff suppressed because it is too large
Load Diff
4336
i18n/es.po
Normal file
4336
i18n/es.po
Normal file
File diff suppressed because it is too large
Load Diff
4333
i18n/es_419.po
Normal file
4333
i18n/es_419.po
Normal file
File diff suppressed because it is too large
Load Diff
3805
i18n/es_CL.po
Normal file
3805
i18n/es_CL.po
Normal file
File diff suppressed because it is too large
Load Diff
4306
i18n/et.po
Normal file
4306
i18n/et.po
Normal file
File diff suppressed because it is too large
Load Diff
3805
i18n/eu.po
Normal file
3805
i18n/eu.po
Normal file
File diff suppressed because it is too large
Load Diff
4214
i18n/fa.po
Normal file
4214
i18n/fa.po
Normal file
File diff suppressed because it is too large
Load Diff
4336
i18n/fi.po
Normal file
4336
i18n/fi.po
Normal file
File diff suppressed because it is too large
Load Diff
3805
i18n/fo.po
Normal file
3805
i18n/fo.po
Normal file
File diff suppressed because it is too large
Load Diff
4340
i18n/fr.po
Normal file
4340
i18n/fr.po
Normal file
File diff suppressed because it is too large
Load Diff
3805
i18n/fr_CA.po
Normal file
3805
i18n/fr_CA.po
Normal file
File diff suppressed because it is too large
Load Diff
3805
i18n/gl.po
Normal file
3805
i18n/gl.po
Normal file
File diff suppressed because it is too large
Load Diff
3811
i18n/gu.po
Normal file
3811
i18n/gu.po
Normal file
File diff suppressed because it is too large
Load Diff
4153
i18n/he.po
Normal file
4153
i18n/he.po
Normal file
File diff suppressed because it is too large
Load Diff
3851
i18n/hr.po
Normal file
3851
i18n/hr.po
Normal file
File diff suppressed because it is too large
Load Diff
4114
i18n/hu.po
Normal file
4114
i18n/hu.po
Normal file
File diff suppressed because it is too large
Load Diff
4005
i18n/hy.po
Normal file
4005
i18n/hy.po
Normal file
File diff suppressed because it is too large
Load Diff
4313
i18n/id.po
Normal file
4313
i18n/id.po
Normal file
File diff suppressed because it is too large
Load Diff
4010
i18n/is.po
Normal file
4010
i18n/is.po
Normal file
File diff suppressed because it is too large
Load Diff
4323
i18n/it.po
Normal file
4323
i18n/it.po
Normal file
File diff suppressed because it is too large
Load Diff
4150
i18n/ja.po
Normal file
4150
i18n/ja.po
Normal file
File diff suppressed because it is too large
Load Diff
3805
i18n/ka.po
Normal file
3805
i18n/ka.po
Normal file
File diff suppressed because it is too large
Load Diff
3805
i18n/kab.po
Normal file
3805
i18n/kab.po
Normal file
File diff suppressed because it is too large
Load Diff
3808
i18n/km.po
Normal file
3808
i18n/km.po
Normal file
File diff suppressed because it is too large
Load Diff
4169
i18n/ko.po
Normal file
4169
i18n/ko.po
Normal file
File diff suppressed because it is too large
Load Diff
3806
i18n/lb.po
Normal file
3806
i18n/lb.po
Normal file
File diff suppressed because it is too large
Load Diff
3805
i18n/lo.po
Normal file
3805
i18n/lo.po
Normal file
File diff suppressed because it is too large
Load Diff
4128
i18n/lt.po
Normal file
4128
i18n/lt.po
Normal file
File diff suppressed because it is too large
Load Diff
4088
i18n/lv.po
Normal file
4088
i18n/lv.po
Normal file
File diff suppressed because it is too large
Load Diff
3805
i18n/mk.po
Normal file
3805
i18n/mk.po
Normal file
File diff suppressed because it is too large
Load Diff
3838
i18n/mn.po
Normal file
3838
i18n/mn.po
Normal file
File diff suppressed because it is too large
Load Diff
4051
i18n/nb.po
Normal file
4051
i18n/nb.po
Normal file
File diff suppressed because it is too large
Load Diff
3802
i18n/ne.po
Normal file
3802
i18n/ne.po
Normal file
File diff suppressed because it is too large
Load Diff
4309
i18n/nl.po
Normal file
4309
i18n/nl.po
Normal file
File diff suppressed because it is too large
Load Diff
4240
i18n/pl.po
Normal file
4240
i18n/pl.po
Normal file
File diff suppressed because it is too large
Load Diff
4076
i18n/pt.po
Normal file
4076
i18n/pt.po
Normal file
File diff suppressed because it is too large
Load Diff
4323
i18n/pt_BR.po
Normal file
4323
i18n/pt_BR.po
Normal file
File diff suppressed because it is too large
Load Diff
4237
i18n/ro.po
Normal file
4237
i18n/ro.po
Normal file
File diff suppressed because it is too large
Load Diff
4332
i18n/ru.po
Normal file
4332
i18n/ru.po
Normal file
File diff suppressed because it is too large
Load Diff
4184
i18n/sk.po
Normal file
4184
i18n/sk.po
Normal file
File diff suppressed because it is too large
Load Diff
4272
i18n/sl.po
Normal file
4272
i18n/sl.po
Normal file
File diff suppressed because it is too large
Load Diff
3805
i18n/sq.po
Normal file
3805
i18n/sq.po
Normal file
File diff suppressed because it is too large
Load Diff
4288
i18n/sr.po
Normal file
4288
i18n/sr.po
Normal file
File diff suppressed because it is too large
Load Diff
3808
i18n/sr@latin.po
Normal file
3808
i18n/sr@latin.po
Normal file
File diff suppressed because it is too large
Load Diff
4328
i18n/sv.po
Normal file
4328
i18n/sv.po
Normal file
File diff suppressed because it is too large
Load Diff
4268
i18n/th.po
Normal file
4268
i18n/th.po
Normal file
File diff suppressed because it is too large
Load Diff
4292
i18n/tr.po
Normal file
4292
i18n/tr.po
Normal file
File diff suppressed because it is too large
Load Diff
4306
i18n/uk.po
Normal file
4306
i18n/uk.po
Normal file
File diff suppressed because it is too large
Load Diff
4297
i18n/vi.po
Normal file
4297
i18n/vi.po
Normal file
File diff suppressed because it is too large
Load Diff
4137
i18n/zh_CN.po
Normal file
4137
i18n/zh_CN.po
Normal file
File diff suppressed because it is too large
Load Diff
4134
i18n/zh_TW.po
Normal file
4134
i18n/zh_TW.po
Normal file
File diff suppressed because it is too large
Load Diff
18
models/__init__.py
Normal file
18
models/__init__.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import res_users
|
||||
from . import calendar
|
||||
from . import crm_lead
|
||||
from . import crm_lost_reason
|
||||
from . import crm_stage
|
||||
from . import crm_team
|
||||
from . import crm_team_member
|
||||
from . import ir_config_parameter
|
||||
from . import res_config_settings
|
||||
from . import res_partner
|
||||
from . import digest
|
||||
from . import crm_lead_scoring_frequency
|
||||
from . import utm
|
||||
from . import crm_recurring_plan
|
||||
from . import mail_activity
|
55
models/calendar.py
Normal file
55
models/calendar.py
Normal file
|
@ -0,0 +1,55 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class CalendarEvent(models.Model):
|
||||
_inherit = 'calendar.event'
|
||||
|
||||
@api.model
|
||||
def default_get(self, fields):
|
||||
if self.env.context.get('default_opportunity_id'):
|
||||
self = self.with_context(
|
||||
default_res_model_id=self.env.ref('crm.model_crm_lead').id,
|
||||
default_res_id=self.env.context['default_opportunity_id']
|
||||
)
|
||||
defaults = super(CalendarEvent, self).default_get(fields)
|
||||
|
||||
# sync res_model / res_id to opportunity id (aka creating meeting from lead chatter)
|
||||
if 'opportunity_id' not in defaults:
|
||||
if self._is_crm_lead(defaults, self.env.context):
|
||||
defaults['opportunity_id'] = defaults.get('res_id', False) or self.env.context.get('default_res_id', False)
|
||||
|
||||
return defaults
|
||||
|
||||
opportunity_id = fields.Many2one(
|
||||
'crm.lead', 'Opportunity', domain="[('type', '=', 'opportunity')]",
|
||||
index=True, ondelete='set null')
|
||||
|
||||
def _compute_is_highlighted(self):
|
||||
super(CalendarEvent, self)._compute_is_highlighted()
|
||||
if self.env.context.get('active_model') == 'crm.lead':
|
||||
opportunity_id = self.env.context.get('active_id')
|
||||
for event in self:
|
||||
if event.opportunity_id.id == opportunity_id:
|
||||
event.is_highlighted = True
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, vals):
|
||||
events = super(CalendarEvent, self).create(vals)
|
||||
for event in events:
|
||||
if event.opportunity_id and not event.activity_ids:
|
||||
event.opportunity_id.log_meeting(event)
|
||||
return events
|
||||
|
||||
def _is_crm_lead(self, defaults, ctx=None):
|
||||
"""
|
||||
This method checks if the concerned model is a CRM lead.
|
||||
The information is not always in the defaults values,
|
||||
this is why it is necessary to check the context too.
|
||||
"""
|
||||
res_model = defaults.get('res_model', False) or ctx and ctx.get('default_res_model')
|
||||
res_model_id = defaults.get('res_model_id', False) or ctx and ctx.get('default_res_model_id')
|
||||
|
||||
return res_model and res_model == 'crm.lead' or res_model_id and self.env['ir.model'].sudo().browse(res_model_id).model == 'crm.lead'
|
2727
models/crm_lead.py
Normal file
2727
models/crm_lead.py
Normal file
File diff suppressed because it is too large
Load Diff
23
models/crm_lead_scoring_frequency.py
Normal file
23
models/crm_lead_scoring_frequency.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class LeadScoringFrequency(models.Model):
|
||||
_name = 'crm.lead.scoring.frequency'
|
||||
_description = 'Lead Scoring Frequency'
|
||||
|
||||
variable = fields.Char('Variable', index=True)
|
||||
value = fields.Char('Value')
|
||||
won_count = fields.Float('Won Count', digits=(16, 1)) # Float because we add 0.1 to avoid zero Frequency issue
|
||||
lost_count = fields.Float('Lost Count', digits=(16, 1)) # Float because we add 0.1 to avoid zero Frequency issue
|
||||
team_id = fields.Many2one('crm.team', 'Sales Team', ondelete="cascade")
|
||||
|
||||
class FrequencyField(models.Model):
|
||||
_name = 'crm.lead.scoring.frequency.field'
|
||||
_description = 'Fields that can be used for predictive lead scoring computation'
|
||||
|
||||
name = fields.Char(related="field_id.field_description")
|
||||
field_id = fields.Many2one(
|
||||
'ir.model.fields', domain=[('model_id.model', '=', 'crm.lead')], required=True,
|
||||
ondelete='cascade',
|
||||
)
|
33
models/crm_lost_reason.py
Normal file
33
models/crm_lost_reason.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import fields, models, _
|
||||
|
||||
|
||||
class LostReason(models.Model):
|
||||
_name = "crm.lost.reason"
|
||||
_description = 'Opp. Lost Reason'
|
||||
|
||||
name = fields.Char('Description', required=True, translate=True)
|
||||
active = fields.Boolean('Active', default=True)
|
||||
leads_count = fields.Integer('Leads Count', compute='_compute_leads_count')
|
||||
|
||||
def _compute_leads_count(self):
|
||||
lead_data = self.env['crm.lead'].with_context(active_test=False)._read_group(
|
||||
[('lost_reason_id', 'in', self.ids)],
|
||||
['lost_reason_id'],
|
||||
['__count'],
|
||||
)
|
||||
mapped_data = {lost_reason.id: count for lost_reason, count in lead_data}
|
||||
for reason in self:
|
||||
reason.leads_count = mapped_data.get(reason.id, 0)
|
||||
|
||||
def action_lost_leads(self):
|
||||
return {
|
||||
'name': _('Leads'),
|
||||
'view_mode': 'tree,form',
|
||||
'domain': [('lost_reason_id', 'in', self.ids)],
|
||||
'res_model': 'crm.lead',
|
||||
'type': 'ir.actions.act_window',
|
||||
'context': {'create': False, 'active_test': False},
|
||||
}
|
19
models/crm_recurring_plan.py
Normal file
19
models/crm_recurring_plan.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class RecurringPlan(models.Model):
|
||||
_name = "crm.recurring.plan"
|
||||
_description = "CRM Recurring revenue plans"
|
||||
_order = "sequence"
|
||||
|
||||
name = fields.Char('Plan Name', required=True, translate=True)
|
||||
number_of_months = fields.Integer('# Months', required=True)
|
||||
active = fields.Boolean('Active', default=True)
|
||||
sequence = fields.Integer('Sequence', default=10)
|
||||
|
||||
_sql_constraints = [
|
||||
('check_number_of_months', 'CHECK(number_of_months >= 0)', 'The number of month can\'t be negative.'),
|
||||
]
|
50
models/crm_stage.py
Normal file
50
models/crm_stage.py
Normal file
|
@ -0,0 +1,50 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
AVAILABLE_PRIORITIES = [
|
||||
('0', 'Low'),
|
||||
('1', 'Medium'),
|
||||
('2', 'High'),
|
||||
('3', 'Very High'),
|
||||
]
|
||||
|
||||
|
||||
class Stage(models.Model):
|
||||
""" Model for case stages. This models the main stages of a document
|
||||
management flow. Main CRM objects (leads, opportunities, project
|
||||
issues, ...) will now use only stages, instead of state and stages.
|
||||
Stages are for example used to display the kanban view of records.
|
||||
"""
|
||||
_name = "crm.stage"
|
||||
_description = "CRM Stages"
|
||||
_rec_name = 'name'
|
||||
_order = "sequence, name, id"
|
||||
|
||||
@api.model
|
||||
def default_get(self, fields):
|
||||
""" As we have lots of default_team_id in context used to filter out
|
||||
leads and opportunities, we pop this key from default of stage creation.
|
||||
Otherwise stage will be created for a given team only which is not the
|
||||
standard behavior of stages. """
|
||||
if 'default_team_id' in self.env.context:
|
||||
ctx = dict(self.env.context)
|
||||
ctx.pop('default_team_id')
|
||||
self = self.with_context(ctx)
|
||||
return super(Stage, self).default_get(fields)
|
||||
|
||||
name = fields.Char('Stage Name', required=True, translate=True)
|
||||
sequence = fields.Integer('Sequence', default=1, help="Used to order stages. Lower is better.")
|
||||
is_won = fields.Boolean('Is Won Stage?')
|
||||
requirements = fields.Text('Requirements', help="Enter here the internal requirements for this stage (ex: Offer sent to customer). It will appear as a tooltip over the stage's name.")
|
||||
team_id = fields.Many2one('crm.team', string='Sales Team', ondelete="set null",
|
||||
help='Specific team that uses this stage. Other teams will not be able to see or use this stage.')
|
||||
fold = fields.Boolean('Folded in Pipeline',
|
||||
help='This stage is folded in the kanban view when there are no records in that stage to display.')
|
||||
# This field for interface only
|
||||
team_count = fields.Integer('team_count', compute='_compute_team_count')
|
||||
|
||||
@api.depends('team_id')
|
||||
def _compute_team_count(self):
|
||||
self.team_count = self.env['crm.team'].search_count([])
|
663
models/crm_team.py
Normal file
663
models/crm_team.py
Normal file
|
@ -0,0 +1,663 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
import datetime
|
||||
import logging
|
||||
import random
|
||||
import threading
|
||||
|
||||
from ast import literal_eval
|
||||
from markupsafe import Markup
|
||||
|
||||
from odoo import api, exceptions, fields, models, _
|
||||
from odoo.osv import expression
|
||||
from odoo.tools import float_compare, float_round
|
||||
from odoo.tools.safe_eval import safe_eval
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Team(models.Model):
|
||||
_name = 'crm.team'
|
||||
_inherit = ['mail.alias.mixin', 'crm.team']
|
||||
_description = 'Sales Team'
|
||||
|
||||
use_leads = fields.Boolean('Leads', help="Check this box to filter and qualify incoming requests as leads before converting them into opportunities and assigning them to a salesperson.")
|
||||
use_opportunities = fields.Boolean('Pipeline', default=True, help="Check this box to manage a presales process with opportunities.")
|
||||
alias_id = fields.Many2one(help="The email address associated with this channel. New emails received will automatically create new leads assigned to the channel.")
|
||||
# assignment
|
||||
assignment_enabled = fields.Boolean('Lead Assign', compute='_compute_assignment_enabled')
|
||||
assignment_auto_enabled = fields.Boolean('Auto Assignment', compute='_compute_assignment_enabled')
|
||||
assignment_optout = fields.Boolean('Skip auto assignment')
|
||||
assignment_max = fields.Integer(
|
||||
'Lead Average Capacity', compute='_compute_assignment_max',
|
||||
help='Monthly average leads capacity for all salesmen belonging to the team')
|
||||
assignment_domain = fields.Char(
|
||||
'Assignment Domain', tracking=True,
|
||||
help='Additional filter domain when fetching unassigned leads to allocate to the team.')
|
||||
# statistics about leads / opportunities / both
|
||||
lead_unassigned_count = fields.Integer(
|
||||
string='# Unassigned Leads', compute='_compute_lead_unassigned_count')
|
||||
lead_all_assigned_month_count = fields.Integer(
|
||||
string='# Leads/Opps assigned this month', compute='_compute_lead_all_assigned_month_count',
|
||||
help="Number of leads and opportunities assigned this last month.")
|
||||
lead_all_assigned_month_exceeded = fields.Boolean('Exceed monthly lead assignement', compute="_compute_lead_all_assigned_month_count",
|
||||
help="True if the monthly lead assignment count is greater than the maximum assignment limit, false otherwise."
|
||||
)
|
||||
opportunities_count = fields.Integer(
|
||||
string='# Opportunities', compute='_compute_opportunities_data')
|
||||
opportunities_amount = fields.Monetary(
|
||||
string='Opportunities Revenues', compute='_compute_opportunities_data')
|
||||
opportunities_overdue_count = fields.Integer(
|
||||
string='# Overdue Opportunities', compute='_compute_opportunities_overdue_data')
|
||||
opportunities_overdue_amount = fields.Monetary(
|
||||
string='Overdue Opportunities Revenues', compute='_compute_opportunities_overdue_data',)
|
||||
# properties
|
||||
lead_properties_definition = fields.PropertiesDefinition('Lead Properties')
|
||||
|
||||
@api.depends('crm_team_member_ids.assignment_max')
|
||||
def _compute_assignment_max(self):
|
||||
for team in self:
|
||||
team.assignment_max = sum(member.assignment_max for member in team.crm_team_member_ids)
|
||||
|
||||
def _compute_assignment_enabled(self):
|
||||
assign_enabled = self.env['ir.config_parameter'].sudo().get_param('crm.lead.auto.assignment', False)
|
||||
auto_assign_enabled = False
|
||||
if assign_enabled:
|
||||
assign_cron = self.sudo().env.ref('crm.ir_cron_crm_lead_assign', raise_if_not_found=False)
|
||||
auto_assign_enabled = assign_cron.active if assign_cron else False
|
||||
self.assignment_enabled = assign_enabled
|
||||
self.assignment_auto_enabled = auto_assign_enabled
|
||||
|
||||
def _compute_lead_unassigned_count(self):
|
||||
leads_data = self.env['crm.lead']._read_group([
|
||||
('team_id', 'in', self.ids),
|
||||
('type', '=', 'lead'),
|
||||
('user_id', '=', False),
|
||||
], ['team_id'], ['__count'])
|
||||
counts = {team.id: count for team, count in leads_data}
|
||||
for team in self:
|
||||
team.lead_unassigned_count = counts.get(team.id, 0)
|
||||
|
||||
@api.depends('crm_team_member_ids.lead_month_count', 'assignment_max')
|
||||
def _compute_lead_all_assigned_month_count(self):
|
||||
for team in self:
|
||||
team.lead_all_assigned_month_count = sum(member.lead_month_count for member in team.crm_team_member_ids)
|
||||
team.lead_all_assigned_month_exceeded = team.lead_all_assigned_month_count > team.assignment_max
|
||||
|
||||
def _compute_opportunities_data(self):
|
||||
opportunity_data = self.env['crm.lead']._read_group([
|
||||
('team_id', 'in', self.ids),
|
||||
('probability', '<', 100),
|
||||
('type', '=', 'opportunity'),
|
||||
], ['team_id'], ['__count', 'expected_revenue:sum'])
|
||||
counts_amounts = {team.id: (count, expected_revenue_sum) for team, count, expected_revenue_sum in opportunity_data}
|
||||
for team in self:
|
||||
team.opportunities_count, team.opportunities_amount = counts_amounts.get(team.id, (0, 0))
|
||||
|
||||
def _compute_opportunities_overdue_data(self):
|
||||
opportunity_data = self.env['crm.lead']._read_group([
|
||||
('team_id', 'in', self.ids),
|
||||
('probability', '<', 100),
|
||||
('type', '=', 'opportunity'),
|
||||
('date_deadline', '<', fields.Date.to_string(fields.Datetime.now()))
|
||||
], ['team_id'], ['__count', 'expected_revenue:sum'])
|
||||
counts_amounts = {team.id: (count, expected_revenue_sum) for team, count, expected_revenue_sum in opportunity_data}
|
||||
for team in self:
|
||||
team.opportunities_overdue_count, team.opportunities_overdue_amount = counts_amounts.get(team.id, (0, 0))
|
||||
|
||||
@api.onchange('use_leads', 'use_opportunities')
|
||||
def _onchange_use_leads_opportunities(self):
|
||||
if not self.use_leads and not self.use_opportunities:
|
||||
self.alias_name = False
|
||||
|
||||
@api.constrains('assignment_domain')
|
||||
def _constrains_assignment_domain(self):
|
||||
for team in self:
|
||||
try:
|
||||
domain = literal_eval(team.assignment_domain or '[]')
|
||||
if domain:
|
||||
self.env['crm.lead'].search(domain, limit=1)
|
||||
except Exception:
|
||||
raise exceptions.ValidationError(_('Assignment domain for team %(team)s is incorrectly formatted', team=team.name))
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# ORM
|
||||
# ------------------------------------------------------------
|
||||
|
||||
def write(self, vals):
|
||||
result = super(Team, self).write(vals)
|
||||
if 'use_leads' in vals or 'use_opportunities' in vals:
|
||||
for team in self:
|
||||
alias_vals = team._alias_get_creation_values()
|
||||
team.write({
|
||||
'alias_name': alias_vals.get('alias_name', team.alias_name),
|
||||
'alias_defaults': alias_vals.get('alias_defaults'),
|
||||
})
|
||||
return result
|
||||
|
||||
def unlink(self):
|
||||
""" When unlinking, concatenate ``crm.lead.scoring.frequency`` linked to
|
||||
the team into "no team" statistics. """
|
||||
frequencies = self.env['crm.lead.scoring.frequency'].search([('team_id', 'in', self.ids)])
|
||||
if frequencies:
|
||||
existing_noteam = self.env['crm.lead.scoring.frequency'].sudo().search([
|
||||
('team_id', '=', False),
|
||||
('variable', 'in', frequencies.mapped('variable'))
|
||||
])
|
||||
for frequency in frequencies:
|
||||
# skip void-like values
|
||||
if float_compare(frequency.won_count, 0.1, 2) != 1 and float_compare(frequency.lost_count, 0.1, 2) != 1:
|
||||
continue
|
||||
|
||||
match = existing_noteam.filtered(lambda frequ_nt: frequ_nt.variable == frequency.variable and frequ_nt.value == frequency.value)
|
||||
if match:
|
||||
# remove extra .1 that may exist in db as those are artifacts of initializing
|
||||
# frequency table. Final value of 0 will be set to 0.1.
|
||||
exist_won_count = float_round(match.won_count, precision_digits=0, rounding_method='HALF-UP')
|
||||
exist_lost_count = float_round(match.lost_count, precision_digits=0, rounding_method='HALF-UP')
|
||||
add_won_count = float_round(frequency.won_count, precision_digits=0, rounding_method='HALF-UP')
|
||||
add_lost_count = float_round(frequency.lost_count, precision_digits=0, rounding_method='HALF-UP')
|
||||
new_won_count = exist_won_count + add_won_count
|
||||
new_lost_count = exist_lost_count + add_lost_count
|
||||
match.won_count = new_won_count if float_compare(new_won_count, 0.1, 2) == 1 else 0.1
|
||||
match.lost_count = new_lost_count if float_compare(new_lost_count, 0.1, 2) == 1 else 0.1
|
||||
else:
|
||||
existing_noteam += self.env['crm.lead.scoring.frequency'].sudo().create({
|
||||
'lost_count': frequency.lost_count if float_compare(frequency.lost_count, 0.1, 2) == 1 else 0.1,
|
||||
'team_id': False,
|
||||
'value': frequency.value,
|
||||
'variable': frequency.variable,
|
||||
'won_count': frequency.won_count if float_compare(frequency.won_count, 0.1, 2) == 1 else 0.1,
|
||||
})
|
||||
return super(Team, self).unlink()
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# MESSAGING
|
||||
# ------------------------------------------------------------
|
||||
|
||||
def _alias_get_creation_values(self):
|
||||
values = super(Team, self)._alias_get_creation_values()
|
||||
values['alias_model_id'] = self.env['ir.model']._get('crm.lead').id
|
||||
if self.id:
|
||||
if not self.use_leads and not self.use_opportunities:
|
||||
values['alias_name'] = False
|
||||
values['alias_defaults'] = defaults = literal_eval(self.alias_defaults or "{}")
|
||||
has_group_use_lead = self.env.user.has_group('crm.group_use_lead')
|
||||
defaults['type'] = 'lead' if has_group_use_lead and self.use_leads else 'opportunity'
|
||||
defaults['team_id'] = self.id
|
||||
return values
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# LEAD ASSIGNMENT
|
||||
# ------------------------------------------------------------
|
||||
|
||||
@api.model
|
||||
def _cron_assign_leads(self, work_days=None):
|
||||
""" Cron method assigning leads. Leads are allocated to all teams and
|
||||
assigned to their members. It is based on either cron configuration
|
||||
either forced through ``work_days`` parameter.
|
||||
|
||||
When based on cron configuration purpose of cron is to assign leads to
|
||||
sales persons. Assigned workload is set to the workload those sales
|
||||
people should perform between two cron iterations. If their maximum
|
||||
capacity is reached assign process will not assign them any more lead.
|
||||
|
||||
e.g. cron is active with interval_number 3, interval_type days. This
|
||||
means cron runs every 3 days. Cron will assign leads for 3 work days
|
||||
to salespersons each 3 days unless their maximum capacity is reached.
|
||||
|
||||
If cron runs on an hour- or minute-based schedule minimum assignment
|
||||
performed is equivalent to 0.2 workdays to avoid rounding issues.
|
||||
Max assignment performed is for 30 days as it is better to run more
|
||||
often than planning for more than one month. Assign process is best
|
||||
designed to run every few hours (~4 times / day) or each few days.
|
||||
|
||||
See ``CrmTeam.action_assign_leads()`` and its sub methods for more
|
||||
details about assign process.
|
||||
|
||||
:param float work_days: see ``CrmTeam.action_assign_leads()``;
|
||||
"""
|
||||
assign_cron = self.sudo().env.ref('crm.ir_cron_crm_lead_assign', raise_if_not_found=False)
|
||||
if not work_days and assign_cron and assign_cron.active:
|
||||
if assign_cron.interval_type == 'months':
|
||||
work_days = 30 # maximum one month of work
|
||||
elif assign_cron.interval_type == 'weeks':
|
||||
work_days = min(30, assign_cron.interval_number * 7) # max at 30 (better lead repartition)
|
||||
elif assign_cron.interval_type == 'days':
|
||||
work_days = min(30, assign_cron.interval_number * 1) # max at 30 (better lead repartition)
|
||||
elif assign_cron.interval_type == 'hours':
|
||||
work_days = max(0.2, assign_cron.interval_number / 24) # min at 0.2 to avoid small numbers issues
|
||||
elif assign_cron.interval_type == 'minutes':
|
||||
work_days = max(0.2, assign_cron.interval_number / 1440) # min at 0.2 to avoid small numbers issues
|
||||
work_days = work_days if work_days else 1 # avoid void values
|
||||
self.env['crm.team'].search([
|
||||
'&', '|', ('use_leads', '=', True), ('use_opportunities', '=', True),
|
||||
('assignment_optout', '=', False)
|
||||
])._action_assign_leads(work_days=work_days)
|
||||
return True
|
||||
|
||||
def action_assign_leads(self, work_days=1, log=True):
|
||||
""" Manual (direct) leads assignment. This method both
|
||||
|
||||
* assigns leads to teams given by self;
|
||||
* assigns leads to salespersons belonging to self;
|
||||
|
||||
See sub methods for more details about assign process.
|
||||
|
||||
:param float work_days: number of work days to consider when assigning leads
|
||||
to teams or salespersons. We consider that Member.assignment_max (or
|
||||
its equivalent on team model) targets 30 work days. We make a ratio
|
||||
between expected number of work days and maximum assignment for those
|
||||
30 days to know lead count to assign.
|
||||
|
||||
:return action: a client notification giving some insights on assign
|
||||
process;
|
||||
"""
|
||||
teams_data, members_data = self._action_assign_leads(work_days=work_days)
|
||||
|
||||
# format result messages
|
||||
logs = self._action_assign_leads_logs(teams_data, members_data)
|
||||
html_message = Markup('<br />').join(logs)
|
||||
notif_message = ' '.join(logs)
|
||||
|
||||
# log a note in case of manual assign (as this method will mainly be called
|
||||
# on singleton record set, do not bother doing a specific message per team)
|
||||
log_action = _("Lead Assignment requested by %(user_name)s", user_name=self.env.user.name)
|
||||
log_message = Markup("<p>%s<br /><br />%s</p>") % (log_action, html_message)
|
||||
self._message_log_batch(bodies=dict((team.id, log_message) for team in self))
|
||||
|
||||
return {
|
||||
'type': 'ir.actions.client',
|
||||
'tag': 'display_notification',
|
||||
'params': {
|
||||
'type': 'success',
|
||||
'title': _("Leads Assigned"),
|
||||
'message': notif_message,
|
||||
'next': {
|
||||
'type': 'ir.actions.act_window_close'
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
def _action_assign_leads(self, work_days=1):
|
||||
""" Private method for lead assignment. This method both
|
||||
|
||||
* assigns leads to teams given by self;
|
||||
* assigns leads to salespersons belonging to self;
|
||||
|
||||
See sub methods for more details about assign process.
|
||||
|
||||
:param float work_days: see ``CrmTeam.action_assign_leads()``;
|
||||
|
||||
:return teams_data, members_data: structure-based result of assignment
|
||||
process. For more details about data see ``CrmTeam._allocate_leads()``
|
||||
and ``CrmTeamMember._assign_and_convert_leads``;
|
||||
"""
|
||||
if not self.env.user.has_group('sales_team.group_sale_manager') and not self.env.user.has_group('base.group_system'):
|
||||
raise exceptions.UserError(_('Lead/Opportunities automatic assignment is limited to managers or administrators'))
|
||||
|
||||
_logger.info('### START Lead Assignment (%d teams, %d sales persons, %.2f work_days)', len(self), len(self.crm_team_member_ids), work_days)
|
||||
teams_data = self._allocate_leads(work_days=work_days)
|
||||
_logger.info('### Team repartition done. Starting salesmen assignment.')
|
||||
members_data = self.crm_team_member_ids._assign_and_convert_leads(work_days=work_days)
|
||||
_logger.info('### END Lead Assignment')
|
||||
return teams_data, members_data
|
||||
|
||||
def _action_assign_leads_logs(self, teams_data, members_data):
|
||||
""" Tool method to prepare notification about assignment process result.
|
||||
|
||||
:param teams_data: see ``CrmTeam._allocate_leads()``;
|
||||
:param members_data: see ``CrmTeamMember._assign_and_convert_leads()``;
|
||||
|
||||
:return list: list of formatted logs, ready to be formatted into a nice
|
||||
plaintext or html message at caller's will
|
||||
"""
|
||||
# extract some statistics
|
||||
assigned = sum(len(teams_data[team]['assigned']) + len(teams_data[team]['merged']) for team in teams_data)
|
||||
duplicates = sum(len(teams_data[team]['duplicates']) for team in teams_data)
|
||||
members = len(members_data)
|
||||
members_assigned = sum(len(member_data['assigned']) for member_data in members_data.values())
|
||||
|
||||
# format user notification
|
||||
message_parts = []
|
||||
# 1- duplicates removal
|
||||
if duplicates:
|
||||
message_parts.append(_("%(duplicates)s duplicates leads have been merged.",
|
||||
duplicates=duplicates))
|
||||
|
||||
# 2- nothing assigned at all
|
||||
if not assigned and not members_assigned:
|
||||
if len(self) == 1:
|
||||
if not self.assignment_max:
|
||||
message_parts.append(
|
||||
_("No allocated leads to %(team_name)s team because it has no capacity. Add capacity to its salespersons.",
|
||||
team_name=self.name))
|
||||
else:
|
||||
message_parts.append(
|
||||
_("No allocated leads to %(team_name)s team and its salespersons because no unassigned lead matches its domain.",
|
||||
team_name=self.name))
|
||||
else:
|
||||
message_parts.append(
|
||||
_("No allocated leads to any team or salesperson. Check your Sales Teams and Salespersons configuration as well as unassigned leads."))
|
||||
|
||||
# 3- team allocation
|
||||
if not assigned and members_assigned:
|
||||
if len(self) == 1:
|
||||
message_parts.append(
|
||||
_("No new lead allocated to %(team_name)s team because no unassigned lead matches its domain.",
|
||||
team_name=self.name))
|
||||
else:
|
||||
message_parts.append(_("No new lead allocated to the teams because no lead match their domains."))
|
||||
elif assigned:
|
||||
if len(self) == 1:
|
||||
message_parts.append(
|
||||
_("%(assigned)s leads allocated to %(team_name)s team.",
|
||||
assigned=assigned, team_name=self.name))
|
||||
else:
|
||||
message_parts.append(
|
||||
_("%(assigned)s leads allocated among %(team_count)s teams.",
|
||||
assigned=assigned, team_count=len(self)))
|
||||
|
||||
# 4- salespersons assignment
|
||||
if not members_assigned and assigned:
|
||||
message_parts.append(
|
||||
_("No lead assigned to salespersons because no unassigned lead matches their domains."))
|
||||
elif members_assigned:
|
||||
message_parts.append(
|
||||
_("%(members_assigned)s leads assigned among %(member_count)s salespersons.",
|
||||
members_assigned=members_assigned, member_count=members))
|
||||
|
||||
return message_parts
|
||||
|
||||
def _allocate_leads(self, work_days=1):
|
||||
""" Allocate leads to teams given by self. This method sets ``team_id``
|
||||
field on lead records that are unassigned (no team and no responsible).
|
||||
No salesperson is assigned in this process. Its purpose is simply to
|
||||
allocate leads within teams.
|
||||
|
||||
This process allocates all available leads on teams weighted by their
|
||||
maximum assignment by month that indicates their relative workload.
|
||||
|
||||
Heuristic of this method is the following:
|
||||
* find unassigned leads for each team, aka leads being
|
||||
* without team, without user -> not assigned;
|
||||
* not in a won stage, and not having False/0 (lost) or 100 (won)
|
||||
probability) -> live leads;
|
||||
* if set, a delay after creation can be applied (see BUNDLE_HOURS_DELAY)
|
||||
parameter explanations here below;
|
||||
* matching the team's assignment domain (empty means
|
||||
everything);
|
||||
|
||||
* assign a weight to each team based on their assignment_max that
|
||||
indicates their relative workload;
|
||||
|
||||
* pick a random team using a weighted random choice and find a lead
|
||||
to assign:
|
||||
|
||||
* remove already assigned leads from the available leads. If there
|
||||
is not any lead spare to assign, remove team from active teams;
|
||||
* pick the first lead and set the current team;
|
||||
* when setting a team on leads, leads are also merged with their
|
||||
duplicates. Purpose is to clean database and avoid assigning
|
||||
duplicates to same or different teams;
|
||||
* add lead and its duplicates to already assigned leads;
|
||||
|
||||
* pick another random team until their is no more leads to assign
|
||||
to any team;
|
||||
|
||||
This process ensure that teams having overlapping domains will all
|
||||
receive leads as lead allocation is done one lead at a time. This
|
||||
allocation will be proportional to their size (assignment of their
|
||||
members).
|
||||
|
||||
:config int crm.assignment.bundle: deprecated
|
||||
:config int crm.assignment.commit.bundle: optional config parameter allowing
|
||||
to set size of lead batch to be committed together. By default 100
|
||||
which is a good trade-off between transaction time and speed
|
||||
:config int crm.assignment.delay: optional config parameter giving a
|
||||
delay before taking a lead into assignment process (BUNDLE_HOURS_DELAY)
|
||||
given in hours. Purpose if to allow other crons or automation rules
|
||||
to make their job. This option is mainly historic as its purpose was
|
||||
to let automation rules prepare leads and score before PLS was added
|
||||
into CRM. This is now not required anymore but still supported;
|
||||
|
||||
:param float work_days: see ``CrmTeam.action_assign_leads()``;
|
||||
|
||||
:return teams_data: dict() with each team assignment result:
|
||||
team: {
|
||||
'assigned': set of lead IDs directly assigned to the team (no
|
||||
duplicate or merged found);
|
||||
'merged': set of lead IDs merged and assigned to the team (main
|
||||
leads being results of merge process);
|
||||
'duplicates': set of lead IDs found as duplicates and merged into
|
||||
other leads. Those leads are unlinked during assign process and
|
||||
are already removed at return of this method;
|
||||
}, ...
|
||||
"""
|
||||
if work_days < 0.2 or work_days > 30:
|
||||
raise ValueError(
|
||||
_('Leads team allocation should be done for at least 0.2 or maximum 30 work days, not %.2f.', work_days)
|
||||
)
|
||||
|
||||
BUNDLE_HOURS_DELAY = int(self.env['ir.config_parameter'].sudo().get_param('crm.assignment.delay', default=0))
|
||||
BUNDLE_COMMIT_SIZE = int(self.env['ir.config_parameter'].sudo().get_param('crm.assignment.commit.bundle', 100))
|
||||
auto_commit = not getattr(threading.current_thread(), 'testing', False)
|
||||
|
||||
# leads
|
||||
max_create_dt = self.env.cr.now() - datetime.timedelta(hours=BUNDLE_HOURS_DELAY)
|
||||
duplicates_lead_cache = dict()
|
||||
|
||||
# teams data
|
||||
teams_data, population, weights = dict(), list(), list()
|
||||
for team in self:
|
||||
if not team.assignment_max:
|
||||
continue
|
||||
|
||||
lead_domain = expression.AND([
|
||||
literal_eval(team.assignment_domain or '[]'),
|
||||
[('create_date', '<=', max_create_dt)],
|
||||
['&', ('team_id', '=', False), ('user_id', '=', False)],
|
||||
['|', ('stage_id', '=', False), ('stage_id.is_won', '=', False)]
|
||||
])
|
||||
|
||||
leads = self.env["crm.lead"].search(lead_domain)
|
||||
# Fill duplicate cache: search for duplicate lead before the assignation
|
||||
# avoid to flush during the search at every assignation
|
||||
for lead in leads:
|
||||
if lead not in duplicates_lead_cache:
|
||||
duplicates_lead_cache[lead] = lead._get_lead_duplicates(email=lead.email_from)
|
||||
|
||||
teams_data[team] = {
|
||||
"team": team,
|
||||
"leads": leads,
|
||||
"assigned": set(),
|
||||
"merged": set(),
|
||||
"duplicates": set(),
|
||||
}
|
||||
population.append(team)
|
||||
weights.append(team.assignment_max)
|
||||
|
||||
# Start a new transaction, since data fetching take times
|
||||
# and the first commit occur at the end of the bundle,
|
||||
# the first transaction can be long which we want to avoid
|
||||
if auto_commit:
|
||||
self._cr.commit()
|
||||
|
||||
# assignment process data
|
||||
global_data = dict(assigned=set(), merged=set(), duplicates=set())
|
||||
leads_done_ids, lead_unlink_ids, counter = set(), set(), 0
|
||||
while population:
|
||||
counter += 1
|
||||
team = random.choices(population, weights=weights, k=1)[0]
|
||||
|
||||
# filter remaining leads, remove team if no more leads for it
|
||||
teams_data[team]["leads"] = teams_data[team]["leads"].filtered(lambda l: l.id not in leads_done_ids).exists()
|
||||
if not teams_data[team]["leads"]:
|
||||
population_index = population.index(team)
|
||||
population.pop(population_index)
|
||||
weights.pop(population_index)
|
||||
continue
|
||||
|
||||
# assign + deduplicate and concatenate results in teams_data to keep some history
|
||||
candidate_lead = teams_data[team]["leads"][0]
|
||||
assign_res = team._allocate_leads_deduplicate(candidate_lead, duplicates_cache=duplicates_lead_cache)
|
||||
for key in ('assigned', 'merged', 'duplicates'):
|
||||
teams_data[team][key].update(assign_res[key])
|
||||
leads_done_ids.update(assign_res[key])
|
||||
global_data[key].update(assign_res[key])
|
||||
lead_unlink_ids.update(assign_res['duplicates'])
|
||||
|
||||
# auto-commit except in testing mode. As this process may be time consuming or we
|
||||
# may encounter errors, already commit what is allocated to avoid endless cron loops.
|
||||
if auto_commit and counter % BUNDLE_COMMIT_SIZE == 0:
|
||||
# unlink duplicates once
|
||||
self.env['crm.lead'].browse(lead_unlink_ids).unlink()
|
||||
lead_unlink_ids = set()
|
||||
self._cr.commit()
|
||||
|
||||
# unlink duplicates once
|
||||
self.env['crm.lead'].browse(lead_unlink_ids).unlink()
|
||||
|
||||
if auto_commit:
|
||||
self._cr.commit()
|
||||
|
||||
# some final log
|
||||
_logger.info('## Assigned %s leads', (len(global_data['assigned']) + len(global_data['merged'])))
|
||||
for team, team_data in teams_data.items():
|
||||
_logger.info(
|
||||
'## Assigned %s leads to team %s',
|
||||
len(team_data['assigned']) + len(team_data['merged']), team.id)
|
||||
_logger.info(
|
||||
'\tLeads: direct assign %s / merge result %s / duplicates merged: %s',
|
||||
team_data['assigned'], team_data['merged'], team_data['duplicates'])
|
||||
return teams_data
|
||||
|
||||
def _allocate_leads_deduplicate(self, leads, duplicates_cache=None):
|
||||
""" Assign leads to sales team given by self by calling lead tool
|
||||
method _handle_salesmen_assignment. In this method we deduplicate leads
|
||||
allowing to reduce number of resulting leads before assigning them
|
||||
to salesmen.
|
||||
|
||||
:param leads: recordset of leads to assign to current team;
|
||||
:param duplicates_cache: if given, avoid to perform a duplicate search
|
||||
and fetch information in it instead;
|
||||
"""
|
||||
self.ensure_one()
|
||||
duplicates_cache = duplicates_cache if duplicates_cache is not None else dict()
|
||||
|
||||
# classify leads
|
||||
leads_assigned = self.env['crm.lead'] # direct team assign
|
||||
leads_done_ids, leads_merged_ids, leads_dup_ids = set(), set(), set() # classification
|
||||
leads_dups_dict = dict() # lead -> its duplicate
|
||||
for lead in leads:
|
||||
if lead.id not in leads_done_ids:
|
||||
|
||||
# fill cache if not already done
|
||||
if lead not in duplicates_cache:
|
||||
duplicates_cache[lead] = lead._get_lead_duplicates(email=lead.email_from)
|
||||
lead_duplicates = duplicates_cache[lead].exists()
|
||||
|
||||
if len(lead_duplicates) > 1:
|
||||
leads_dups_dict[lead] = lead_duplicates
|
||||
leads_done_ids.update((lead + lead_duplicates).ids)
|
||||
else:
|
||||
leads_assigned += lead
|
||||
leads_done_ids.add(lead.id)
|
||||
|
||||
# assign team to direct assign (leads_assigned) + dups keys (to ensure their team
|
||||
# if they are elected master of merge process)
|
||||
dups_to_assign = [lead for lead in leads_dups_dict]
|
||||
leads_assigned.union(*dups_to_assign)._handle_salesmen_assignment(user_ids=None, team_id=self.id)
|
||||
|
||||
for lead in leads.filtered(lambda lead: lead in leads_dups_dict):
|
||||
lead_duplicates = leads_dups_dict[lead]
|
||||
merged = lead_duplicates._merge_opportunity(user_id=False, team_id=False, auto_unlink=False, max_length=0)
|
||||
leads_dup_ids.update((lead_duplicates - merged).ids)
|
||||
leads_merged_ids.add(merged.id)
|
||||
|
||||
return {
|
||||
'assigned': set(leads_assigned.ids),
|
||||
'merged': leads_merged_ids,
|
||||
'duplicates': leads_dup_ids,
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# ACTIONS
|
||||
# ------------------------------------------------------------
|
||||
|
||||
#TODO JEM : refactor this stuff with xml action, proper customization,
|
||||
@api.model
|
||||
def action_your_pipeline(self):
|
||||
action = self.env["ir.actions.actions"]._for_xml_id("crm.crm_lead_action_pipeline")
|
||||
return self._action_update_to_pipeline(action)
|
||||
|
||||
@api.model
|
||||
def action_opportunity_forecast(self):
|
||||
action = self.env['ir.actions.actions']._for_xml_id('crm.crm_lead_action_forecast')
|
||||
return self._action_update_to_pipeline(action)
|
||||
|
||||
@api.model
|
||||
def _action_update_to_pipeline(self, action):
|
||||
user_team_id = self.env.user.sale_team_id.id
|
||||
if user_team_id:
|
||||
# To ensure that the team is readable in multi company
|
||||
user_team_id = self.search([('id', '=', user_team_id)], limit=1).id
|
||||
else:
|
||||
user_team_id = self.search([], limit=1).id
|
||||
action['help'] = "<p class='o_view_nocontent_smiling_face'>%s</p><p>" % _("Create an Opportunity")
|
||||
if user_team_id:
|
||||
if self.user_has_groups('sales_team.group_sale_manager'):
|
||||
action['help'] += "<p>%s</p>" % _("""As you are a member of no Sales Team, you are showed the Pipeline of the <b>first team by default.</b>
|
||||
To work with the CRM, you should <a name="%d" type="action" tabindex="-1">join a team.</a>""",
|
||||
self.env.ref('sales_team.crm_team_action_config').id)
|
||||
else:
|
||||
action['help'] += "<p>%s</p>" % _("""As you are a member of no Sales Team, you are showed the Pipeline of the <b>first team by default.</b>
|
||||
To work with the CRM, you should join a team.""")
|
||||
action_context = safe_eval(action['context'], {'uid': self.env.uid})
|
||||
if user_team_id:
|
||||
action_context['default_team_id'] = user_team_id
|
||||
|
||||
action['context'] = action_context
|
||||
return action
|
||||
|
||||
def _compute_dashboard_button_name(self):
|
||||
super(Team, self)._compute_dashboard_button_name()
|
||||
team_with_pipelines = self.filtered(lambda el: el.use_opportunities)
|
||||
team_with_pipelines.update({'dashboard_button_name': _("Pipeline")})
|
||||
|
||||
def action_primary_channel_button(self):
|
||||
self.ensure_one()
|
||||
if self.use_opportunities:
|
||||
action = self.env['ir.actions.actions']._for_xml_id('crm.crm_case_form_view_salesteams_opportunity')
|
||||
rcontext = {
|
||||
'team': self,
|
||||
}
|
||||
action['help'] = self.env['ir.ui.view']._render_template('crm.crm_action_helper', values=rcontext)
|
||||
return action
|
||||
return super(Team,self).action_primary_channel_button()
|
||||
|
||||
def _graph_get_model(self):
|
||||
if self.use_opportunities:
|
||||
return 'crm.lead'
|
||||
return super(Team,self)._graph_get_model()
|
||||
|
||||
def _graph_date_column(self):
|
||||
if self.use_opportunities:
|
||||
return 'create_date'
|
||||
return super(Team,self)._graph_date_column()
|
||||
|
||||
def _graph_y_query(self):
|
||||
if self.use_opportunities:
|
||||
return 'count(*)'
|
||||
return super(Team,self)._graph_y_query()
|
||||
|
||||
def _extra_sql_conditions(self):
|
||||
if self.use_opportunities:
|
||||
return "AND type LIKE 'opportunity'"
|
||||
return super(Team,self)._extra_sql_conditions()
|
||||
|
||||
def _graph_title_and_key(self):
|
||||
if self.use_opportunities:
|
||||
return ['', _('New Opportunities')] # no more title
|
||||
return super(Team, self)._graph_title_and_key()
|
212
models/crm_team_member.py
Normal file
212
models/crm_team_member.py
Normal file
|
@ -0,0 +1,212 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
import datetime
|
||||
import logging
|
||||
import math
|
||||
import threading
|
||||
import random
|
||||
|
||||
from ast import literal_eval
|
||||
|
||||
from odoo import api, exceptions, fields, models, _
|
||||
from odoo.osv import expression
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class TeamMember(models.Model):
|
||||
_inherit = 'crm.team.member'
|
||||
|
||||
# assignment
|
||||
assignment_enabled = fields.Boolean(related="crm_team_id.assignment_enabled")
|
||||
assignment_domain = fields.Char('Assignment Domain', tracking=True)
|
||||
assignment_optout = fields.Boolean('Skip auto assignment')
|
||||
assignment_max = fields.Integer('Average Leads Capacity (on 30 days)', default=30)
|
||||
lead_month_count = fields.Integer(
|
||||
'Leads (30 days)', compute='_compute_lead_month_count',
|
||||
help='Lead assigned to this member those last 30 days')
|
||||
|
||||
@api.depends('user_id', 'crm_team_id')
|
||||
def _compute_lead_month_count(self):
|
||||
for member in self:
|
||||
if member.user_id.id and member.crm_team_id.id:
|
||||
member.lead_month_count = self.env['crm.lead'].with_context(active_test=False).search_count(
|
||||
member._get_lead_month_domain()
|
||||
)
|
||||
else:
|
||||
member.lead_month_count = 0
|
||||
|
||||
@api.constrains('assignment_domain')
|
||||
def _constrains_assignment_domain(self):
|
||||
for member in self:
|
||||
try:
|
||||
domain = literal_eval(member.assignment_domain or '[]')
|
||||
if domain:
|
||||
self.env['crm.lead'].search(domain, limit=1)
|
||||
except Exception:
|
||||
raise exceptions.ValidationError(_(
|
||||
'Member assignment domain for user %(user)s and team %(team)s is incorrectly formatted',
|
||||
user=member.user_id.name, team=member.crm_team_id.name
|
||||
))
|
||||
|
||||
def _get_lead_month_domain(self):
|
||||
limit_date = fields.Datetime.now() - datetime.timedelta(days=30)
|
||||
return [
|
||||
('user_id', '=', self.user_id.id),
|
||||
('team_id', '=', self.crm_team_id.id),
|
||||
('date_open', '>=', limit_date),
|
||||
]
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# LEAD ASSIGNMENT
|
||||
# ------------------------------------------------------------
|
||||
|
||||
def _assign_and_convert_leads(self, work_days=1):
|
||||
""" Main processing method to assign leads to sales team members. It also
|
||||
converts them into opportunities. This method should be called after
|
||||
``_allocate_leads`` as this method assigns leads already allocated to
|
||||
the member's team. Its main purpose is therefore to distribute team
|
||||
workload on its members based on their capacity.
|
||||
|
||||
Preparation
|
||||
|
||||
* prepare lead domain for each member. It is done using a logical
|
||||
AND with team's domain and member's domain. Member domains further
|
||||
restricts team domain;
|
||||
* prepare a set of available leads for each member by searching for
|
||||
leads matching domain with a sufficient limit to ensure all members
|
||||
will receive leads;
|
||||
* prepare a weighted population sample. Population are members that
|
||||
should received leads. Initial weight is the number of leads to
|
||||
assign to that specific member. This is minimum value between
|
||||
* remaining this month: assignment_max - number of lead already
|
||||
assigned this month;
|
||||
* days-based assignment: assignment_max with a ratio based on
|
||||
``work_days`` parameter (see ``CrmTeam.action_assign_leads()``)
|
||||
* e.g. Michel Poilvache (max: 30 - currently assigned: 15) limit
|
||||
for 2 work days: min(30-15, 30/15) -> 2 leads assigned
|
||||
* e.g. Michel Tartopoil (max: 30 - currently assigned: 26) limit
|
||||
for 10 work days: min(30-26, 30/3) -> 4 leads assigned
|
||||
|
||||
This method then follows the following heuristic
|
||||
|
||||
* take a weighted random choice in population;
|
||||
* find first available (not yet assigned) lead in its lead set;
|
||||
* if found:
|
||||
* convert it into an opportunity and assign member as salesperson;
|
||||
* lessen member's weight so that other members have an higher
|
||||
probability of being picked up next;
|
||||
* if not found: consider this member is out of assignment process,
|
||||
remove it from population so that it is not picked up anymore;
|
||||
|
||||
Assignment is performed one lead at a time for fairness purpose. Indeed
|
||||
members may have overlapping domains within a given team. To ensure
|
||||
some fairness in process once a member receives a lead, a new choice is
|
||||
performed with updated weights. This is not optimal from performance
|
||||
point of view but increases probability leads are correctly distributed
|
||||
within the team.
|
||||
|
||||
:param float work_days: see ``CrmTeam.action_assign_leads()``;
|
||||
|
||||
:return members_data: dict() with each member assignment result:
|
||||
membership: {
|
||||
'assigned': set of lead IDs directly assigned to the member;
|
||||
}, ...
|
||||
|
||||
"""
|
||||
if work_days < 0.2 or work_days > 30:
|
||||
raise ValueError(
|
||||
_('Leads team allocation should be done for at least 0.2 or maximum 30 work days, not %.2f.', work_days)
|
||||
)
|
||||
|
||||
members_data, population, weights = dict(), list(), list()
|
||||
members = self.filtered(lambda member: not member.assignment_optout and member.assignment_max > 0)
|
||||
if not members:
|
||||
return members_data
|
||||
|
||||
# prepare a global lead count based on total leads to assign to salespersons
|
||||
lead_limit = sum(
|
||||
member._get_assignment_quota(work_days=work_days)
|
||||
for member in members
|
||||
)
|
||||
|
||||
# could probably be optimized
|
||||
for member in members:
|
||||
lead_domain = expression.AND([
|
||||
literal_eval(member.assignment_domain or '[]'),
|
||||
['&', '&', ('user_id', '=', False), ('date_open', '=', False), ('team_id', '=', member.crm_team_id.id)]
|
||||
])
|
||||
|
||||
leads = self.env["crm.lead"].search(lead_domain, order='probability DESC, id', limit=lead_limit)
|
||||
|
||||
to_assign = member._get_assignment_quota(work_days=work_days)
|
||||
members_data[member.id] = {
|
||||
"team_member": member,
|
||||
"max": member.assignment_max,
|
||||
"to_assign": to_assign,
|
||||
"leads": leads,
|
||||
"assigned": self.env["crm.lead"],
|
||||
}
|
||||
population.append(member.id)
|
||||
weights.append(to_assign)
|
||||
|
||||
leads_done_ids = set()
|
||||
counter = 0
|
||||
# auto-commit except in testing mode
|
||||
auto_commit = not getattr(threading.current_thread(), 'testing', False)
|
||||
commit_bundle_size = int(self.env['ir.config_parameter'].sudo().get_param('crm.assignment.commit.bundle', 100))
|
||||
while population and any(weights):
|
||||
counter += 1
|
||||
member_id = random.choices(population, weights=weights, k=1)[0]
|
||||
member_index = population.index(member_id)
|
||||
member_data = members_data[member_id]
|
||||
|
||||
lead = next((lead for lead in member_data['leads'] if lead.id not in leads_done_ids), False)
|
||||
if lead:
|
||||
leads_done_ids.add(lead.id)
|
||||
members_data[member_id]["assigned"] += lead
|
||||
weights[member_index] = weights[member_index] - 1
|
||||
|
||||
lead.with_context(mail_auto_subscribe_no_notify=True).convert_opportunity(
|
||||
lead.partner_id,
|
||||
user_ids=member_data['team_member'].user_id.ids
|
||||
)
|
||||
|
||||
if auto_commit and counter % commit_bundle_size == 0:
|
||||
self._cr.commit()
|
||||
else:
|
||||
weights[member_index] = 0
|
||||
|
||||
if weights[member_index] <= 0:
|
||||
population.pop(member_index)
|
||||
weights.pop(member_index)
|
||||
|
||||
# failsafe
|
||||
if counter > 100000:
|
||||
population = list()
|
||||
|
||||
if auto_commit:
|
||||
self._cr.commit()
|
||||
# log results and return
|
||||
result_data = dict(
|
||||
(member_info["team_member"], {"assigned": member_info["assigned"]})
|
||||
for member_id, member_info in members_data.items()
|
||||
)
|
||||
_logger.info('Assigned %s leads to %s salesmen', len(leads_done_ids), len(members))
|
||||
for member, member_info in result_data.items():
|
||||
_logger.info('-> member %s: assigned %d leads (%s)', member.id, len(member_info["assigned"]), member_info["assigned"])
|
||||
return result_data
|
||||
|
||||
def _get_assignment_quota(self, work_days=1):
|
||||
""" Compute assignment quota based on work_days. This quota includes
|
||||
a compensation to speedup getting to the lead average (``assignment_max``).
|
||||
As this field is a counter for "30 days" -> divide by requested work
|
||||
days in order to have base assign number then add compensation.
|
||||
|
||||
:param float work_days: see ``CrmTeam.action_assign_leads()``;
|
||||
"""
|
||||
assign_ratio = work_days / 30.0
|
||||
to_assign = self.assignment_max * assign_ratio
|
||||
compensation = max(0, self.assignment_max - (self.lead_month_count + to_assign)) * 0.2
|
||||
return round(to_assign + compensation)
|
39
models/digest.py
Normal file
39
models/digest.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.exceptions import AccessError
|
||||
|
||||
|
||||
class Digest(models.Model):
|
||||
_inherit = 'digest.digest'
|
||||
|
||||
kpi_crm_lead_created = fields.Boolean('New Leads')
|
||||
kpi_crm_lead_created_value = fields.Integer(compute='_compute_kpi_crm_lead_created_value')
|
||||
kpi_crm_opportunities_won = fields.Boolean('Opportunities Won')
|
||||
kpi_crm_opportunities_won_value = fields.Integer(compute='_compute_kpi_crm_opportunities_won_value')
|
||||
|
||||
def _compute_kpi_crm_lead_created_value(self):
|
||||
if not self.env.user.has_group('sales_team.group_sale_salesman'):
|
||||
raise AccessError(_("Do not have access, skip this data for user's digest email"))
|
||||
|
||||
self._calculate_company_based_kpi('crm.lead', 'kpi_crm_lead_created_value')
|
||||
|
||||
def _compute_kpi_crm_opportunities_won_value(self):
|
||||
if not self.env.user.has_group('sales_team.group_sale_salesman'):
|
||||
raise AccessError(_("Do not have access, skip this data for user's digest email"))
|
||||
|
||||
self._calculate_company_based_kpi(
|
||||
'crm.lead',
|
||||
'kpi_crm_opportunities_won_value',
|
||||
date_field='date_closed',
|
||||
additional_domain=[('type', '=', 'opportunity'), ('probability', '=', '100')],
|
||||
)
|
||||
|
||||
def _compute_kpis_actions(self, company, user):
|
||||
res = super(Digest, self)._compute_kpis_actions(company, user)
|
||||
res['kpi_crm_lead_created'] = 'crm.crm_lead_action_pipeline&menu_id=%s' % self.env.ref('crm.crm_menu_root').id
|
||||
res['kpi_crm_opportunities_won'] = 'crm.crm_lead_action_pipeline&menu_id=%s' % self.env.ref('crm.crm_menu_root').id
|
||||
if user.has_group('crm.group_use_lead'):
|
||||
res['kpi_crm_lead_created'] = 'crm.crm_lead_all_leads&menu_id=%s' % self.env.ref('crm.crm_menu_root').id
|
||||
return res
|
32
models/ir_config_parameter.py
Normal file
32
models/ir_config_parameter.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, models
|
||||
from odoo.addons.base.models.ir_model import MODULE_UNINSTALL_FLAG
|
||||
|
||||
|
||||
class IrConfigParameter(models.Model):
|
||||
_inherit = 'ir.config_parameter'
|
||||
|
||||
def write(self, vals):
|
||||
result = super(IrConfigParameter, self).write(vals)
|
||||
if any(record.key == "crm.pls_fields" for record in self):
|
||||
self.env.flush_all()
|
||||
self.env.registry.setup_models(self.env.cr)
|
||||
return result
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
records = super(IrConfigParameter, self).create(vals_list)
|
||||
if any(record.key == "crm.pls_fields" for record in records):
|
||||
self.env.flush_all()
|
||||
self.env.registry.setup_models(self.env.cr)
|
||||
return records
|
||||
|
||||
def unlink(self):
|
||||
pls_emptied = any(record.key == "crm.pls_fields" for record in self)
|
||||
result = super(IrConfigParameter, self).unlink()
|
||||
if pls_emptied and not self._context.get(MODULE_UNINSTALL_FLAG):
|
||||
self.env.flush_all()
|
||||
self.env.registry.setup_models(self.env.cr)
|
||||
return result
|
26
models/mail_activity.py
Normal file
26
models/mail_activity.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import models
|
||||
|
||||
|
||||
class MailActivity(models.Model):
|
||||
_inherit = "mail.activity"
|
||||
|
||||
def action_create_calendar_event(self):
|
||||
""" Small override of the action that creates a calendar.
|
||||
|
||||
If the activity is linked to a crm.lead through the "opportunity_id" field, we include in
|
||||
the action context the default values used when scheduling a meeting from the crm.lead form
|
||||
view.
|
||||
e.g: It will set the partner_id of the crm.lead as default attendee of the meeting. """
|
||||
|
||||
action = super(MailActivity, self).action_create_calendar_event()
|
||||
opportunity = self.calendar_event_id.opportunity_id
|
||||
if opportunity:
|
||||
opportunity_action_context = opportunity.action_schedule_meeting(smart_calendar=False).get('context', {})
|
||||
opportunity_action_context['initial_date'] = self.calendar_event_id.start
|
||||
|
||||
action['context'].update(opportunity_action_context)
|
||||
|
||||
return action
|
170
models/res_config_settings.py
Normal file
170
models/res_config_settings.py
Normal file
|
@ -0,0 +1,170 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from datetime import timedelta
|
||||
from dateutil.relativedelta import relativedelta
|
||||
|
||||
from odoo import api, exceptions, fields, models, _
|
||||
|
||||
|
||||
class ResConfigSettings(models.TransientModel):
|
||||
_inherit = 'res.config.settings'
|
||||
|
||||
group_use_lead = fields.Boolean(string="Leads", implied_group='crm.group_use_lead')
|
||||
group_use_recurring_revenues = fields.Boolean(string="Recurring Revenues", implied_group='crm.group_use_recurring_revenues')
|
||||
# Membership
|
||||
is_membership_multi = fields.Boolean(string='Multi Teams', config_parameter='sales_team.membership_multi')
|
||||
# Lead assignment
|
||||
crm_use_auto_assignment = fields.Boolean(
|
||||
string='Rule-Based Assignment', config_parameter='crm.lead.auto.assignment')
|
||||
crm_auto_assignment_action = fields.Selection([
|
||||
('manual', 'Manually'), ('auto', 'Repeatedly')],
|
||||
string='Auto Assignment Action', compute='_compute_crm_auto_assignment_data',
|
||||
readonly=False, store=True,
|
||||
help='Manual assign allow to trigger assignment from team form view using an action button. Automatic configures a cron running repeatedly assignment in all teams.')
|
||||
crm_auto_assignment_interval_type = fields.Selection([
|
||||
('minutes', 'Minutes'), ('hours', 'Hours'),
|
||||
('days', 'Days'), ('weeks', 'Weeks')],
|
||||
string='Auto Assignment Interval Unit', compute='_compute_crm_auto_assignment_data',
|
||||
readonly=False, store=True,
|
||||
help='Interval type between each cron run (e.g. each 2 days or each 2 hours)')
|
||||
crm_auto_assignment_interval_number = fields.Integer(
|
||||
string="Repeat every", compute='_compute_crm_auto_assignment_data',
|
||||
readonly=False, store=True,
|
||||
help='Number of interval type between each cron run (e.g. each 2 days or each 4 days)')
|
||||
crm_auto_assignment_run_datetime = fields.Datetime(
|
||||
string="Auto Assignment Next Execution Date", compute='_compute_crm_auto_assignment_data',
|
||||
readonly=False, store=True)
|
||||
# IAP
|
||||
module_crm_iap_mine = fields.Boolean("Generate new leads based on their country, industries, size, etc.")
|
||||
module_crm_iap_enrich = fields.Boolean("Enrich your leads automatically with company data based on their email address.")
|
||||
module_website_crm_iap_reveal = fields.Boolean("Create Leads/Opportunities from your website's traffic")
|
||||
lead_enrich_auto = fields.Selection([
|
||||
('manual', 'Enrich leads on demand only'),
|
||||
('auto', 'Enrich all leads automatically'),
|
||||
], string='Enrich lead automatically', default='auto', config_parameter='crm.iap.lead.enrich.setting')
|
||||
lead_mining_in_pipeline = fields.Boolean("Create a lead mining request directly from the opportunity pipeline.", config_parameter='crm.lead_mining_in_pipeline')
|
||||
predictive_lead_scoring_start_date = fields.Date(string='Lead Scoring Starting Date', compute="_compute_pls_start_date", inverse="_inverse_pls_start_date_str")
|
||||
predictive_lead_scoring_start_date_str = fields.Char(string='Lead Scoring Starting Date in String', config_parameter='crm.pls_start_date')
|
||||
predictive_lead_scoring_fields = fields.Many2many('crm.lead.scoring.frequency.field', string='Lead Scoring Frequency Fields', compute="_compute_pls_fields", inverse="_inverse_pls_fields_str")
|
||||
predictive_lead_scoring_fields_str = fields.Char(string='Lead Scoring Frequency Fields in String', config_parameter='crm.pls_fields')
|
||||
predictive_lead_scoring_field_labels = fields.Char(compute='_compute_predictive_lead_scoring_field_labels')
|
||||
|
||||
@api.depends('crm_use_auto_assignment')
|
||||
def _compute_crm_auto_assignment_data(self):
|
||||
assign_cron = self.sudo().env.ref('crm.ir_cron_crm_lead_assign', raise_if_not_found=False)
|
||||
for setting in self:
|
||||
if setting.crm_use_auto_assignment and assign_cron:
|
||||
setting.crm_auto_assignment_action = 'auto' if assign_cron.active else 'manual'
|
||||
setting.crm_auto_assignment_interval_type = assign_cron.interval_type or 'days'
|
||||
setting.crm_auto_assignment_interval_number = assign_cron.interval_number or 1
|
||||
setting.crm_auto_assignment_run_datetime = assign_cron.nextcall
|
||||
else:
|
||||
setting.crm_auto_assignment_action = 'manual'
|
||||
setting.crm_auto_assignment_interval_type = setting.crm_auto_assignment_run_datetime = False
|
||||
setting.crm_auto_assignment_interval_number = 1
|
||||
|
||||
@api.onchange('crm_auto_assignment_interval_type', 'crm_auto_assignment_interval_number')
|
||||
def _onchange_crm_auto_assignment_run_datetime(self):
|
||||
if self.crm_auto_assignment_interval_number <= 0:
|
||||
raise exceptions.UserError(_('Repeat frequency should be positive.'))
|
||||
elif self.crm_auto_assignment_interval_number >= 100:
|
||||
raise exceptions.UserError(_('Invalid repeat frequency. Consider changing frequency type instead of using large numbers.'))
|
||||
self.crm_auto_assignment_run_datetime = self._get_crm_auto_assignmment_run_datetime(
|
||||
self.crm_auto_assignment_run_datetime,
|
||||
self.crm_auto_assignment_interval_type,
|
||||
self.crm_auto_assignment_interval_number
|
||||
)
|
||||
|
||||
@api.depends('predictive_lead_scoring_fields_str')
|
||||
def _compute_pls_fields(self):
|
||||
""" As config_parameters does not accept m2m field,
|
||||
we get the fields back from the Char config field, to ease the configuration in config panel """
|
||||
for setting in self:
|
||||
if setting.predictive_lead_scoring_fields_str:
|
||||
names = setting.predictive_lead_scoring_fields_str.split(',')
|
||||
fields = self.env['ir.model.fields'].search([('name', 'in', names), ('model', '=', 'crm.lead')])
|
||||
setting.predictive_lead_scoring_fields = self.env['crm.lead.scoring.frequency.field'].search([('field_id', 'in', fields.ids)])
|
||||
else:
|
||||
setting.predictive_lead_scoring_fields = None
|
||||
|
||||
def _inverse_pls_fields_str(self):
|
||||
""" As config_parameters does not accept m2m field,
|
||||
we store the fields with a comma separated string into a Char config field """
|
||||
for setting in self:
|
||||
if setting.predictive_lead_scoring_fields:
|
||||
setting.predictive_lead_scoring_fields_str = ','.join(setting.predictive_lead_scoring_fields.mapped('field_id.name'))
|
||||
else:
|
||||
setting.predictive_lead_scoring_fields_str = ''
|
||||
|
||||
@api.depends('predictive_lead_scoring_start_date_str')
|
||||
def _compute_pls_start_date(self):
|
||||
""" As config_parameters does not accept Date field,
|
||||
we get the date back from the Char config field, to ease the configuration in config panel """
|
||||
for setting in self:
|
||||
lead_scoring_start_date = setting.predictive_lead_scoring_start_date_str
|
||||
# if config param is deleted / empty, set the date 8 days prior to current date
|
||||
if not lead_scoring_start_date:
|
||||
setting.predictive_lead_scoring_start_date = fields.Date.to_date(fields.Date.today() - timedelta(days=8))
|
||||
else:
|
||||
try:
|
||||
setting.predictive_lead_scoring_start_date = fields.Date.to_date(lead_scoring_start_date)
|
||||
except ValueError:
|
||||
# the config parameter is malformed, so set the date 8 days prior to current date
|
||||
setting.predictive_lead_scoring_start_date = fields.Date.to_date(fields.Date.today() - timedelta(days=8))
|
||||
|
||||
def _inverse_pls_start_date_str(self):
|
||||
""" As config_parameters does not accept Date field,
|
||||
we store the date formated string into a Char config field """
|
||||
for setting in self:
|
||||
if setting.predictive_lead_scoring_start_date:
|
||||
setting.predictive_lead_scoring_start_date_str = fields.Date.to_string(setting.predictive_lead_scoring_start_date)
|
||||
|
||||
@api.depends('predictive_lead_scoring_fields')
|
||||
def _compute_predictive_lead_scoring_field_labels(self):
|
||||
for setting in self:
|
||||
if setting.predictive_lead_scoring_fields:
|
||||
field_names = [_('Stage')] + [field.name for field in setting.predictive_lead_scoring_fields]
|
||||
setting.predictive_lead_scoring_field_labels = _('%s and %s', ', '.join(field_names[:-1]), field_names[-1])
|
||||
else:
|
||||
setting.predictive_lead_scoring_field_labels = _('Stage')
|
||||
|
||||
def set_values(self):
|
||||
group_use_lead_id = self.env['ir.model.data']._xmlid_to_res_id('crm.group_use_lead')
|
||||
has_group_lead_before = group_use_lead_id in self.env.user.groups_id.ids
|
||||
super(ResConfigSettings, self).set_values()
|
||||
# update use leads / opportunities setting on all teams according to settings update
|
||||
has_group_lead_after = group_use_lead_id in self.env.user.groups_id.ids
|
||||
if has_group_lead_before != has_group_lead_after:
|
||||
teams = self.env['crm.team'].search([])
|
||||
teams.filtered('use_opportunities').use_leads = has_group_lead_after
|
||||
for team in teams:
|
||||
team.alias_id.write(team._alias_get_creation_values())
|
||||
# synchronize cron with settings
|
||||
assign_cron = self.sudo().env.ref('crm.ir_cron_crm_lead_assign', raise_if_not_found=False)
|
||||
if assign_cron:
|
||||
# Writing on a cron tries to grab a write-lock on the table. This
|
||||
# could be avoided when saving a res.config without modifying this specific
|
||||
# configuration
|
||||
cron_vals = {
|
||||
'active': self.crm_use_auto_assignment and self.crm_auto_assignment_action == 'auto',
|
||||
'interval_type': self.crm_auto_assignment_interval_type,
|
||||
'interval_number': self.crm_auto_assignment_interval_number,
|
||||
# keep nextcall on cron as it is required whatever the setting
|
||||
'nextcall': self.crm_auto_assignment_run_datetime if self.crm_auto_assignment_run_datetime else assign_cron.nextcall,
|
||||
}
|
||||
cron_vals = {field_name: value for field_name, value in cron_vals.items() if assign_cron[field_name] != value}
|
||||
if cron_vals:
|
||||
assign_cron.write(cron_vals)
|
||||
# TDE FIXME: re create cron if not found ?
|
||||
|
||||
def _get_crm_auto_assignmment_run_datetime(self, run_datetime, run_interval, run_interval_number):
|
||||
if not run_interval:
|
||||
return False
|
||||
if run_interval == 'manual':
|
||||
return run_datetime if run_datetime else False
|
||||
return fields.Datetime.now() + relativedelta(**{run_interval: run_interval_number})
|
||||
|
||||
def action_crm_assign_leads(self):
|
||||
self.ensure_one()
|
||||
return self.env['crm.team'].search([('assignment_optout', '=', False)]).action_assign_leads(work_days=2, log=False)
|
78
models/res_partner.py
Normal file
78
models/res_partner.py
Normal file
|
@ -0,0 +1,78 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models
|
||||
from odoo.osv import expression
|
||||
|
||||
|
||||
|
||||
class Partner(models.Model):
|
||||
_name = 'res.partner'
|
||||
_inherit = 'res.partner'
|
||||
|
||||
team_id = fields.Many2one(
|
||||
'crm.team', string='Sales Team',
|
||||
compute='_compute_team_id',
|
||||
precompute=True, # avoid queries post-create
|
||||
ondelete='set null', readonly=False, store=True)
|
||||
opportunity_ids = fields.One2many('crm.lead', 'partner_id', string='Opportunities', domain=[('type', '=', 'opportunity')])
|
||||
opportunity_count = fields.Integer("Opportunity", compute='_compute_opportunity_count')
|
||||
|
||||
@api.model
|
||||
def default_get(self, fields):
|
||||
rec = super(Partner, self).default_get(fields)
|
||||
active_model = self.env.context.get('active_model')
|
||||
if active_model == 'crm.lead' and len(self.env.context.get('active_ids', [])) <= 1:
|
||||
lead = self.env[active_model].browse(self.env.context.get('active_id')).exists()
|
||||
if lead:
|
||||
rec.update(
|
||||
phone=lead.phone,
|
||||
mobile=lead.mobile,
|
||||
function=lead.function,
|
||||
title=lead.title.id,
|
||||
website=lead.website,
|
||||
street=lead.street,
|
||||
street2=lead.street2,
|
||||
city=lead.city,
|
||||
state_id=lead.state_id.id,
|
||||
country_id=lead.country_id.id,
|
||||
zip=lead.zip,
|
||||
)
|
||||
return rec
|
||||
|
||||
@api.depends('parent_id')
|
||||
def _compute_team_id(self):
|
||||
for partner in self.filtered(lambda partner: not partner.team_id and partner.company_type == 'person' and partner.parent_id.team_id):
|
||||
partner.team_id = partner.parent_id.team_id
|
||||
|
||||
def _compute_opportunity_count(self):
|
||||
# retrieve all children partners and prefetch 'parent_id' on them
|
||||
all_partners = self.with_context(active_test=False).search_fetch(
|
||||
[('id', 'child_of', self.ids)], ['parent_id'],
|
||||
)
|
||||
|
||||
opportunity_data = self.env['crm.lead'].with_context(active_test=False)._read_group(
|
||||
domain=[('partner_id', 'in', all_partners.ids)],
|
||||
groupby=['partner_id'], aggregates=['__count']
|
||||
)
|
||||
self_ids = set(self._ids)
|
||||
|
||||
self.opportunity_count = 0
|
||||
for partner, count in opportunity_data:
|
||||
while partner:
|
||||
if partner.id in self_ids:
|
||||
partner.opportunity_count += count
|
||||
partner = partner.parent_id
|
||||
|
||||
def action_view_opportunity(self):
|
||||
'''
|
||||
This function returns an action that displays the opportunities from partner.
|
||||
'''
|
||||
action = self.env['ir.actions.act_window']._for_xml_id('crm.crm_lead_opportunities')
|
||||
action['context'] = {}
|
||||
if self.is_company:
|
||||
action['domain'] = [('partner_id.commercial_partner_id', '=', self.id)]
|
||||
else:
|
||||
action['domain'] = [('partner_id', '=', self.id)]
|
||||
action['domain'] = expression.AND([action['domain'], [('active', 'in', [True, False])]])
|
||||
return action
|
11
models/res_users.py
Normal file
11
models/res_users.py
Normal file
|
@ -0,0 +1,11 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class Users(models.Model):
|
||||
_inherit = 'res.users'
|
||||
|
||||
target_sales_won = fields.Integer('Won in Opportunities Target')
|
||||
target_sales_done = fields.Integer('Activities Done Target')
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user