Skip to content
Browse files

[IMP] mass_mailing_sale: remove complex computation of invoices linke…

…d to mailing UTM

UTM fields are available in the invoice without sale_crm. That's why just apply
search_read on account.move instead of doing

--> search on sale order
--> map on invoice_ids which is computed
--> search_read on

to get sale_invoiced_amount.

Currently, stat button 'Invoiced' is not redirecting to invoices tree
view because of wrong action and domain parameters. Thus we, set proper
action and pass valid parameter to get that invoices tree view.

Task 1919391

closes #35296

Signed-off-by: Thibault Delavallee (tde) <>
  • Loading branch information...
hbh-odoo authored and tde-banana-odoo committed Jul 30, 2019
1 parent be983c7 commit bc6accc5688d3c38a35949751779f808e9c2063f
Showing with 8 additions and 14 deletions.
  1. +8 −14 addons/mass_mailing_sale/models/
@@ -20,16 +20,11 @@ def _compute_sale_quotation_count(self):

def _compute_sale_invoiced_amount(self):
has_so_access = self.env['sale.order'].check_access_rights('read', raise_exception=False)
has_invoice_report_access = self.env[''].check_access_rights('read', raise_exception=False)
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[''].search_read(
[('move_id', 'in', invoices.ids), ('state', 'not in', ['draft', 'cancel'])],
mass_mailing.sale_invoiced_amount = sum(r['price_subtotal'] for r in res)
if self.user_has_groups('sales_team.group_sale_salesman') and self.user_has_groups('account.group_account_invoice'):
domain = self._get_sale_utm_domain() + [('state', 'not in', ['draft', 'cancel'])]
moves = self.env['account.move'].search_read(domain, ['amount_untaxed'])
mass_mailing.sale_invoiced_amount = sum(i['amount_untaxed'] for i in moves)
mass_mailing.sale_invoiced_amount = 0

@@ -42,13 +37,12 @@ def action_redirect_to_quotations(self):

def action_redirect_to_invoiced(self):
action = self.env.ref('account.view_move_form').read()[0]
invoices = self.env['sale.order'].search(self._get_sale_utm_domain()).mapped('invoice_ids')
action = self.env.ref('account.action_move_out_invoice_type').read()[0]
moves = self.env['account.move'].search(self._get_sale_utm_domain())
action['domain'] = [
('id', 'in', invoices.ids),
('id', 'in', moves.ids),
('type', 'in', ('out_invoice', 'out_refund')),
('type', '=', 'posted'),
('partner_id', 'child_of',,
('state', 'not in', ['draft', 'cancel']),
return action

0 comments on commit bc6accc

Please sign in to comment.
You can’t perform that action at this time.