From fd4798195d0d2d2c72a779dbceca4a63205c6421 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9my=20Baranx=20=28bar=29?=
Date: Thu, 5 Mar 2020 13:09:39 +0000
Subject: [PATCH] [IMP] crm, sales: add crm tags on sale orders
As the crm.lead.tags model shall be used in CRM and/or Sales apps,
it has been moved to the sales_team module, which is a depedency
of the CRM and Sales apps.
As these tags becomes more generic than just "lead tags", the model
has been renamed from crm.lead.tags to crm.tags.
Tags on sale orders were already present but not visible. They are
now visible in the "Other Info" section, and optionally in sale order
tree views.
When a quotation is created from an opportunity (CRM app), existing tags
are populated from the opportunity to the sale order (Sales app).
Views and demo data of several modules have been updated accordingly.
Task ID 2191276
---
addons/crm/data/crm_lead_demo.xml | 123 +++++++-----------
addons/crm/models/__init__.py | 1 -
addons/crm/models/crm_lead.py | 10 +-
addons/crm/security/ir.model.access.csv | 3 -
addons/crm/views/crm_lead_views.xml | 54 +-------
.../models/crm_iap_lead_mining_request.py | 2 +-
.../models/crm_reveal_rule.py | 2 +-
addons/sale/models/sale.py | 1 +
addons/sale/views/sale_views.xml | 12 +-
addons/sale_crm/models/crm_lead.py | 1 +
addons/sale_crm/models/sale_order.py | 1 -
addons/sale_crm/views/sale_order_views.xml | 22 ----
addons/sales_team/__manifest__.py | 5 +-
addons/sales_team/data/crm_tag_demo.xml | 39 ++++++
addons/sales_team/models/__init__.py | 1 +
.../models/crm_tag.py} | 4 +-
.../sales_team/security/ir.model.access.csv | 3 +
addons/sales_team/views/crm_tag_views.xml | 54 ++++++++
.../data/crm_lead_demo.xml | 2 +-
.../data/crm_partner_assign_data.xml | 6 +-
20 files changed, 172 insertions(+), 174 deletions(-)
create mode 100644 addons/sales_team/data/crm_tag_demo.xml
rename addons/{crm/models/crm_lead_tag.py => sales_team/models/crm_tag.py} (86%)
create mode 100644 addons/sales_team/views/crm_tag_views.xml
diff --git a/addons/crm/data/crm_lead_demo.xml b/addons/crm/data/crm_lead_demo.xml
index 10f47973e20..e1b3c7edf1d 100644
--- a/addons/crm/data/crm_lead_demo.xml
+++ b/addons/crm/data/crm_lead_demo.xml
@@ -1,41 +1,6 @@
-
-
-
- Product
-
-
-
- Software
-
-
-
- Services
-
-
-
- Information
-
-
-
- Design
-
-
-
- Training
-
-
-
- Consulting
-
-
-
- Other
-
-
-
@@ -50,7 +15,7 @@
93190
Rue Léon Dierx 73
+33 1 25 54 45 69
-
+
1
@@ -86,7 +51,7 @@
33000
Rue Ignasse Blanchoux 214/32
+33 1 25 54 45 69
-
+
1
@@ -119,7 +84,7 @@
10001
Lafayette Ave 450/12
+1 555 754 3010
-
+
2
@@ -141,7 +106,7 @@
Manchester
03101
United Street 68
-
+
2
@@ -165,7 +130,7 @@
1909
West Allegheny Ave 800
+1 813 494 5005
-
+
2
@@ -204,7 +169,7 @@ Contact: +1 813 494 5005
]]>
Roma
00118
-
+
2
@@ -226,7 +191,7 @@ Contact: +1 813 494 5005]]>
29000
R. Sen. Pompeu
+11 55 21 5555 5555
-
+
0
@@ -247,7 +212,7 @@ Contact: +1 813 494 5005]]>
London
E1AB
-
+
1
@@ -282,7 +247,7 @@ ESM Expert
]]>
Oxford
OX1 1RQ
-
+
2
@@ -303,7 +268,7 @@ ESM Expert
]]>
Madrid
28001
-
+
2
@@ -338,7 +303,7 @@ Andrew]]>
Wavre
1300
-
+
2
@@ -358,7 +323,7 @@ Andrew]]>
Shenzhen
-
+
2
@@ -386,7 +351,7 @@ Andrew]]>
Melbourne
Kensington Road 189
-
+
1
@@ -412,7 +377,7 @@ Andrew]]>
1300
Rue de Namur 69
+32 10 588 558
-
+
2
@@ -435,7 +400,7 @@ Andrew]]>
Wavre
Rue de Namur 69
+32 10 588 558
-
+
1
@@ -528,7 +493,7 @@ Andrew]]>
Liverpool
L25 4RL
Union Road
-
+
2
@@ -553,7 +518,7 @@ Andrew]]>
Brussels
1100
Rue des Palais 51, bte 33
-
+
1
@@ -586,7 +551,7 @@ Andrew]]>
3661 Station Street
-
+
1
@@ -636,7 +601,7 @@ Andrew]]>
3rd Floor, Room 3-C,
Carretera Panamericana, Km 1, Urb. Delgado Chalbaud
+58 212 681 0538
-
+
1
@@ -661,7 +626,7 @@ Andrew]]>
60610
Chicago
+1 312 349 2324
-
+
2
@@ -681,7 +646,7 @@ Andrew]]>
Birmingham
B46 3AG
Cannon Hill Park
-
+
2
@@ -700,7 +665,7 @@ Andrew]]>
Benjamin Flores
Nebula Business
-
+
1
@@ -718,7 +683,7 @@ Andrew]]>
80.0
0
-
+
@@ -737,7 +702,7 @@ Andrew]]>
Lima
0
-
+
@@ -761,7 +726,7 @@ Andrew]]>
Palermo, Capital Federal
C1414CMS Capital Federal
2
-
+
@@ -784,7 +749,7 @@ Andrew]]>
Wavre
1300
2
-
+
@@ -808,7 +773,7 @@ Andrew]]>
1300
Rue de Namur 69
2
-
+
@@ -832,7 +797,7 @@ Andrew]]>
1300
Rue de Namur 69
0
-
+
@@ -852,7 +817,7 @@ Andrew]]>
93190
Rue Léon Dierx 73
+33 1 25 54 45 69
-
+
1
@@ -874,7 +839,7 @@ Andrew]]>
1080
Rue du Commerce 93
+32 22 33 54 07
-
+
1
@@ -894,7 +859,7 @@ Andrew]]>
Chevy Chase
1920 Del Dew Drive
-
+
1
@@ -916,7 +881,7 @@ Andrew]]>
Chevy Chase
1920 Del Dew Drive
-
+
1
@@ -937,7 +902,7 @@ Andrew]]>
max123@itconsult.com
Milan
-
+
1
@@ -957,7 +922,7 @@ Andrew]]>
London
1 Russel square
-
+
1
@@ -977,7 +942,7 @@ Andrew]]>
roxshott9@trellian.com
Canguaretama
-
+
1
@@ -996,7 +961,7 @@ Andrew]]>
mlimprecht8@fastcompany.com
Valejas
-
+
1
@@ -1016,7 +981,7 @@ Andrew]]>
akalinovich7@tinypic.com
Boafeo
-
+
1
@@ -1036,7 +1001,7 @@ Andrew]]>
jjobbins6@simplemachines.org
Gvardeysk
-
+
1
@@ -1056,7 +1021,7 @@ Andrew]]>
eespinazo5@reuters.com
Amsterdam
-
+
1
@@ -1076,7 +1041,7 @@ Andrew]]>
credford4@salon.com
Odoyev
-
+
1
@@ -1098,7 +1063,7 @@ Andrew]]>
ikirvell3@gnu.org
Dahu Satu
-
+
1
@@ -1118,7 +1083,7 @@ Andrew]]>
ngrabert2@dailymail.co.uk
Tokyo
-
+
1
@@ -1138,7 +1103,7 @@ Andrew]]>
fseiller1@theglobeandmail.com
Wurigelebur
-
+
1
@@ -1159,7 +1124,7 @@ Andrew]]>
tbrockhouse0@google.pl
Brussels
-
+
1
diff --git a/addons/crm/models/__init__.py b/addons/crm/models/__init__.py
index dcc76fd80f9..ebd90b6419b 100644
--- a/addons/crm/models/__init__.py
+++ b/addons/crm/models/__init__.py
@@ -4,7 +4,6 @@
from . import res_users
from . import calendar
from . import crm_lead
-from . import crm_lead_tag
from . import crm_lost_reason
from . import crm_stage
from . import crm_team
diff --git a/addons/crm/models/crm_lead.py b/addons/crm/models/crm_lead.py
index 58fc27f7eca..d8fce1f43c8 100644
--- a/addons/crm/models/crm_lead.py
+++ b/addons/crm/models/crm_lead.py
@@ -98,7 +98,7 @@ class Lead(models.Model):
('grey', 'No next activity planned'), ('red', 'Next activity late'), ('green', 'Next activity is planned')],
string='Kanban State', compute='_compute_kanban_state')
tag_ids = fields.Many2many(
- 'crm.lead.tag', 'crm_lead_tag_rel', 'lead_id', 'tag_id', string='Tags',
+ 'crm.tag', 'crm_tag_rel', 'lead_id', 'tag_id', string='Tags',
help="Classify and analyze your lead/opportunity categories like: Training, Service")
color = fields.Integer('Color Index', default=0)
# Opportunity specific
@@ -1526,8 +1526,8 @@ class Lead(models.Model):
# get all tag_ids won / lost count
self.flush(['probability', 'active'])
query = """select l.probability, l.active, t.id, count(l.probability) as count
- from crm_lead_tag_rel rel
- inner join crm_lead_tag t on rel.tag_id = t.id
+ from crm_tag_rel rel
+ inner join crm_tag t on rel.tag_id = t.id
inner join crm_lead l on l.id = rel.lead_id
where (l.probability = 0 or l.probability >= 100)
and l.create_date > %%s
@@ -1590,8 +1590,8 @@ class Lead(models.Model):
query = """SELECT l.id as lead_id, t.id as tag_id
FROM crm_lead l
- LEFT JOIN crm_lead_tag_rel rel ON l.id = rel.lead_id
- LEFT JOIN crm_lead_tag t ON rel.tag_id = t.id
+ LEFT JOIN crm_tag_rel rel ON l.id = rel.lead_id
+ LEFT JOIN crm_tag t ON rel.tag_id = t.id
WHERE ((l.probability > 0 AND l.probability < 100) OR l.probability is null) AND l.active = True AND l.id in %s order by l.team_id asc"""
self._cr.execute(query, [tuple(self.ids)])
tag_results = self._cr.dictfetchall()
diff --git a/addons/crm/security/ir.model.access.csv b/addons/crm/security/ir.model.access.csv
index 6930fe946b8..a5c66314e71 100644
--- a/addons/crm/security/ir.model.access.csv
+++ b/addons/crm/security/ir.model.access.csv
@@ -8,9 +8,6 @@ access_res_partner_category_manager,res.partner.category.crm.manager,base.model_
access_res_partner,res.partner.crm.user,base.model_res_partner,sales_team.group_sale_salesman,1,1,1,0
access_res_partner_category,res.partner.category.crm.user,base.model_res_partner_category,sales_team.group_sale_salesman,1,1,1,0
access_crm_lead_partner_manager,crm.lead.partner.manager,model_crm_lead,base.group_partner_manager,1,0,0,0
-access_crm_lead_tag,crm_lead_tag,model_crm_lead_tag,base.group_user,1,0,0,0
-access_crm_lead_tag_salesman,crm_lead_tag salesman,model_crm_lead_tag,sales_team.group_sale_salesman,1,1,1,0
-access_crm_lead_tag_manager,crm_lead_tag manager,model_crm_lead_tag,sales_team.group_sale_manager,1,1,1,1
access_crm_lost_reason_manager,crm.lost.reason.manager,model_crm_lost_reason,sales_team.group_sale_manager,1,1,1,1
access_crm_lost_reason_salesman,crm.lost.reason.salesman,model_crm_lost_reason,sales_team.group_sale_salesman,1,0,0,0
access_crm_lost_reason_user,crm.lost.reason.user,model_crm_lost_reason,base.group_user,1,0,0,0
diff --git a/addons/crm/views/crm_lead_views.xml b/addons/crm/views/crm_lead_views.xml
index 8fcb9d30be1..c3d618f7cc9 100644
--- a/addons/crm/views/crm_lead_views.xml
+++ b/addons/crm/views/crm_lead_views.xml
@@ -1,43 +1,5 @@
-
-
- crm.lead.tag.form
- crm.lead.tag
-
-
-
-
-
-
- crm.lead.tag.tree
- crm.lead.tag
-
-
-
-
-
-
-
-
crm.lead.form
crm.lead
@@ -954,24 +916,10 @@ if record:
name="CRM"
action="action_your_pipeline"/>
-
-
- Tags
- crm.lead.tag
-
-
-
- Create new tags for your opportunities
-
- Create tags that fit your business (product structure, sales type, etc.) to better manage and track your opportunities.
-
-
-
-
diff --git a/addons/crm_iap_lead/models/crm_iap_lead_mining_request.py b/addons/crm_iap_lead/models/crm_iap_lead_mining_request.py
index 8c996e2fdc6..7ab2477f014 100644
--- a/addons/crm_iap_lead/models/crm_iap_lead_mining_request.py
+++ b/addons/crm_iap_lead/models/crm_iap_lead_mining_request.py
@@ -40,7 +40,7 @@ class CRMLeadMiningRequest(models.Model):
lead_type = fields.Selection([('lead', 'Lead'), ('opportunity', 'Opportunity')], string='Type', required=True, default=_default_lead_type)
team_id = fields.Many2one('crm.team', string='Sales Team', domain="[('use_opportunities', '=', True)]")
user_id = fields.Many2one('res.users', string='Salesperson')
- tag_ids = fields.Many2many('crm.lead.tag', string='Tags')
+ tag_ids = fields.Many2many('crm.tag', string='Tags')
lead_ids = fields.One2many('crm.lead', 'lead_mining_request_id', string='Generated Lead / Opportunity')
leads_count = fields.Integer(compute='_compute_leads_count', string='Number of Generated Leads')
diff --git a/addons/crm_iap_lead_website/models/crm_reveal_rule.py b/addons/crm_iap_lead_website/models/crm_reveal_rule.py
index 36f8cc7e5b5..671aa6be16a 100644
--- a/addons/crm_iap_lead_website/models/crm_reveal_rule.py
+++ b/addons/crm_iap_lead_website/models/crm_reveal_rule.py
@@ -53,7 +53,7 @@ class CRMRevealRule(models.Model):
lead_type = fields.Selection([('lead', 'Lead'), ('opportunity', 'Opportunity')], string='Type', required=True, default='opportunity')
suffix = fields.Char(string='Suffix', help='This will be appended in name of generated lead so you can identify lead/opportunity is generated with this rule')
team_id = fields.Many2one('crm.team', string='Sales Team')
- tag_ids = fields.Many2many('crm.lead.tag', string='Tags')
+ tag_ids = fields.Many2many('crm.tag', string='Tags')
user_id = fields.Many2one('res.users', string='Salesperson')
priority = fields.Selection(crm_stage.AVAILABLE_PRIORITIES, string='Priority')
lead_ids = fields.One2many('crm.lead', 'reveal_rule_id', string='Generated Lead / Opportunity')
diff --git a/addons/sale/models/sale.py b/addons/sale/models/sale.py
index 65d5fda54c7..ca0b98ef8e0 100644
--- a/addons/sale/models/sale.py
+++ b/addons/sale/models/sale.py
@@ -251,6 +251,7 @@ class SaleOrder(models.Model):
show_update_pricelist = fields.Boolean(string='Has Pricelist Changed',
help="Technical Field, True if the pricelist was changed;\n"
" this will then display a recomputation button")
+ tag_ids = fields.Many2many('crm.tag', 'sale_order_tag_rel', 'order_id', 'tag_id', string='Tags')
_sql_constraints = [
('date_order_conditional_required', "CHECK( (state IN ('sale', 'done') AND date_order IS NOT NULL) OR state NOT IN ('sale', 'done') )", "A confirmed sales order requires a confirmation date."),
diff --git a/addons/sale/views/sale_views.xml b/addons/sale/views/sale_views.xml
index 5d08a7c03c3..87f5052b561 100644
--- a/addons/sale/views/sale_views.xml
+++ b/addons/sale/views/sale_views.xml
@@ -51,9 +51,16 @@
+
+
Products
ir.actions.act_window
@@ -202,6 +209,7 @@
+
@@ -229,6 +237,7 @@
+
@@ -653,6 +662,7 @@
+
diff --git a/addons/sale_crm/models/crm_lead.py b/addons/sale_crm/models/crm_lead.py
index 56ca8677d3f..1a2d8374318 100644
--- a/addons/sale_crm/models/crm_lead.py
+++ b/addons/sale_crm/models/crm_lead.py
@@ -81,6 +81,7 @@ class CrmLead(models.Model):
'default_origin': self.name,
'default_source_id': self.source_id.id,
'default_company_id': self.company_id.id or self.env.company.id,
+ 'default_tag_ids': [(6, 0, self.tag_ids.ids)]
}
return action
diff --git a/addons/sale_crm/models/sale_order.py b/addons/sale_crm/models/sale_order.py
index 6d5f4fe265e..81ce2154f4a 100644
--- a/addons/sale_crm/models/sale_order.py
+++ b/addons/sale_crm/models/sale_order.py
@@ -7,7 +7,6 @@ from odoo import fields, models
class SaleOrder(models.Model):
_inherit = 'sale.order'
- tag_ids = fields.Many2many('crm.lead.tag', 'sale_order_tag_rel', 'order_id', 'tag_id', string='Tags')
opportunity_id = fields.Many2one(
'crm.lead', string='Opportunity', check_company=True,
domain="[('type', '=', 'opportunity'), '|', ('company_id', '=', False), ('company_id', '=', company_id)]")
diff --git a/addons/sale_crm/views/sale_order_views.xml b/addons/sale_crm/views/sale_order_views.xml
index 9ecfa1897c0..2cacb40bd73 100644
--- a/addons/sale_crm/views/sale_order_views.xml
+++ b/addons/sale_crm/views/sale_order_views.xml
@@ -20,28 +20,6 @@
-
- sale.order.tree.inherit.sale.crm
- sale.order
-
-
-
-
-
-
-
-
-
- sale.order.tree.inherit.sale.crm
- sale.order
-
-
-
-
-
-
-
-