mirror of
https://github.com/OCA/web.git
synced 2025-02-22 13:21:25 +02:00
[ADD] web_widget_pattern
This commit is contained in:
1
web_widget_pattern/models/__init__.py
Normal file
1
web_widget_pattern/models/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import base
|
||||
28
web_widget_pattern/models/base.py
Normal file
28
web_widget_pattern/models/base.py
Normal file
@@ -0,0 +1,28 @@
|
||||
# Copyright 2024 Hunki Enterprises BV
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0)
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class Base(models.AbstractModel):
|
||||
_inherit = "base"
|
||||
|
||||
def _valid_field_parameter(self, field, name):
|
||||
return super()._valid_field_parameter(field, name) or (
|
||||
name == "pattern" and isinstance(field, fields.Char)
|
||||
)
|
||||
|
||||
@api.model
|
||||
def _get_view_field_attributes(self):
|
||||
return super()._get_view_field_attributes() + ["pattern"]
|
||||
|
||||
@api.model
|
||||
def fields_get(self, allfields=None, attributes=None):
|
||||
result = super().fields_get(allfields=allfields, attributes=attributes)
|
||||
if attributes is None or "pattern" in attributes:
|
||||
for field_name, description in result.items():
|
||||
field = self._fields.get(field_name)
|
||||
pattern = getattr(field, "pattern", None)
|
||||
if pattern is not None:
|
||||
description["pattern"] = pattern
|
||||
return result
|
||||
Reference in New Issue
Block a user