Hi,
I am trying to have a fields.function that have a default value for res_partner if it is a contact of a company, or if it is a company. But this value can be changed.
So I try this:
def _passiv(self, cr, uid, ids, field_names, arg, context):
res = {}
for partner in self.browse(cr, uid, ids, context):
res[partner.id] = False
if partner.parent_id:
res[partner.id] = True
if partner.is_company:
res[partner.id] = True
return res
def _set_passiv(self, cr, uid, ids, name, value, arg, context=None):
if not value: return False
if type(ids)!=type([]):
ids=[ids]
for partner in self.browse(cr, uid, ids, context=context):
cr.execute("""update res_partner set
passiv=%s where id=%s""", (value, partner.id))
return True
_columns = {
'passiv': fields.function(_passiv, fnct_inv = _set_passiv, store = True, string='Passiv', type='boolean', help="Check if it is a passiv"),
}
This code give me right values to default, but if I edit my field and save it this doesn't save my choice. I can't access to vals or any other variable that have the value that the user gave to the field.
So, I have it not readonly but I can never change the value.
Any ideas?
Hello Anabela, Have you found any solution? If yes, can you please post it as i am facing same problem in case of function field. Regards,