mirror of
https://github.com/OCA/web.git
synced 2025-02-22 13:21:25 +02:00
[9.0]Add web_duplicate_visibility
[ADD] web_duplicate_visibility
This commit is contained in:
committed by
Holger Brunn
parent
477b5db43e
commit
4fd6076bc0
@@ -0,0 +1,35 @@
|
||||
odoo.define('web.DuplicateVisibility',function (require) {
|
||||
"use strict";
|
||||
|
||||
var core = require('web.core');
|
||||
var Sidebar = require('web.Sidebar');
|
||||
var FormView = require('web.FormView');
|
||||
|
||||
var _t = core._t;
|
||||
|
||||
var DuplicateVisibility = FormView.include({
|
||||
/**
|
||||
* Instantiate and render the sidebar if a sidebar is requested
|
||||
* Sets this.sidebar
|
||||
* @param {jQuery} [$node] a jQuery node where the sidebar should be inserted
|
||||
* $node may be undefined, in which case the FormView inserts the sidebar in a
|
||||
* div of its template
|
||||
**/
|
||||
render_sidebar: function($node) {
|
||||
var res = this._super.apply(this, arguments);
|
||||
if (this.sidebar) {
|
||||
if(!this.is_action_enabled('duplicate') &&
|
||||
this.sidebar.items.hasOwnProperty('other')){
|
||||
this.sidebar.items.other = this.sidebar.items.other.filter(
|
||||
function(item){
|
||||
return item.label !== _t("Duplicate");
|
||||
}
|
||||
);
|
||||
this.sidebar.redraw();
|
||||
}
|
||||
}
|
||||
return res;
|
||||
},
|
||||
});
|
||||
|
||||
});
|
||||
82
web_duplicate_visibility/static/test/duplicate_visibility.js
Normal file
82
web_duplicate_visibility/static/test/duplicate_visibility.js
Normal file
@@ -0,0 +1,82 @@
|
||||
"use strict";
|
||||
odoo.define_section('web_duplicate_visibility',
|
||||
['web.data', 'web.FormView'],
|
||||
function(test, mock){
|
||||
|
||||
function assertDuplicate(data, FormView, form_tag, visible){
|
||||
mock.add('test.model:read', function () {
|
||||
return [{ id: 1, a: 'foo', b: 'bar', c: 'baz' }];
|
||||
});
|
||||
|
||||
mock.add('test.model:fields_view_get', function () {
|
||||
return {
|
||||
type: 'form',
|
||||
fields: {
|
||||
a: {type: 'char', string: "A"},
|
||||
b: {type: 'char', string: "B"},
|
||||
c: {type: 'char', string: "C"}
|
||||
},
|
||||
arch: form_tag +
|
||||
' <field name="a"/>' +
|
||||
' <field name="b"/>' +
|
||||
' <field name="c"/>' +
|
||||
'</form>',
|
||||
};
|
||||
});
|
||||
|
||||
var ds = new data.DataSetStatic(null, 'test.model', null, [1]);
|
||||
ds.index = 0;
|
||||
var $fix = $( "#qunit-fixture");
|
||||
var form = new FormView(
|
||||
{},
|
||||
ds,
|
||||
false,
|
||||
{
|
||||
sidebar: true,
|
||||
}
|
||||
);
|
||||
form.appendTo($fix);
|
||||
form.do_show();
|
||||
form.render_sidebar();
|
||||
|
||||
var $fix = $( "#qunit-fixture");
|
||||
var actions = $fix.find('.oe_sidebar a[data-section="other"]').filter(
|
||||
function(i, obj){
|
||||
return obj.text.trim() == "Duplicate";
|
||||
}
|
||||
);
|
||||
strictEqual(
|
||||
actions.length, visible, "duplicate state is not as expected"
|
||||
);
|
||||
};
|
||||
|
||||
test('Duplicate button visible when nothing set',
|
||||
function(assert, data, FormView){
|
||||
assertDuplicate(data, FormView, '<form>', 1);
|
||||
});
|
||||
|
||||
test('Duplicate button visible when create="1"',
|
||||
function(assert, data, FormView){
|
||||
assertDuplicate(data, FormView, '<form create="1">', 1);
|
||||
});
|
||||
|
||||
test('Duplicate button visible when duplicate="1"',
|
||||
function(assert, data, FormView){
|
||||
assertDuplicate(data, FormView, '<form duplicate="1">', 1);
|
||||
});
|
||||
|
||||
test('Duplicate button not displayed when create="0"',
|
||||
function(assert, data, FormView){
|
||||
assertDuplicate(data, FormView, '<form create="0">', 0);
|
||||
});
|
||||
|
||||
test('Duplicate button not displayed when create="1" duplicate="0"',
|
||||
function(assert, data, FormView){
|
||||
assertDuplicate(data, FormView, '<form create="1" duplicate="0">', 0);
|
||||
});
|
||||
|
||||
test('Duplicate button not displayed when duplicate="0"',
|
||||
function(assert, data, FormView){
|
||||
assertDuplicate(data, FormView, '<form duplicate="0">', 0);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user