Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
1 Balas
4881 Tampilan

Hi, im trying to modify the model website.track by  adding a many2one field , this field have to pick a contact depending on some URL parameters.

To do that I have inherited the website.track model and added a function. To test the function I used a button to trigger it and works fine. The problem starts when I try to override the create method to trigger the function everytime a record is created. I dont understand why the create function is not doing anything even the log doesnt show up.

Any help is welcome

Here is mi code: 


import logging
from odoo import fields, models, api

logger = logging.getLogger(__name__)
class visita(models.Model):
    _inherit = 'website.track'


    partner_id = fields.Many2one(comodel_name = 'mailing.contact',string='visitante')
 
    @api.depends("url")
    def reconoce(self):
        for a in self:
            var = a.url
            if "?" in var:
                try:
                    var2 = int(var[var.find('?')+1:var.find('%')])
                    a['partner_id'] = self.env['mailing.contact'].browse(var2) #Code for get an Id from                                                                                                                        the url
                except:
                    a['partner_id'] = False

    @api.model
    def create(self,vals_list):
        logger.info("TESTING FUNCION CREATE ")
        result = super(visita, self).create(vals_list)
        result.reconoce()
        return result


Avatar
Buang
Jawaban Terbai

Hi,

Website visitor and track records not created/updated using model create/write methods, they are created using insert/update SQL query in this method _upsert_visitor 

if you check the Website visitor model access rules, you will see there is no create access for any group. check Line 15 and 16 in this link

The website track overrided create method will be called only when track product, mean when you open website shop and open any product page. the method  _add_viewed_product will be called and this method call _add_tracking and in this method the website track create will be called and your overrided will be called as well.

So you can check  _upsert_visitor method if you can override it.

Avatar
Buang
Post Terkait Replies Tampilan Aktivitas
Libary managment Diselesaikan
2
Mei 23
1706
1
Apr 25
1336
Odoo App Diselesaikan
1
Nov 23
1899
0
Mei 24
1603
0
Sep 23
2554