| 1 |
|
| 2 |
|
| 3 |
from odoo import fields, models |
| 4 |
|
| 5 |
|
| 6 |
class SaleReport(models.Model): |
| 7 |
_inherit = 'sale.report' |
| 8 |
|
| 9 |
website_id = fields.Many2one('website', readonly=True) |
| 10 |
is_abandoned_cart = fields.Boolean(string="Abandoned Cart", readonly=True) |
| 11 |
public_categ_ids = fields.Many2many( |
| 12 |
string="eCommerce Categories", |
| 13 |
related='product_tmpl_id.public_categ_ids', |
| 14 |
) |
| 15 |
|
| 16 |
def _select_additional_fields(self): |
| 17 |
res = super()._select_additional_fields() |
| 18 |
res['website_id'] = "s.website_id" |
| 19 |
res['is_abandoned_cart'] = """ |
| 20 |
s.date_order <= (timezone('utc', now()) - ((COALESCE(w.cart_abandoned_delay, '1.0') || ' hour')::INTERVAL)) |
| 21 |
AND s.website_id IS NOT NULL |
| 22 |
AND s.state = 'draft' |
| 23 |
AND s.partner_id != %s""" % self.env.ref('base.public_partner').id |
| 24 |
return res |
| 25 |
|
| 26 |
def _from_sale(self): |
| 27 |
res = super()._from_sale() |
| 28 |
res += """ |
| 29 |
LEFT JOIN website w ON w.id = s.website_id""" |
| 30 |
return res |
| 31 |
|
| 32 |
def _group_by_sale(self): |
| 33 |
res = super()._group_by_sale() |
| 34 |
res += """, |
| 35 |
s.website_id, |
| 36 |
w.cart_abandoned_delay""" |
| 37 |
return res |