diff --git a/addons/mass_mailing_sale/__init__.py b/addons/mass_mailing_sale/__init__.py new file mode 100644 index 00000000000..dc5e6b693d1 --- /dev/null +++ b/addons/mass_mailing_sale/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import models diff --git a/addons/mass_mailing_sale/__manifest__.py b/addons/mass_mailing_sale/__manifest__.py new file mode 100644 index 00000000000..e241e12f7b8 --- /dev/null +++ b/addons/mass_mailing_sale/__manifest__.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +{ + 'name': 'Mass mailing on sale orders', + 'category': 'Hidden', + 'version': '1.0', + 'summary': 'Add sale order UTM info on mass mailing', + 'description': """UTM and mass mailing on sale orders""", + 'depends': ['sale', 'mass_mailing', 'website_sale_link_tracker'], + 'data': [ + 'views/mass_mailing_views.xml', + ], + 'demo': [ + 'data/mass_mailing_demo.xml', + ], + 'auto_install': True, +} diff --git a/addons/mass_mailing_sale/data/mass_mailing_demo.xml b/addons/mass_mailing_sale/data/mass_mailing_demo.xml new file mode 100644 index 00000000000..0d6110a40bf --- /dev/null +++ b/addons/mass_mailing_sale/data/mass_mailing_demo.xml @@ -0,0 +1,78 @@ + + + + + Sale Newsletter + in_queue + + + + + + + [] + email + ${object.company_id.email} + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+ Hello
+ + ${object.name} + +
+ ${object.company_id.name} +
+
+
+
+

Dear ${object.name}

+

Great stories have personality. Consider telling a great story that provides personality. Writing a story with personality for potential clients will assist with making a relationship connection. This shows up in small quirks like word choices or phrases. Write from your point of view, not from someone else's experience.

+

Great stories are for everyone even when only written for just one person. If you try to write with a wide general audience in mind, your story will ring false and be bland. No one will be interested. Write for one person. If it’s genuine for the one, it’s genuine for the rest.

+
+
+ ${object.company_id.name}
+
+ ${object.company_id.phone} + % if object.company_id.email + | + + ${object.company_id.email} + + % endif + ${object.company_id.website} + | + + ${object.company_id.website} + + % endif +
+
+
+ Powered by Odoo +
+
+
+
\ No newline at end of file diff --git a/addons/mass_mailing_sale/models/__init__.py b/addons/mass_mailing_sale/models/__init__.py new file mode 100644 index 00000000000..972aef5812b --- /dev/null +++ b/addons/mass_mailing_sale/models/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import mass_mailing diff --git a/addons/mass_mailing_sale/models/mass_mailing.py b/addons/mass_mailing_sale/models/mass_mailing.py new file mode 100644 index 00000000000..a04db461d7f --- /dev/null +++ b/addons/mass_mailing_sale/models/mass_mailing.py @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + + +from odoo import api, fields, models + + +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') + + @api.depends('mailing_domain') + def _compute_sale_quotation_count(self): + for mass_mailing in self: + if mass_mailing.mailing_model_name != 'sale.order': + mass_mailing.sale_quotation_count = 0 + else: + mass_mailing.sale_quotation_count = self.env['sale.order'].search_count(self._get_sale_utm_domain()) + + @api.depends('mailing_domain') + def _compute_sale_invoiced_amount(self): + for mass_mailing in self: + if mass_mailing.mailing_model_name != 'sale.order': + mass_mailing.sale_invoiced_amount = 0 + else: + 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']) + mass_mailing.sale_invoiced_amount = sum(r['user_currency_price_total'] for r in res) + + @api.multi + def action_redirect_to_quotations(self): + action = self.env.ref('sale.action_quotations_with_onboarding').read()[0] + action['domain'] = self._get_sale_utm_domain() + action['context'] = {'default_type': 'lead'} + return action + + @api.multi + def action_redirect_to_invoiced(self): + action = self.env.ref('account.action_invoice_refund_out_tree').read()[0] + 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 + + def _get_sale_utm_domain(self): + res = [] + if self.campaign_id: + res.append(('campaign_id', '=', self.campaign_id.id)) + if self.source_id: + res.append(('source_id', '=', self.source_id.id)) + if self.medium_id: + res.append(('medium_id', '=', self.medium_id.id)) + if not res: + res.append(('1', '=', '0')) + return res diff --git a/addons/mass_mailing_sale/views/mass_mailing_views.xml b/addons/mass_mailing_sale/views/mass_mailing_views.xml new file mode 100644 index 00000000000..40a2b9ad0ce --- /dev/null +++ b/addons/mass_mailing_sale/views/mass_mailing_views.xml @@ -0,0 +1,26 @@ + + + + mail.mass_mailing.view.form.inherit.sale + mail.mass_mailing + + + + + + + + + \ No newline at end of file