İçereği Atla
Menü
Bu soru işaretlendi
1 Cevapla
4153 Görünümler

Hi,

I'm creating a new Widget to update some fields inside a Model. I've created a new API route in the controller and when I try to update the data of my model this one is not changing. I have a computed method to change it in visualization, how can I set correctly the data and keep the field's visualization with the computed method? 

Someone can help me?

Thanks


Model:

# -*- coding: utf-8 -*-
from odoo import _, api, fields, models


class EasyConnectorUser(models.Model):
    _name = "easy_connector.user"
    _description = "EasyConnector user"

    # Defining fields
    login = fields.Char(
        required=True, string='EasyConnector user login'
    )
    password = fields.Char(
        compute='', inverse='',
        invisible=True, copy=False,
        string='EasyConnector user password'
    )
    token = fields.Text(string='Authorization token', compute='_compute_token')

    def _compute_token(self):
        for user in self:
            user.token = 'Has tokenif user.token else 'No token'



Controller:

class AuthController(http.Controller):
    @http.route('/easy_connector/auth', type='json', auth="public")
    def auth(self, **kw):
        users = request.env['easy_connector.user'].search([])
        for user in users:
            user.token = 'Test'

        return {
            'force_refresh': True,
        }
Avatar
Vazgeç
En İyi Yanıt

Hi,

Please give @api.depends for the compute function. And also give store=True when defining the field token.Then the calculation depended on some other field(s) of the same table or some other table. Then it is possible update the model via controller.

Regards

Avatar
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
3
Ağu 23
4619
1
Tem 22
8910
1
Ara 24
3846
0
Haz 21
1978
1
Eki 20
5129