mirror of
https://github.com/bringout/oca-ocb-sale.git
synced 2026-04-27 05:52:06 +02:00
19.0 vanilla
This commit is contained in:
parent
79f83631d5
commit
73afc09215
6267 changed files with 1534193 additions and 1130106 deletions
|
|
@ -1,39 +1,33 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from datetime import datetime
|
||||
from dateutil.relativedelta import relativedelta
|
||||
|
||||
from odoo import fields,api, models, _
|
||||
from odoo.exceptions import UserError, ValidationError
|
||||
from odoo import _, fields, models
|
||||
|
||||
|
||||
class CrmTeam(models.Model):
|
||||
_inherit = "crm.team"
|
||||
_inherit = 'crm.team'
|
||||
|
||||
website_ids = fields.One2many('website', 'salesteam_id', string='Websites')
|
||||
abandoned_carts_count = fields.Integer(
|
||||
compute='_compute_abandoned_carts',
|
||||
string='Number of Abandoned Carts', readonly=True)
|
||||
website_ids = fields.One2many(
|
||||
string="Websites", comodel_name='website', inverse_name='salesteam_id',
|
||||
)
|
||||
abandoned_carts_amount = fields.Integer(
|
||||
compute='_compute_abandoned_carts',
|
||||
string='Amount of Abandoned Carts', readonly=True)
|
||||
string="Amount of Abandoned Carts", compute='_compute_abandoned_carts',
|
||||
)
|
||||
abandoned_carts_count = fields.Integer(
|
||||
string="Number of Abandoned Carts", compute='_compute_abandoned_carts',
|
||||
)
|
||||
|
||||
def _compute_abandoned_carts(self):
|
||||
# abandoned carts to recover are draft sales orders that have no order lines,
|
||||
# a partner other than the public user, and created over an hour ago
|
||||
# and the recovery mail was not yet sent
|
||||
counts = {}
|
||||
amounts = {}
|
||||
website_teams = self.filtered(lambda team: team.website_ids)
|
||||
if website_teams:
|
||||
abandoned_carts_data = self.env['sale.order']._read_group([
|
||||
('is_abandoned_cart', '=', True),
|
||||
('cart_recovery_email_sent', '=', False),
|
||||
('team_id', 'in', website_teams.ids),
|
||||
], ['amount_total', 'team_id'], ['team_id'])
|
||||
counts = {data['team_id'][0]: data['team_id_count'] for data in abandoned_carts_data}
|
||||
amounts = {data['team_id'][0]: data['amount_total'] for data in abandoned_carts_data}
|
||||
abandoned_carts_data = self.env['sale.order']._read_group([
|
||||
('is_abandoned_cart', '=', True),
|
||||
('cart_recovery_email_sent', '=', False),
|
||||
('team_id', 'in', website_teams.ids),
|
||||
], ['team_id'], ['amount_total:sum', '__count'])
|
||||
counts = {team.id: count for team, __, count in abandoned_carts_data}
|
||||
amounts = {team.id: amount_total_sum for team, amount_total_sum, __ in abandoned_carts_data}
|
||||
for team in self:
|
||||
team.abandoned_carts_count = counts.get(team.id, 0)
|
||||
team.abandoned_carts_amount = amounts.get(team.id, 0)
|
||||
|
|
@ -43,7 +37,7 @@ class CrmTeam(models.Model):
|
|||
return {
|
||||
'name': _('Abandoned Carts'),
|
||||
'type': 'ir.actions.act_window',
|
||||
'view_mode': 'tree,form',
|
||||
'view_mode': 'list,form',
|
||||
'domain': [('is_abandoned_cart', '=', True)],
|
||||
'search_view_id': [self.env.ref('sale.sale_order_view_search_inherit_sale').id],
|
||||
'context': {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue