This question has been flagged
1 Reply
2294 Views

hi all,

I want to search string like using postgresql substr and position, how i can do this in odoo

a  = fields.Char(default='ABCD-XYZ-MNOP')

if i want to search XYZ (it can be anything else like 'Smith' or 'John' etc.), search between 2 '-' characters, the '-' characters are here for the formatting which will used by default. how i can do it with  onchange function using a compute field.

here is screenshot what i did in Oracle using simple SQL:


regards

Avatar
Discard
Author Best Answer

ok, got help from @SDBot (thanks to him) on stackoverflow as below, its working fine.

class UserInfo(models.Model):
    _name = 'tests.userinfo'
    _description = "Test User Information"
    userid = fields.Many2one('res.partner', string='Select User')
    cnic = fields.Char(string='CNIC', store=True)
    cnic_ess = fields.Char(compute='_compute_cnic', store=True)
    @api.onchange('cnic')
    def _compute_cnic(self):
        for rec in self:
            split_str = (rec.cnic or '').split('-')
            rec.cnic_ess = split_str[1] if len(split_str) > 1 else ''
Avatar
Discard