Oralover
Oralover

Reputation: 93

in odoo 14 how i can search part of string within a field value

I can search it in oracle using SQL (not plsql) but don't know how to in odoo framework. Want to find as below -the middle part, which value is variable length-please help how to in python (.py) file where I can have an onchange function to assign this value to a computed field? enter image description here

Upvotes: 0

Views: 795

Answers (1)

SDBot
SDBot

Reputation: 834

ok, try this:

value_field = fields.Char("Value")
extracted = fields.Char("Extracted", compute="_compute_extracted")

@api.depends('value_field')
def _compute_extracted(self):
    for rec in self:
        split_str = (rec.value_field or '').split('-')
        rec.extracted = split_str[1] if len(split_str) > 1 else ''

Upvotes: 1

Related Questions