3
0
Fork 0

[FIX] web_action_conditionable: Adapt to new api

12.0
Alexandre Díaz 2019-07-31 13:18:44 +02:00 committed by AaronHForgeFlow
parent fafbbe8a04
commit ada18f0338
8 changed files with 80 additions and 63 deletions

View File

@ -25,7 +25,17 @@ web_action_conditionable
|badge1| |badge2| |badge3| |badge4| |badge5|
This module was written to extend the functionality of actions in tree views.
This module was written to extend the functionality of actions in
tree view (One2Many fields).
**Table of contents**
.. contents::
:local:
Usage
=====
Odoo by default support:
::
@ -36,20 +46,10 @@ with this module you can:
::
<tree delete="state=='draft'">
<tree delete="state=='draft'" create="state!='sent'">
It works in any tree view, so you can use it in One2many.
**Table of contents**
.. contents::
:local:
Usage
=====
This module has no direct interface, it only adds functionality for custom views.
Bug Tracker
===========
@ -73,6 +73,7 @@ Contributors
* Cristian Salamea <cristian.salamea@gmail.com>
* André Paramés <github@andreparames.com> (https://www.acsone.eu/)
* Alexandre Díaz <alexandre.diaz@tecnativa.com>
Maintainers
~~~~~~~~~~~

View File

@ -1,2 +1,3 @@
* Cristian Salamea <cristian.salamea@gmail.com>
* André Paramés <github@andreparames.com> (https://www.acsone.eu/)
* Alexandre Díaz <alexandre.diaz@tecnativa.com>

View File

@ -1,14 +1,2 @@
This module was written to extend the functionality of actions in tree views.
Odoo by default support:
::
<tree delete="false" create="false">
with this module you can:
::
<tree delete="state=='draft'">
It works in any tree view, so you can use it in One2many.
This module was written to extend the functionality of actions in
tree view (One2Many fields).

View File

@ -1 +1,13 @@
This module has no direct interface, it only adds functionality for custom views.
Odoo by default support:
::
<tree delete="false" create="false">
with this module you can:
::
<tree delete="state=='draft'" create="state!='sent'">
It works in any tree view, so you can use it in One2many.

View File

@ -368,16 +368,8 @@ ul.auto-toc {
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/web/tree/12.0/web_action_conditionable"><img alt="OCA/web" src="https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/web-12-0/web-12-0-web_action_conditionable"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/162/12.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This module was written to extend the functionality of actions in tree views.
Odoo by default support:</p>
<pre class="literal-block">
&lt;tree delete=&quot;false&quot; create=&quot;false&quot;&gt;
</pre>
<p>with this module you can:</p>
<pre class="literal-block">
&lt;tree delete=&quot;state=='draft'&quot;&gt;
</pre>
<p>It works in any tree view, so you can use it in One2many.</p>
<p>This module was written to extend the functionality of actions in
tree view (One2Many fields).</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
@ -393,7 +385,15 @@ Odoo by default support:</p>
</div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#id1">Usage</a></h1>
<p>This module has no direct interface, it only adds functionality for custom views.</p>
<p>Odoo by default support:</p>
<pre class="literal-block">
&lt;tree delete=&quot;false&quot; create=&quot;false&quot;&gt;
</pre>
<p>with this module you can:</p>
<pre class="literal-block">
&lt;tree delete=&quot;state=='draft'&quot; create=&quot;state!='sent'&quot;&gt;
</pre>
<p>It works in any tree view, so you can use it in One2many.</p>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#id2">Bug Tracker</a></h1>
@ -416,6 +416,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<ul class="simple">
<li>Cristian Salamea &lt;<a class="reference external" href="mailto:cristian.salamea&#64;gmail.com">cristian.salamea&#64;gmail.com</a>&gt;</li>
<li>André Paramés &lt;<a class="reference external" href="mailto:github&#64;andreparames.com">github&#64;andreparames.com</a>&gt; (<a class="reference external" href="https://www.acsone.eu/">https://www.acsone.eu/</a>)</li>
<li>Alexandre Díaz &lt;<a class="reference external" href="mailto:alexandre.diaz&#64;tecnativa.com">alexandre.diaz&#64;tecnativa.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">

View 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();
}
}
},
});
});

View File

@ -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;
}
}
});
});

View File

@ -2,7 +2,7 @@
<odoo>
<template id="assets_backend" name="action conditionable assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/web_action_conditionable/static/src/js/views.js"/>
<script type="text/javascript" src="/web_action_conditionable/static/src/js/field_one2many.js"></script>
</xpath>
</template>
</odoo>