Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
1 Beantwoorden
3503 Weergaven

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
Annuleer
Auteur Beste antwoord

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
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
4
mrt. 25
7833
4
mrt. 25
8899
0
jul. 22
1243
2
feb. 21
6180
4
okt. 20
8836