[IMP] mass_mailing: improve mass mailing stat buttons (domain/visibility)
Task #1907952 Purpose ======= The number of generated leads/opportunities from the mass mailing on the stat button should count both active and archived leads/opportunities. The stat buttons on mass mailing added by sales and crm apps should appear on every selected 'model' for the recipients (a mass mailing sent to 'leads' can generate sales). Specs ======= Opportunity stat button: - double check that the number is based on both leads or opportunities, active or archived Stat buttons Leads #, Quotations #, Invoice Amount should appear on the form all the time for showcase purposes closes odoo/odoo#29568
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
|
||||
from odoo import api, fields, models
|
||||
from odoo.osv import expression
|
||||
|
||||
|
||||
class MassMailing(models.Model):
|
||||
@@ -10,34 +11,31 @@ class MassMailing(models.Model):
|
||||
_inherit = 'mail.mass_mailing'
|
||||
|
||||
crm_lead_activated = fields.Boolean('Use Leads', compute='_compute_crm_lead_activated')
|
||||
crm_lead_count = fields.Integer('Lead Count', compute='_compute_crm_lead_count')
|
||||
crm_opportunities_count = fields.Integer('Opportunities Count', compute='_compute_crm_opportunities_count')
|
||||
crm_lead_count = fields.Integer('Lead Count', groups='sales_team.group_sale_salesman', compute='_compute_crm_lead_and_opportunities_count')
|
||||
crm_opportunities_count = fields.Integer('Opportunities Count', groups='sales_team.group_sale_salesman', compute='_compute_crm_lead_and_opportunities_count')
|
||||
|
||||
def _compute_crm_lead_activated(self):
|
||||
for mass_mailing in self:
|
||||
mass_mailing.crm_lead_activated = self.env.user.has_group('crm.group_use_lead')
|
||||
|
||||
@api.depends('crm_lead_activated')
|
||||
def _compute_crm_lead_count(self):
|
||||
for mass_mailing in self:
|
||||
if mass_mailing.crm_lead_activated:
|
||||
mass_mailing.crm_lead_count = self.env['crm.lead'].search_count(self._get_crm_utm_domain())
|
||||
else:
|
||||
mass_mailing.crm_lead_count = 0
|
||||
|
||||
@api.depends('crm_lead_activated')
|
||||
def _compute_crm_opportunities_count(self):
|
||||
def _compute_crm_lead_and_opportunities_count(self):
|
||||
for mass_mailing in self:
|
||||
lead_and_opportunities_count = mass_mailing.crm_lead_count = self.env['crm.lead'] \
|
||||
.with_context(active_test=False) \
|
||||
.search_count(self._get_crm_utm_domain())
|
||||
if mass_mailing.crm_lead_activated:
|
||||
mass_mailing.crm_lead_count = lead_and_opportunities_count
|
||||
mass_mailing.crm_opportunities_count = 0
|
||||
else:
|
||||
mass_mailing.crm_opportunities_count = self.env['crm.lead'].search_count(self._get_crm_utm_domain())
|
||||
mass_mailing.crm_lead_count = 0
|
||||
mass_mailing.crm_opportunities_count = lead_and_opportunities_count
|
||||
|
||||
@api.multi
|
||||
def action_redirect_to_leads(self):
|
||||
action = self.env.ref('crm.crm_lead_all_leads').read()[0]
|
||||
action['domain'] = self._get_crm_utm_domain()
|
||||
action['context'] = {'default_type': 'lead'}
|
||||
action['context'] = {'default_type': 'lead', 'active_test': False}
|
||||
return action
|
||||
|
||||
@api.multi
|
||||
@@ -45,16 +43,19 @@ class MassMailing(models.Model):
|
||||
action = self.env.ref('crm.crm_lead_opportunities').read()[0]
|
||||
action['view_mode'] = 'tree,kanban,graph,pivot,form,calendar'
|
||||
action['domain'] = self._get_crm_utm_domain()
|
||||
action['context'] = {'active_test': False}
|
||||
return action
|
||||
|
||||
def _get_crm_utm_domain(self):
|
||||
res = []
|
||||
""" We want all records that match the UTMs """
|
||||
domain = []
|
||||
if self.campaign_id:
|
||||
res.append(('campaign_id', '=', self.campaign_id.id))
|
||||
domain = expression.AND([domain, [('campaign_id', '=', self.campaign_id.id)]])
|
||||
if self.source_id:
|
||||
res.append(('source_id', '=', self.source_id.id))
|
||||
domain = expression.AND([domain, [('source_id', '=', self.source_id.id)]])
|
||||
if self.medium_id:
|
||||
res.append(('medium_id', '=', self.medium_id.id))
|
||||
if not res:
|
||||
res.append((0, '=', 1))
|
||||
return res
|
||||
domain = expression.AND([domain, [('medium_id', '=', self.medium_id.id)]])
|
||||
if not domain:
|
||||
domain = expression.AND([domain, [(0, '=', 1)]])
|
||||
|
||||
return domain
|
||||
|
||||
@@ -11,14 +11,16 @@
|
||||
type="object"
|
||||
icon="fa-star"
|
||||
class="oe_stat_button"
|
||||
attrs="{'invisible': ['|', '|', ('state', 'in', ('draft','test')), ('mailing_model_name', '!=', 'crm.lead'), ('crm_lead_activated', '=', False)]}" >
|
||||
groups="sales_team.group_sale_salesman"
|
||||
attrs="{'invisible': ['|', ('state', '=', 'draft'), ('crm_lead_activated', '=', False)]}" >
|
||||
<field name="crm_lead_count" string="Leads" widget="statinfo"/>
|
||||
</button>
|
||||
<button name="action_redirect_to_opportunities"
|
||||
type="object"
|
||||
icon="fa-star"
|
||||
class="oe_stat_button"
|
||||
attrs="{'invisible': ['|', '|', ('state', 'in', ('draft','test')), ('mailing_model_name', '!=', 'crm.lead'), ('crm_lead_activated', '=', True)]}" >
|
||||
groups="sales_team.group_sale_salesman"
|
||||
attrs="{'invisible': ['|', ('state', '=', 'draft'), ('crm_lead_activated', '=', True)]}" >
|
||||
<field name="crm_opportunities_count" string="Opportunities" widget="statinfo"/>
|
||||
</button>
|
||||
</xpath>
|
||||
|
||||
@@ -9,8 +9,8 @@ class MassMailing(models.Model):
|
||||
_name = 'mail.mass_mailing'
|
||||
_inherit = 'mail.mass_mailing'
|
||||
|
||||
sale_quotation_count = fields.Integer('Quotation Count', compute='_compute_sale_quotation_count')
|
||||
sale_invoiced_amount = fields.Integer('Invoiced Amount', compute='_compute_sale_invoiced_amount')
|
||||
sale_quotation_count = fields.Integer('Quotation Count', groups='sales_team.group_sale_salesman', compute='_compute_sale_quotation_count')
|
||||
sale_invoiced_amount = fields.Integer('Invoiced Amount', groups='sales_team.group_sale_salesman', compute='_compute_sale_invoiced_amount')
|
||||
|
||||
@api.depends('mailing_domain')
|
||||
def _compute_sale_quotation_count(self):
|
||||
@@ -25,7 +25,10 @@ class MassMailing(models.Model):
|
||||
for mass_mailing in self:
|
||||
if has_so_access and has_invoice_report_access:
|
||||
invoices = self.env['sale.order'].search(self._get_sale_utm_domain()).mapped('invoice_ids')
|
||||
res = self.env['account.invoice.report'].search_read([('invoice_id', 'in', invoices.ids)], ['user_currency_price_total'])
|
||||
res = self.env['account.invoice.report'].search_read(
|
||||
[('invoice_id', 'in', invoices.ids), ('state', 'not in', ['draft', 'cancel'])],
|
||||
['user_currency_price_total']
|
||||
)
|
||||
mass_mailing.sale_invoiced_amount = sum(r['user_currency_price_total'] for r in res)
|
||||
else:
|
||||
mass_mailing.sale_invoiced_amount = 0
|
||||
@@ -43,7 +46,6 @@ class MassMailing(models.Model):
|
||||
invoices = self.env['sale.order'].search(self._get_sale_utm_domain()).mapped('invoice_ids')
|
||||
action['domain'] = [
|
||||
('id', 'in', invoices.ids),
|
||||
('type', 'in', ['out_invoice', 'out_refund']),
|
||||
('state', 'not in', ['draft', 'cancel'])
|
||||
]
|
||||
return action
|
||||
|
||||
@@ -10,14 +10,16 @@
|
||||
type="object"
|
||||
icon="fa-usd"
|
||||
class="oe_stat_button"
|
||||
attrs="{'invisible': ['|', ('state', 'in', ('draft','test')), ('mailing_model_name', '!=', 'sale.order')]}" >
|
||||
groups="sales_team.group_sale_salesman"
|
||||
attrs="{'invisible': [('state', '=', 'draft')]}">
|
||||
<field name="sale_quotation_count" string="Quotations" widget="statinfo"/>
|
||||
</button>
|
||||
<button name="action_redirect_to_invoiced"
|
||||
type="object"
|
||||
icon="fa-money"
|
||||
class="oe_stat_button"
|
||||
attrs="{'invisible': ['|', ('state', 'in', ('draft','test')), ('mailing_model_name', '!=', 'sale.order')]}" >
|
||||
groups="sales_team.group_sale_salesman"
|
||||
attrs="{'invisible': [('state', '=', 'draft')]}" >
|
||||
<field name="sale_invoiced_amount" string="Invoiced" widget="statinfo"/>
|
||||
</button>
|
||||
</xpath>
|
||||
|
||||
Reference in New Issue
Block a user