Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
4885 Widoki

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


Awatar
Odrzuć
Najlepsza odpowiedź

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.

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
Libary managment Rozwiązane
2
maj 23
1707
1
kwi 25
1339
Odoo App Rozwiązane
1
lis 23
1899
0
maj 24
1633
0
wrz 23
2586