mirror of
https://github.com/OCA/web.git
synced 2025-02-22 13:21:25 +02:00
[FIX] web_action_conditionable: Adapt to new api
This commit is contained in:
committed by
Jasmin Solanki
parent
c81f3e8ae2
commit
de855a52a7
38
web_action_conditionable/static/src/js/field_one2many.js
Normal file
38
web_action_conditionable/static/src/js/field_one2many.js
Normal file
@@ -0,0 +1,38 @@
|
||||
/* global py */
|
||||
/* Copyright 2019 Alexandre Díaz
|
||||
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
|
||||
odoo.define('web.web_action_conditionable', function (require) {
|
||||
"use strict";
|
||||
|
||||
var FieldOne2Many = require('web.relational_fields').FieldOne2Many;
|
||||
|
||||
FieldOne2Many.include({
|
||||
init: function () {
|
||||
var self = this;
|
||||
try {
|
||||
return this._super.apply(this, arguments);
|
||||
} catch (error) {
|
||||
var arch = this.view && this.view.arch;
|
||||
if (arch) {
|
||||
['create', 'delete'].forEach(function (item) {
|
||||
if (!_.has(arch.attrs, item)) {
|
||||
return;
|
||||
}
|
||||
var expr = arch.attrs[item];
|
||||
try {
|
||||
self.activeActions[item] = py.evaluate(
|
||||
py.parse(py.tokenize(expr)),
|
||||
self.recordData).toJSON();
|
||||
} catch (ignored) {
|
||||
// Do nothing
|
||||
}
|
||||
});
|
||||
this.editable = arch.attrs.editable;
|
||||
}
|
||||
if (this.attrs.columnInvisibleFields) {
|
||||
this._processColumnInvisibleFields();
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
});
|
||||
@@ -1,24 +0,0 @@
|
||||
odoo.define('web.web_action_conditionable', function (require) {
|
||||
"use strict";
|
||||
|
||||
var View = require('web.View');
|
||||
|
||||
View.include({
|
||||
is_action_enabled: function(action) {
|
||||
var attrs = this.fields_view.arch.attrs;
|
||||
if (action in attrs) {
|
||||
try {
|
||||
return this._super(action);
|
||||
} catch(error) {
|
||||
var expr = attrs[action];
|
||||
var expression = py.parse(py.tokenize(expr));
|
||||
var cxt = this.dataset.get_context().__eval_context.__contexts[1];
|
||||
var result = py.evaluate(expression, cxt).toJSON();
|
||||
return result
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user