[IMP] runbot: add qualifiers ir.model.fields

This commit is contained in:
Xavier-Do 2024-12-04 09:28:15 +01:00
parent b92f14b803
commit 96dcbc5e7c
2 changed files with 25 additions and 2 deletions

View File

@ -681,6 +681,28 @@ class ErrorQualifyRegex(models.Model):
test_ids = fields.One2many('runbot.error.qualify.test', 'qualify_regex_id', string="Test Sample", help="Error samples to test qualifying regex")
def action_generate_fields(self):
for rec in self:
for field in list(re.compile(rec.regex).groupindex.keys()):
existing = self.env['ir.model.fields'].search([('model', '=', 'runbot.build.error.content'), ('name', '=', f'x_{field}')])
if existing:
_logger.info(f"Field x_%s already exists", field)
else:
_logger.info(f"Creating field x_%s", field)
self.env['ir.model.fields'].create({
'model_id': self.env['ir.model']._get('runbot.build.error.content').id,
'name': f'x_{field}',
'field_description': ' '.join(field.capitalize().split('_')),
'ttype': 'char',
'required': False,
'readonly': True,
'store': True,
'depends': 'qualifiers',
'compute': f"""
for error_content in self:
error_content['x_{field}'] = error_content.qualifiers.get('{field}', '')""",
})
@api.constrains('regex')
def _validate(self):
for rec in self:

View File

@ -433,8 +433,6 @@
<field name="model">runbot.error.qualify.regex</field>
<field name="arch" type="xml">
<tree string="Qualifying Regexes">
<header>
</header>
<field name="sequence" widget="handle"/>
<field name="regex" readonly="1"/>
<field name="source_field" readonly="1"/>
@ -447,6 +445,9 @@
<field name="model">runbot.error.qualify.regex</field>
<field name="arch" type="xml">
<form>
<header>
<button type="object" name="action_generate_fields" string="Create corresponding fields"/>
</header>
<div class="alert alert-info" role="alert">
The regular expresion must have at least one named group pattern e.g: <code>'(?P&lt;module&gt;\w+)'</code>
</div>