Skip to content

Commit

Permalink
[MIG] web_widget_open_tab: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
moitabenfdz committed Apr 29, 2024
1 parent 5c423c8 commit 5ab1cf6
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 12 deletions.
2 changes: 1 addition & 1 deletion web_widget_open_tab/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "Widget Open on new Tab",
"summary": """
Allow to open record from trees on new tab from tree views""",
"version": "16.0.2.0.0",
"version": "17.0.1.0.0",
"license": "AGPL-3",
"author": "Creu Blanca,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/web",
Expand Down
21 changes: 11 additions & 10 deletions web_widget_open_tab/static/src/js/open_tab_widget.esm.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/** @odoo-module */

import {Component} from "@odoo/owl";
import {_t} from "@web/core/l10n/translation";
import {registry} from "@web/core/registry";
import {standardFieldProps} from "@web/views/fields/standard_field_props";
import {_lt} from "@web/core/l10n/translation";
import {Component} from "@odoo/owl";

export class OpenTabWidget extends Component {
openNewTab(ev) {
Expand All @@ -13,7 +13,7 @@ export class OpenTabWidget extends Component {
var url = window.location.href;
var searchParams = new URLSearchParams(url.split("#")[1]);
searchParams.set("view_type", "form");
searchParams.set("id", this.props.value);
searchParams.set("id", this.props.record.data.id);
if (
!searchParams.has("model") ||
searchParams.get("model") !== this.props.record.resModel
Expand All @@ -34,12 +34,13 @@ OpenTabWidget.props = {
title: {type: String, optional: true},
};

OpenTabWidget.displayName = _lt("Open Tab");
OpenTabWidget.supportedTypes = ["integer"];
OpenTabWidget.extractProps = () => {
return {
title: _lt("Click to open on new tab"),
};
export const openTabWidget = {
component: OpenTabWidget,
displayName: _t("Open Tab"),
supportedTypes: ["integer"],
extractProps: () => ({
title: _t("Click to open on new tab"),
}),
};

registry.category("fields").add("open_tab", OpenTabWidget);
registry.category("fields").add("open_tab", openTabWidget);
2 changes: 1 addition & 1 deletion web_widget_open_tab/static/src/xml/open_tab_widget.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<template>
<t t-name="web_widget_open_tab.openTab" owl="1">
<t t-name="web_widget_open_tab.openTab">
<a
class="btn open_tab_widget fa fa-external-link"
t-att-href="_getReference()"
Expand Down
1 change: 1 addition & 0 deletions web_widget_open_tab/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_main
21 changes: 21 additions & 0 deletions web_widget_open_tab/tests/test_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from odoo.tests import common


class Test(common.TransactionCase):
def test_add_open_tab_field(self):
self.env["ir.model"]._get("res.company").add_open_tab_field = True
arch, view = self.env["res.company"]._get_view(view_id=None, view_type="tree")
found = arch.xpath("//field[@widget='open_tab']")
self.assertEqual(len(found), 1)

def test_no_add_open_tab_field(self):
self.env["ir.model"]._get("res.company").add_open_tab_field = False
arch, view = self.env["res.company"]._get_view(view_id=None, view_type="tree")
found = arch.xpath("//field[@widget='open_tab']")
self.assertFalse(found)

def test_add_open_tab_field_no_name_field(self):
self.env["ir.model"]._get("res.groups").add_open_tab_field = True
arch, view = self.env["res.groups"]._get_view(view_id=None, view_type="tree")
found = arch.xpath("//field[@widget='open_tab']")
self.assertEqual(len(found), 1)

0 comments on commit 5ab1cf6

Please sign in to comment.