İçereği Atla
Menü
Bu soru işaretlendi
1 Cevapla
3841 Görünümler

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
Vazgeç
Üretici En İyi Yanıt

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
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
4
Mar 25
8695
4
Mar 25
9533
0
Tem 22
1452
2
Şub 21
6513
4
Eki 20
9259