from odd.utils import expand_version_list, odoo_source_url

_LOG = logging.getLogger(__name__)
FIELD_TYPE_VERSION_MAP = expand_version_list(
    {
        ">=8": {
            "Binary",
            "Boolean",
            "Char",
            "Date",
            "Datetime",
            "Float",
            "Html",
            "Id",
            "Integer",
            "Many2many",
            "Many2one",
            "One2many",
            "Reference",
            "Selection",
            "Serialized",
            "Text",
        },
        ">=9": {"Monetary"},
    },
    *SUPPORTED_VERSIONS,
    result_cls=set,
)
FIELD_TYPE_STRING_INDEX_MAP = {"One2many": 2, "Many2one": 1, "Many2many": 4}
ODOO_SOURCE_URL_VERSION_MAP = {
    8:
Example #2
0
from odd.plugin import Plugin
from odd.utils import (
    expand_version_list,
    remove_old_style_format,
    split_external_id,
    split_groups,
)

XML_OPERATION_VERSION_MAP = expand_version_list(
    {
        ">=8": [
            "record",
            "menuitem",
            "act_window",
            "report",
            "template",
            "delete",
            "function",
        ]
    },
    *SUPPORTED_ODOO_VERSIONS,
    result_cls=list,
)
KNOWN_FIELD_MODELS = {
    "ir.rule": {
        "model_id": "ir.model"
    },
    "ir.ui.view": {
        "inherit_id": "ir.ui.view"
    },
}
Example #3
0
    remove_old_style_format,
    split_external_id,
    split_groups,
)
from odd.xml_utils import get_view_arch
from odd.yaml_utils import YamlTag, line_column_index_1, load

XML_OPERATION_VERSION_MAP = expand_version_list(
    {
        ">=8": [
            "record",
            "menuitem",
            "act_window",
            "report",
            "template",
            "delete",
            "function",
        ],
        "==8": ["ir_set"],
        "<=10": ["workflow"],
    },
    *SUPPORTED_VERSIONS,
    result_cls=list,
)
KNOWN_FIELD_MODELS = {
    "ir.rule": {
        "model_id": "ir.model"
    },
    "ir.ui.view": {
        "inherit_id": "ir.ui.view"
    },
Example #4
0
COMMON_ATTRS_VERSION_MAP = expand_version_list(
    {
        ">=8": {
            "string",
            "help",
            "readonly",
            "required",
            "index",
            "default",
            "states",
            "groups",
            "copy",
            "company_dependent",
            "change_default",
            "deprecated",
            "store",
            "inherited",
        },
        ">=8,<13": {
            "oldname",
            # mail
            "track_visibility",
        },
        "==12": {
            # mail
            "track_sequence"
        },
        ">=10": {
            "group_operator",
            "prefetch",
            # base_sparse_field
            "sparse",
        },
        ">=13": {
            "depends_context",
            # mail
            "tracking",
            "tracking_sequence",
        },
        ">10,<13": {"context_dependent"},
    },
    *SUPPORTED_VERSIONS,
    result_cls=set,
)
Example #5
0
from odd.check import Check
from odd.const import SUPPORTED_VERSIONS
from odd.issue import Issue, Location
from odd.utils import expand_version_list
from odd.parso_utils import column_index_1, extract_func_name, walk

ROUTE_KWARG_VERSION_MAP = {
    ">=8": ["auth", "methods", "multilang", "type", "website"],
    ">=9": ["cors", "csrf"],
    ">=11": ["sitemap"],
    ">=12": ["save_session"],
}

ROUTE_KWARGS = expand_version_list(ROUTE_KWARG_VERSION_MAP,
                                   *SUPPORTED_VERSIONS,
                                   result_cls=set)


class RouteKwargs(Check):
    _handles = {"python_module"}

    def on_python_module(self, python_module):
        for node in walk(python_module.module):
            if node.type != "decorator":
                continue

            name_parts = extract_func_name(node)
            if (len(name_parts) == 1 and name_parts[0] != "route") or (
                    len(name_parts) == 2 and
                (name_parts[0] != "http" or name_parts[1] != "route")):
                continue
Example #6
0
from odd.check import Check
from odd.const import SUPPORTED_VERSIONS
from odd.issue import Issue, Location
from odd.utils import expand_version_list

ROOT_TAG_VERSION_MAP = expand_version_list(
    {
        ">=8": ["openerp"],
        ">=9": ["odoo"]
    },
    *SUPPORTED_VERSIONS,
    result_cls=list)


class DataElementParent(Check):
    _handles = {"xml_tree"}

    def on_xml_tree(self, xml_tree):
        root_tags = ROOT_TAG_VERSION_MAP[xml_tree.addon.version]
        xpath_expr = "//data[%s]" % " and ".join(f"not(parent::{root_tag})"
                                                 for root_tag in root_tags)

        for data in xml_tree.tree_node.xpath(xpath_expr):
            yield Issue(
                "invalid_data_element_parent",
                f"Expected `<data>` element to be a direct child of one of "
                f"these elements: {', '.join(root_tags)}",
                xml_tree.addon.manifest_path,
                [Location(xml_tree.path, [data.sourceline])],
                categories=["correctness"],
            )
Example #7
0
import lxml.etree as ET

from odd.check import Check
from odd.issue import Issue, Location
from odd.utils import expand_version_list
from odd.const import SUPPORTED_VERSIONS
from odd.xml_utils import get_root, get_view_arch

_LOG = logging.getLogger(__name__)

VIEW_ELEMENT_VERSION_MAP = expand_version_list(
    {
        ">=8": {"diagram", "search", "tree", "graph", "calendar"},
        ">=8,<=10": {"form", "kanban"},
        ">=8,<=12": {"gantt"},
        ">=9": {"pivot"},
        ">=13": {"activity"},
    },
    *SUPPORTED_VERSIONS,
    result_cls=set,
)


@functools.lru_cache()
def _load_validator(tag: str, version: int) -> ET.RelaxNG:
    module = f"odd.data.relaxng.v{version:d}"
    file_path = "view.rng" if version < 11 else f"{tag:s}_view.rng"
    with importlib.resources.path(module, file_path) as path:
        _LOG.debug("Loading RelaxNG schema from file: %s", path)
        return ET.RelaxNG(get_root(path))