Exemplo n.º 1
0
    def _extract_xml_act_window(self, addon, filename, tree):
        # <act_window> shortcut.
        for act_window in tree.xpath("//act_window"):
            yield _ref_or_def(
                addon,
                filename,
                act_window.sourceline,
                act_window.attrib["id"],
                "ir.actions.act_window",
            )

            groups = act_window.get("groups")
            if groups:
                for group in split_groups(groups):
                    yield _ref(addon, filename, act_window.sourceline, group,
                               "res.groups")

            view_id = act_window.get("view_id")
            if view_id:
                yield _ref(addon, filename, act_window.sourceline, view_id,
                           "ir.ui.view")

            res_model = act_window.get("res_model")
            if res_model:
                yield _model_ref(addon, filename, act_window.sourceline,
                                 res_model)

            src_model = act_window.get("src_model")
            if src_model:
                yield _model_ref(addon, filename, act_window.sourceline,
                                 src_model)
Exemplo n.º 2
0
    def _extract_xml_menuitem(self, addon, filename, tree):
        # <menuitem> shortcut.
        for menuitem in tree.xpath("//menuitem"):
            yield _ref_or_def(
                addon,
                filename,
                menuitem.sourceline,
                menuitem.attrib["id"],
                "ir.ui.menu",
            )
            parent = menuitem.get("parent")
            if parent:
                yield _ref(addon, filename, menuitem.sourceline, parent,
                           "ir.ui.menu")

            action = menuitem.get("action")
            if action:
                yield _ref(
                    addon,
                    filename,
                    menuitem.sourceline,
                    action,
                    "ir.actions.act_window",
                )

            groups = menuitem.get("groups")
            if groups:
                for group in split_groups(groups):
                    yield _ref(addon, filename, menuitem.sourceline, group,
                               "res.groups")
Exemplo n.º 3
0
    def _extract_xml_record(self, addon, filename, tree):
        # <record> operation.
        for record in tree.xpath("//record"):
            record_model, record_id = record.attrib["model"], record.get("id")
            if record_model:
                yield _model_ref(addon, filename, record.sourceline,
                                 record_model)
            if record_id:
                yield _ref_or_def(addon, filename, record.sourceline,
                                  record_id, record_model)

            # <field> operation.
            for field in record.iterchildren(tag="field"):
                field_name = field.attrib["name"]

                field_external_id = _field_record_id(record_model, field_name)
                yield ExternalIDReference(
                    addon,
                    UNKNOWN,
                    field_external_id,
                    "ir.model.fields",
                    Location(filename, field.sourceline),
                )

                ref = field.get("ref")
                if ref:
                    ref_model = KNOWN_FIELD_MODELS.get(record_model, {}).get(
                        field_name, UNKNOWN)
                    yield _ref(addon, filename, field.sourceline, ref,
                               ref_model)

                for attr_name in ("eval", "search"):
                    yield from self._get_ref_from_eval(addon, filename,
                                                       field.sourceline,
                                                       field.get(attr_name))

            # View-specific tags.
            if record_model != "ir.ui.view":
                continue

            arch = get_view_arch(record)
            if arch is None:
                continue

            for button in arch.xpath(".//button[@type='action' and @name]"):
                button_name = button.get("name")
                if button_name:
                    yield _ref(
                        addon,
                        filename,
                        button.sourceline,
                        remove_old_style_format(button_name),
                        "ir.ui.view",
                    )

            for el in arch.xpath(".//*[@groups]"):
                groups = el.get("groups")
                for group in split_groups(groups):
                    yield _ref(addon, filename, el.sourceline, group,
                               "res.groups")
Exemplo n.º 4
0
    def _extract_xml_template(self, addon, filename, tree):
        # <template> shortcut.
        for template in tree.xpath("//template"):
            template_id = template.get("id")
            if template_id:
                yield _ref_or_def(addon, filename, template.sourceline,
                                  template_id, "ir.ui.view")

            inherit_id = template.get("inherit_id")
            if inherit_id:
                yield _ref(addon, filename, template.sourceline, inherit_id,
                           "ir.ui.view")

            groups = template.get("groups")
            if groups:
                for group in split_groups(groups):
                    yield _ref(addon, filename, template.sourceline, group,
                               "res.groups")
Exemplo n.º 5
0
    def _extract_xml_report(self, addon, filename, tree):
        # <report> shortcut.
        for report in tree.xpath("//report"):
            # TODO: `name`, `file`?
            yield _ref_or_def(
                addon,
                filename,
                report.sourceline,
                report.attrib["id"],
                "ir.actions.report",
            )

            name = report.get("name")
            if name and "rml" not in report.attrib:
                yield _ref(addon, filename, report.sourceline, name,
                           "ir.ui.view")

            paperformat_id = report.get("paperformat")
            if paperformat_id and addon.odoo_version > 8:
                yield _ref(
                    addon,
                    filename,
                    report.sourceline,
                    paperformat_id,
                    "report.paperformat",
                )

            model = report.get("model")
            if model:
                yield _model_ref(addon, filename, report.sourceline, model)

            groups = report.get("groups")
            if groups:
                for group in split_groups(groups):
                    yield _ref(addon, filename, report.sourceline, group,
                               "res.groups")
Exemplo n.º 6
0
def _user_has_groups_getter(
        _, args: typing.Iterator[typing.Any]) -> typing.Iterator[str]:
    first_arg = next(args, None)
    if first_arg and isinstance(first_arg, str):
        yield from split_groups(first_arg)
Exemplo n.º 7
0
def _user_has_groups_getter(_,
                            call: Call) -> typing.Generator[str, None, None]:
    if call.args:
        if isinstance(call.args[0], str) and call.args[0]:
            yield from split_groups(call.args[0])