mirror of
https://github.com/bringout/oca-ocb-sale.git
synced 2026-04-27 10:52:05 +02:00
19.0 vanilla
This commit is contained in:
parent
79f83631d5
commit
73afc09215
6267 changed files with 1534193 additions and 1130106 deletions
|
|
@ -1,36 +1,37 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from odoo import fields, models, api
|
||||
|
||||
class WebsiteTrack(models.Model):
|
||||
_inherit = 'website.track'
|
||||
|
||||
product_id = fields.Many2one('product.product', ondelete='cascade', readonly=True, index='btree_not_null')
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class WebsiteVisitor(models.Model):
|
||||
_inherit = 'website.visitor'
|
||||
|
||||
visitor_product_count = fields.Integer('Product Views', compute="_compute_product_statistics", help="Total number of views on products")
|
||||
product_ids = fields.Many2many('product.product', string="Visited Products", compute="_compute_product_statistics")
|
||||
product_count = fields.Integer('Products Views', compute="_compute_product_statistics", help="Total number of product viewed")
|
||||
visitor_product_count = fields.Integer(
|
||||
string="Product Views",
|
||||
help="Total number of views on products",
|
||||
compute='_compute_product_statistics',
|
||||
)
|
||||
product_ids = fields.Many2many(
|
||||
string="Visited Products",
|
||||
comodel_name='product.product',
|
||||
compute='_compute_product_statistics',
|
||||
)
|
||||
product_count = fields.Integer(
|
||||
string='Products Views',
|
||||
help="Total number of product viewed",
|
||||
compute='_compute_product_statistics',
|
||||
)
|
||||
|
||||
@api.depends('website_track_ids')
|
||||
def _compute_product_statistics(self):
|
||||
results = self.env['website.track']._read_group(
|
||||
[('visitor_id', 'in', self.ids), ('product_id', '!=', False),
|
||||
'|', ('product_id.company_id', 'in', self.env.companies.ids), ('product_id.company_id', '=', False)],
|
||||
['visitor_id', 'product_id'], ['visitor_id', 'product_id'],
|
||||
lazy=False)
|
||||
mapped_data = {}
|
||||
for result in results:
|
||||
visitor_info = mapped_data.get(result['visitor_id'][0], {'product_count': 0, 'product_ids': set()})
|
||||
visitor_info['product_count'] += result['__count']
|
||||
visitor_info['product_ids'].add(result['product_id'][0])
|
||||
mapped_data[result['visitor_id'][0]] = visitor_info
|
||||
results = self.env['website.track']._read_group([
|
||||
('visitor_id', 'in', self.ids), ('product_id', '!=', False),
|
||||
('product_id', 'any', self.env['product.product']._check_company_domain(self.env.companies)),
|
||||
], ['visitor_id'], ['product_id:array_agg', '__count'])
|
||||
mapped_data = {
|
||||
visitor.id: {'product_count': count, 'product_ids': product_ids}
|
||||
for visitor, product_ids, count in results
|
||||
}
|
||||
|
||||
for visitor in self:
|
||||
visitor_info = mapped_data.get(visitor.id, {'product_ids': [], 'product_count': 0})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue