diff --git a/addons/website_sale/__manifest__.py b/addons/website_sale/__manifest__.py index 716190ba..b88a1e5a 100644 --- a/addons/website_sale/__manifest__.py +++ b/addons/website_sale/__manifest__.py @@ -14,6 +14,7 @@ 'data/data.xml', 'data/web_planner_data.xml', 'data/mail_template_data.xml', + 'data/ir_cron_view.xml', 'views/product_views.xml', 'views/account_views.xml', 'views/sale_report_views.xml', diff --git a/addons/website_sale/data/ir_cron_view.xml b/addons/website_sale/data/ir_cron_view.xml new file mode 100644 index 00000000..7cd47f00 --- /dev/null +++ b/addons/website_sale/data/ir_cron_view.xml @@ -0,0 +1,14 @@ + + + + eCommerce: Cart Recovery Email Cron + + code + model.send_cart_recovery_mail() + 1 + hours + -1 + + + + \ No newline at end of file diff --git a/addons/website_sale/models/res_config_settings.py b/addons/website_sale/models/res_config_settings.py index a0ffad78..5f127cdd 100644 --- a/addons/website_sale/models/res_config_settings.py +++ b/addons/website_sale/models/res_config_settings.py @@ -72,6 +72,8 @@ class ResConfigSettings(models.TransientModel): cart_recovery_mail_template = literal_eval(params.get_param('website_sale.cart_recovery_mail_template_id', default='False')) if cart_recovery_mail_template and not self.env['mail.template'].browse(cart_recovery_mail_template).exists(): cart_recovery_mail_template = self._default_recovery_mail_template() + else: + cart_recovery_mail_template = self._default_recovery_mail_template() res.update( automatic_invoice=params.get_param('website_sale.automatic_invoice', default=False), diff --git a/addons/website_sale/models/sale_order.py b/addons/website_sale/models/sale_order.py index fb6a491c..b958b952 100644 --- a/addons/website_sale/models/sale_order.py +++ b/addons/website_sale/models/sale_order.py @@ -264,3 +264,19 @@ class SaleOrder(models.Model): res = super(SaleOrder, self)._prepare_invoice() res['website_id'] = self.website_id.id return res + + @api.model + def send_cart_recovery_mail(self): + for val in self.search([('state', 'in', ['draft', 'sent'])]): + template = False + try: + template = self.env.ref( + 'website_sale.mail_template_sale_cart_recovery', + raise_if_not_found=False) + except ValueError: + pass + if val.partner_id.email and template and val.is_abandoned_cart \ + and not val.cart_recovery_email_sent: + template.with_context(lang=val.partner_id.lang).send_mail( + val.id, force_send=True, raise_exception=True) + val.cart_recovery_email_sent = True