Skip to content

Commit

Permalink
[IMP] mass_mailing_sale: remove complex computation of invoices linke…
Browse files Browse the repository at this point in the history
…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 account.invoice.report

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) <tde@openerp.com>
  • Loading branch information
hbh-odoo authored and tde-banana-odoo committed Aug 19, 2019
1 parent be983c7 commit bc6accc
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions addons/mass_mailing_sale/models/mass_mailing.py
Expand Up @@ -20,16 +20,11 @@ def _compute_sale_quotation_count(self):

@api.depends('mailing_domain')
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['account.invoice.report'].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['account.invoice.report'].search_read(
[('move_id', 'in', invoices.ids), ('state', 'not in', ['draft', 'cancel'])],
['price_subtotal']
)
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)
else:
mass_mailing.sale_invoiced_amount = 0

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

@api.multi
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', self.id),
('state', 'not in', ['draft', 'cancel']),
]
return action

Expand Down

0 comments on commit bc6accc

Please sign in to comment.