Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
2 Vastaukset
6373 Näkymät

I've overridden the create method for my custom module to create only records that have certain data in vals dict. I did this because the model is being filled by a service over xml-rpc calls, so I don't want to create a record if a user does not exist in odoo.

So I first check if the key is even in vals dict and if it is I check if it's in Odoo else I return False (tried None same error). The error is caused by the models.py original create method because of the decorator @api.returns('self', lambda value: value.id). So every time that I want to return false I get an AttributeError: 'bool' object has no attribute 'id' in my log.

Is there a way to return False/None without raising an AttributeError? I can't make this check in the script that's executed by the service, because every xml-rpc call/response takes ~ 1s and I need to do 3-5 and this would take to long. 


@api.model
def create(self, vals):
if 'from_number' not in vals or 'to_number' not in vals:
_logger.error(u'TABLA: from or to number not in vals! Exiting! vals: {}'.format(vals))
return False

if vals['from_number'] != '':
caller_partner_id = self.get_partner_by_number(vals['from_number'])
if caller_partner_id:
vals['caller_partner_id'] = caller_partner_id
else:
_logger.error(u'TABLA: from number not in vals! Exiting! vals: {}'.format(vals))
return False

# some more checks, same style

call = super(TablaAsteriskCalls, self).create(vals)

# some more code if the record is created

return call


   

Avatar
Hylkää
Tekijä Paras vastaus

It's just a simple fix... just had to override the lamdba in the decorator.

@api.returns('self', lambda value: value.id if value else False)
Avatar
Hylkää
Paras vastaus

Hello,

Instead of returning False/None just return empty record, as following :

return self.browse()
Avatar
Hylkää
Tekijä

yep... you answer works to.

Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
1
marrask. 17
3617
1
toukok. 19
5362
1
maalisk. 18
11137
3
toukok. 17
11009
1
jouluk. 19
3638