-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] web_action_conditionable: support forms
- Loading branch information
Showing
7 changed files
with
91 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,7 @@ web_action_conditionable | |
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
Add support for conditions on create and delete actions on One2Many fields. | ||
Add support for conditions on create and delete actions on One2Many fields, as well as conditions for create, delete, duplicate and edit actions on forms. | ||
|
||
**Table of contents** | ||
|
||
|
@@ -38,20 +38,32 @@ Add support for conditions on create and delete actions on One2Many fields. | |
Usage | ||
===== | ||
|
||
Odoo by default support: | ||
Odoo by default supports: | ||
|
||
:: | ||
|
||
<tree delete="false" create="false"> | ||
|
||
with this module you can: | ||
with this module you can do: | ||
|
||
:: | ||
|
||
<tree delete="state=='draft'" create="state!='sent'"> | ||
|
||
It works in any tree view, so you can use it in One2many. | ||
|
||
Similarly in forms you can write: | ||
|
||
:: | ||
|
||
<form create="false" delete="false" duplicate="false" edit="false"> | ||
|
||
and with this module you can do: | ||
|
||
:: | ||
|
||
<form create="state=='draft'" delete="state!='done'" duplicate="some_field=='some value'" edit="state!='done'"> | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
|
@@ -80,6 +92,7 @@ Contributors | |
* Jasper Jumelet <[email protected]> | ||
* `Trobz <https://trobz.com>`_: | ||
* Nguyễn Minh Chiến <[email protected]> | ||
* Holger Brunn <[email protected]> (https://hunki-enterprises.com) | ||
|
||
Other credits | ||
~~~~~~~~~~~~~ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
* Jasper Jumelet <[email protected]> | ||
* `Trobz <https://trobz.com>`_: | ||
* Nguyễn Minh Chiến <[email protected]> | ||
* Holger Brunn <[email protected]> (https://hunki-enterprises.com) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
Add support for conditions on create and delete actions on One2Many fields. | ||
Add support for conditions on create and delete actions on One2Many fields, as well as conditions for create, delete, duplicate and edit actions on forms. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,25 @@ | ||
Odoo by default support: | ||
Odoo by default supports: | ||
|
||
:: | ||
|
||
<tree delete="false" create="false"> | ||
|
||
with this module you can: | ||
with this module you can do: | ||
|
||
:: | ||
|
||
<tree delete="state=='draft'" create="state!='sent'"> | ||
|
||
It works in any tree view, so you can use it in One2many. | ||
|
||
Similarly in forms you can write: | ||
|
||
:: | ||
|
||
<form create="false" delete="false" duplicate="false" edit="false"> | ||
|
||
and with this module you can do: | ||
|
||
:: | ||
|
||
<form create="state=='draft'" delete="state!='done'" duplicate="some_field=='some value'" edit="state!='done'"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
web_action_conditionable/static/src/components/form_arch_parser.esm.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** @odoo-module **/ | ||
import {FormArchParser} from "@web/views/form/form_arch_parser"; | ||
import {patch} from "@web/core/utils/patch"; | ||
|
||
patch(FormArchParser.prototype, "web_action_conditionable", { | ||
parse(arch) { | ||
const result = this._super(...arguments); | ||
const parsedArch = this.parseXML(arch); | ||
for (const action of ["create", "delete", "duplicate", "edit"]) { | ||
result.activeActions[action + "_expression"] = | ||
parsedArch.getAttribute(action); | ||
} | ||
return result; | ||
}, | ||
}); |
32 changes: 32 additions & 0 deletions
32
web_action_conditionable/static/src/components/form_controller.esm.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** @odoo-module **/ | ||
import {FormController} from "@web/views/form/form_controller"; | ||
import {evaluateExpr} from "@web/core/py_js/py"; | ||
import {patch} from "@web/core/utils/patch"; | ||
|
||
patch(FormController.prototype, "web_action_conditionable", { | ||
setup() { | ||
this._super(...arguments); | ||
owl.onWillRender(() => { | ||
return this._evaluate_web_action_conditionable(); | ||
}); | ||
}, | ||
async _evaluate_web_action_conditionable() { | ||
for (const action of ["create", "delete", "duplicate", "edit"]) { | ||
try { | ||
this.archInfo.activeActions[action] = evaluateExpr( | ||
this.archInfo.activeActions[action + "_expression"] || "True", | ||
this.model.root.data | ||
); | ||
if (action === "edit") { | ||
this.canEdit = this.archInfo.activeActions[action]; | ||
this.model.root.switchMode(this.canEdit ? "edit" : "readonly"); | ||
} | ||
if (action === "create") { | ||
this.canCreate = this.archInfo.activeActions[action]; | ||
} | ||
} catch (exception) { | ||
console.log(exception); | ||
} | ||
} | ||
}, | ||
}); |