Hi guys,
I have a get method in a class to a boolean field: Method:
def get_method(self, cr, uid, ids, field1, context=None):
res = {}
if field1==True:
res = '1'
else:
res = '2'
return res
The field definition: 'field1': fields.boolean('Field1')
The problem is that this allways returns '2' no matter if field1 is True or False. I'm using the method in an onchange method to another class to update a selection field, which is having possible values 1 and 2.
Also please consider the fact that i'm very beginner...
Many thanks in advance!
More details:
I have class A and class B under same custom module. Under class A i have an onchange method in a field many2one. The many2one is also present in class B (like partner_id present in res_partner_address and crm_lead under CRM module :)), so this way i'm retrieving some fields value using this onchange method under class A. The onchange under class A is also using the method described above, to get the values of class B boolean field1 and transform its True or False value to 1 or 2 and returning it to the onchange method. Practically i'm trying to change boolean field from class A to a selection field in class B. Field selection in class A has the following definition:
'contorizat': fields.selection([('1', 'C'),('2', 'N')], 'Contorizat'),
The onchange method and the get method works fine with only one issue: the get method is allways returning 1 no matter the value of the boolean field1 under class B is True or False. So i'm not sure if this can be done on boolean field or there is something i'm doing very wrong. I hope this is explained ok otherwise i will need to get all the code here.
Many thanks for the fast reply !
Update codes: Class A: field many2one:
'apartament_id': fields.many2one('bloc.apartamente', 'Numar apartament'),
field selection which is getting updated by the onchange method:
'contorizat': fields.selection([('1', 'C'),('2', 'N')], 'Contorizat fake'),
onchange method in class A:
def onchange_apt_id(self, cr, uid, ids, add, nr_ctr_pers, nr_persoane, su, plateste_fr, contorizat, context=None):
data = {'value': {'nr_ctr_pers': False}}
if add:
apt = self.pool.get('bloc.apartamente').browse(cr, uid, add)
data['value'] = {'nr_ctr_pers': apt.locatari_prezenti or False,
'nr_persoane': apt.numar_locatari or False,
'su': apt.suprafata_utila or False,
'plateste_fr': apt.fond_rulment or False,
'contorizat': apt.get_contorizat(cr, uid, ids)}
return data
Class B: field boolean:
'apa_calda_contorizat': fields.boolean('Contorizat apa calda'),
get method:
def get_contorizat(self, cr, uid, ids, apa_calda_contorizat, context=None):
res = {}
a = apa_calda_contorizat
if a==True:
res = '1'
else:
res = '2'
return res
ur question is not clear explain it with ur scenario
Class A and Class B have in comun field many2one 'apartament_id'. In Class a the onchange method onchange_apt_id is applied on this field. The field value updated in Class A (which is the issue here) is field selection 'contorizat' - last on ein the onchange method which is calling the get_contorizat method.
I changed the boolean field on Class B to be a selection field so now with the necesary changes, the onchange method works without the get_method. But still don't understand why the get method does not work on that boolean field on class B. So for the sake of knowledge, if anyone knows why please update.