Hello Tryton Community,

I was trying to modify a dict field key's value directly with a function 
field through it's setter and getter class functions, but the value doesn't 
get stored into the DB after the record is saved. I want to store some 
value into dat[num1], directly using the function field, but it does not 
work. Does anyone know why? I have attached part of the code below for 
inspection. I have created a module that extends the Company class for 
testing purpose. Can anyone guide me on this? 

class Company:
    __metaclass__ = PoolMeta
    __name__ = 'company.company'
    dat = fields.Dict('company.companyvardict','dat')
    num1 = fields.Function(fields.Integer('Num1', depends=['dat'],
        states=STATES),'get_dats', setter='set_dats')
   
    @classmethod
    def get_dats(cls, companies, names):
        result = {k:{} for k in names}
        for c in companies:
            for n in names:
                if not c.dat:
                    result[n][c.id] = None
                else:
                    result[n][c.id] = c.dat[n]
        return result

    @classmethod
    def set_dats(cls, companies, name, value):
        for c in companies:
            if not type(c.dat) is dict:
                c.dat = {}
            if value:
                c.dat[name] = value
            elif name in c.dat:
                del c.dat[name]



Many thanks in advanced for the help.

    

-- 
You received this message because you are subscribed to the Google Groups 
"tryton" group.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tryton/5b049146-d0cf-4ae1-8d14-21465b5f0528%40googlegroups.com.

Reply via email to