[FIX] crm, sale: safe override of sales team

The user can delete teams created during the installation of the Sale
Team module, both CRM and Sale modify those teams but the way they
modify the teams doesn't take their deletion into account.

opw-1962297

closes odoo/odoo#32412

Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
This commit is contained in:
Julien Castiaux
2019-04-08 13:42:52 +00:00
parent 8d97b3b6fc
commit 30a848bffb
7 changed files with 30 additions and 18 deletions
+18
View File
@@ -13,3 +13,21 @@ def uninstall_hook(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {})
teams = env['crm.team'].search([('dashboard_graph_model', '=', 'crm.opportunity.report')])
teams.update({'dashboard_graph_model': None})
def _update_sale_teams(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {})
sale_team = env.ref('sales_team.team_sales_department', False)
ws_team = env.ref('sales_team.salesteam_website_sales', False)
teams = [team for team in [sale_team, ws_team] if team]
if teams:
env['crm.team'].message_unsubscribe(teams, [env.ref('base.partner_root')])
env['crm.team'].message_subscribe(teams, [env.ref('base.partner_root')])
if sale_team:
sale_team.write({
'use_opportunities': True,
'alias_name': 'sales',
'dashboard_graph_model': 'crm.lead',
})
+1
View File
@@ -56,4 +56,5 @@
'application': True,
'auto_install': False,
'uninstall_hook': 'uninstall_hook',
'post_init_hook': '_update_sale_teams',
}
-7
View File
@@ -1,13 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<record id="sales_team.team_sales_department" model="crm.team">
<field name="use_opportunities">True</field>
<field name="alias_name">sales</field>
<field name="dashboard_graph_model">crm.lead</field>
<field name="company_id" eval="False"/>
</record>
<!--default alias for leads-->
<record id="mail_alias_lead_info" model="mail.alias">
<field name="alias_name"></field>
-5
View File
@@ -60,11 +60,6 @@
<field name="relation_field">team_id</field>
</record>
<function model="crm.team" name="message_unsubscribe"
eval="[ref('sales_team.team_sales_department'),ref('sales_team.salesteam_website_sales')], [ref('base.partner_root')]"/>
<function model="crm.team" name="message_subscribe"
eval="[ref('sales_team.team_sales_department'),ref('sales_team.salesteam_website_sales')], [ref('base.partner_root')]"/>
<!--Definition of an email template with an empty body that will be used in opportunity mailing.
Used to give a basis for email recipients, name and to ease the definition of a further
elaborated template. -->
+10
View File
@@ -22,3 +22,13 @@ def uninstall_hook(cr, registry):
rec._onchange_team_type()
cr.after("commit", partial(update_dashboard_graph_model, cr.dbname))
def _update_sale_teams(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {})
sale_team = env.ref('sales_team.team_sales_department', False)
if sale_team:
sale_team.write({
'use_quotations': True,
'use_invoices': True,
'dashboard_graph_model': 'sale.report'
})
+1
View File
@@ -40,6 +40,7 @@ This module contains all the common features of Sales Management and eCommerce.
'data/product_product_demo.xml',
],
'uninstall_hook': "uninstall_hook",
'post_init_hook': '_update_sale_teams',
'installable': True,
'auto_install': False
}
-6
View File
@@ -1,12 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<record model="crm.team" id="sales_team.team_sales_department">
<field name="use_quotations" eval="True"/>
<field name="use_invoices" eval="True"/>
<field name="dashboard_graph_model">sale.report</field>
</record>
<!-- Share Button in action menu -->
<record id="model_sale_order_action_share" model="ir.actions.server">
<field name="name">Share</field>