Skip to content

Commit 4fd6076

Browse files
Pierre Verkesthbrunn
Pierre Verkest
authored andcommitted
[9.0]Add web_duplicate_visibility
[ADD] web_duplicate_visibility
1 parent 477b5db commit 4fd6076

File tree

7 files changed

+262
-0
lines changed

7 files changed

+262
-0
lines changed

web_duplicate_visibility/README.rst

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
2+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
3+
:alt: License: AGPL-3
4+
5+
========================
6+
Web duplicate visibility
7+
========================
8+
9+
This module allows to manage the visibility of duplicate button from the form
10+
view declaration.
11+
12+
Usage
13+
=====
14+
15+
While the default behavior of odoo is to display the duplicate button when user
16+
is allowed to create a new object. You are now able to remove duplicate button
17+
explicitly even if you are able to create new object::
18+
19+
<record id="view_form_id" model="ir.ui.view">
20+
<field name="name">view name</field>
21+
<field name="model">my.model</field>
22+
<field name="priority" eval="10"/>
23+
<field name="arch" type="xml">
24+
<form string="..." duplicate="0">
25+
...
26+
</form>
27+
</field>
28+
</record>
29+
30+
or by extending an existing view::
31+
32+
<field name="arch" type="xml">
33+
<xpath expr="//form" position="attributes">
34+
<attribute name="duplicate">0</attribute>
35+
</xpath>
36+
</field>
37+
38+
39+
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
40+
:alt: Try me on Runbot
41+
:target: https://runbot.odoo-community.org/runbot/repo/github-com-oca-web-162
42+
43+
Bug Tracker
44+
===========
45+
46+
Bugs are tracked on `GitHub Issues
47+
<https://github.com/OCA/web/issues>`_. In case of trouble, please
48+
check there if your issue has already been reported. If you spotted it first,
49+
help us smashing it by providing a detailed and welcomed `feedback
50+
<https://github.com/OCA/web/issues/new?body=module:%20web_duplicate_visibility%0
51+
Aversion:%209.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20
52+
behavior**%0A%0A**Expected%20behavior**>`_.
53+
54+
Credits
55+
=======
56+
57+
Images
58+
------
59+
60+
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/
61+
blob/master/template/module/static/description/icon.svg>`_.
62+
63+
Contributors
64+
------------
65+
66+
* Pierre Verkest <[email protected]>
67+
* Christophe Combelles <[email protected]>
68+
* Simon André <[email protected]>
69+
70+
Maintainer
71+
----------
72+
73+
.. image:: https://odoo-community.org/logo.png
74+
:alt: Odoo Community Association
75+
:target: https://odoo-community.org
76+
77+
This module is maintained by the OCA.
78+
79+
OCA, or the Odoo Community Association, is a nonprofit organization whose
80+
mission is to support the collaborative development of Odoo features and
81+
promote its widespread use.
82+
83+
To contribute to this module, please visit https://odoo-community.org.

web_duplicate_visibility/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# -*- coding: utf-8 -*-
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# -*- coding: utf-8 -*-
2+
# © 2016 Pierre Verkest <[email protected]>
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
4+
{
5+
"name": "web duplicate visibility",
6+
"summary": "Manage the duplicate button visibiliy",
7+
"version": "9.0.1.0.0",
8+
"category": "web",
9+
"website": "https://odoo-community.org/",
10+
"author": "Pierre Verkest <[email protected]>,"
11+
" Odoo Community Association (OCA)",
12+
"license": "AGPL-3",
13+
"application": False,
14+
"installable": True,
15+
"depends": [
16+
"base",
17+
"web",
18+
],
19+
"data": [
20+
"views/assets.xml",
21+
],
22+
"demo": [
23+
"demo/res_users_view.xml",
24+
],
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<odoo>
3+
<record id="view_users_form" model="ir.ui.view">
4+
<field name="inherit_id" ref="base.view_users_form"/>
5+
<field name="model">res.users</field>
6+
<field name="arch" type="xml">
7+
<xpath expr="//form" position="attributes">
8+
<attribute name="duplicate">0</attribute>
9+
</xpath>
10+
</field>
11+
</record>
12+
</odoo>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
odoo.define('web.DuplicateVisibility',function (require) {
2+
"use strict";
3+
4+
var core = require('web.core');
5+
var Sidebar = require('web.Sidebar');
6+
var FormView = require('web.FormView');
7+
8+
var _t = core._t;
9+
10+
var DuplicateVisibility = FormView.include({
11+
/**
12+
* Instantiate and render the sidebar if a sidebar is requested
13+
* Sets this.sidebar
14+
* @param {jQuery} [$node] a jQuery node where the sidebar should be inserted
15+
* $node may be undefined, in which case the FormView inserts the sidebar in a
16+
* div of its template
17+
**/
18+
render_sidebar: function($node) {
19+
var res = this._super.apply(this, arguments);
20+
if (this.sidebar) {
21+
if(!this.is_action_enabled('duplicate') &&
22+
this.sidebar.items.hasOwnProperty('other')){
23+
this.sidebar.items.other = this.sidebar.items.other.filter(
24+
function(item){
25+
return item.label !== _t("Duplicate");
26+
}
27+
);
28+
this.sidebar.redraw();
29+
}
30+
}
31+
return res;
32+
},
33+
});
34+
35+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
"use strict";
2+
odoo.define_section('web_duplicate_visibility',
3+
['web.data', 'web.FormView'],
4+
function(test, mock){
5+
6+
function assertDuplicate(data, FormView, form_tag, visible){
7+
mock.add('test.model:read', function () {
8+
return [{ id: 1, a: 'foo', b: 'bar', c: 'baz' }];
9+
});
10+
11+
mock.add('test.model:fields_view_get', function () {
12+
return {
13+
type: 'form',
14+
fields: {
15+
a: {type: 'char', string: "A"},
16+
b: {type: 'char', string: "B"},
17+
c: {type: 'char', string: "C"}
18+
},
19+
arch: form_tag +
20+
' <field name="a"/>' +
21+
' <field name="b"/>' +
22+
' <field name="c"/>' +
23+
'</form>',
24+
};
25+
});
26+
27+
var ds = new data.DataSetStatic(null, 'test.model', null, [1]);
28+
ds.index = 0;
29+
var $fix = $( "#qunit-fixture");
30+
var form = new FormView(
31+
{},
32+
ds,
33+
false,
34+
{
35+
sidebar: true,
36+
}
37+
);
38+
form.appendTo($fix);
39+
form.do_show();
40+
form.render_sidebar();
41+
42+
var $fix = $( "#qunit-fixture");
43+
var actions = $fix.find('.oe_sidebar a[data-section="other"]').filter(
44+
function(i, obj){
45+
return obj.text.trim() == "Duplicate";
46+
}
47+
);
48+
strictEqual(
49+
actions.length, visible, "duplicate state is not as expected"
50+
);
51+
};
52+
53+
test('Duplicate button visible when nothing set',
54+
function(assert, data, FormView){
55+
assertDuplicate(data, FormView, '<form>', 1);
56+
});
57+
58+
test('Duplicate button visible when create="1"',
59+
function(assert, data, FormView){
60+
assertDuplicate(data, FormView, '<form create="1">', 1);
61+
});
62+
63+
test('Duplicate button visible when duplicate="1"',
64+
function(assert, data, FormView){
65+
assertDuplicate(data, FormView, '<form duplicate="1">', 1);
66+
});
67+
68+
test('Duplicate button not displayed when create="0"',
69+
function(assert, data, FormView){
70+
assertDuplicate(data, FormView, '<form create="0">', 0);
71+
});
72+
73+
test('Duplicate button not displayed when create="1" duplicate="0"',
74+
function(assert, data, FormView){
75+
assertDuplicate(data, FormView, '<form create="1" duplicate="0">', 0);
76+
});
77+
78+
test('Duplicate button not displayed when duplicate="0"',
79+
function(assert, data, FormView){
80+
assertDuplicate(data, FormView, '<form duplicate="0">', 0);
81+
});
82+
});
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<odoo>
3+
<template id="assets_backend"
4+
name="web_duplicate_visibility backend assets"
5+
inherit_id="web.assets_backend">
6+
<xpath expr="."
7+
position="inside">
8+
<script type="text/javascript"
9+
src="/web_duplicate_visibility/static/src/js/duplicate_visibility.js">
10+
</script>
11+
</xpath>
12+
</template>
13+
14+
<template id="qunit_suite"
15+
name="web_duplicate_visibility qunit assets"
16+
inherit_id="web.qunit_suite">
17+
<xpath expr="//html/head"
18+
position="inside">
19+
<script type="text/javascript"
20+
src="/web_duplicate_visibility/static/test/duplicate_visibility.js">
21+
</script>
22+
</xpath>
23+
</template>
24+
</odoo>

0 commit comments

Comments
 (0)