43
43
=====
44
44
45
45
#. Go to *Settings > Tachnical > User Interface > Form Banner Rules * and create a rule.
46
- #. Choose Model, (optionally) restrict Form Views, set Default Severity, Target XPath
47
- (insertion point), Position, and configure the message.
46
+ #. Choose Model, select Trigger Fields (optional), set Default Severity, select Views
47
+ (optional), update Target XPath (insertion point) and Position, and configure the
48
+ message.
48
49
#. Save. Open any matching form record—the banner will appear and auto-refresh after
49
50
load/save/reload.
50
51
@@ -68,6 +69,13 @@ Evaluation context variables available in Message Value Code:
68
69
* `user `: Current user (`env.user `).
69
70
* `ctx `: Copy of the current context (`dict(env.context) `).
70
71
* `record `: Current record (the form's record).
72
+ * `draft `: The persisted field values of the ORM record (before applying the current
73
+ form's unsaved changes) + the current unsaved changes on trigger fields.
74
+ Should be used instead of `record ` when your rule is triggered dynamically by an
75
+ update to a trigger field. It doesn't include any values from complex fields
76
+ (x2many/reference, etc).
77
+ * `record_id `: Integer id of the record being edited, or `False ` if the form
78
+ is creating a new record.
71
79
* `model `: Shortcut to the current model (`env[record._name] `).
72
80
* `url_for(obj) `: Helper that returns a backend form URL for `obj `.
73
81
* `context_today(ts=None) `: User-timezone “today” (date) for reliable date comparisons.
@@ -79,6 +87,19 @@ Evaluation context variables available in Message Value Code:
79
87
80
88
All of the above are injected by the module to the safe_eval locals.
81
89
90
+ Trigger Fields
91
+ ~~~~~~~~~~~~~~
92
+
93
+ *Trigger Fields * is an optional list of model fields that, when changed in the open
94
+ form, cause the banner to **recompute live **. If left empty, the banner does **not **
95
+ auto-refresh as the user edits the form.
96
+
97
+ When a trigger fires, the module sends the current draft values to the server, sanitizes
98
+ them, builds an evaluation record, and re-runs your `message_value_code `.
99
+
100
+ You should use `draft ` instead of `record ` to access the current form values if your
101
+ rule is triggered based on an update to a trigger field.
102
+
82
103
Message setting examples:
83
104
~~~~~~~~~~~~~~~~~~~~~~~~~
84
105
@@ -123,7 +144,7 @@ It is also possible to use "convenience placeholders" without an explicit `value
123
144
.. code-block :: python
124
145
125
146
{
126
- " visible" : record.amount_total > 30000 ,
147
+ " visible" : record.amount_total >= 30000 ,
127
148
" severity" : " danger" if record.amount_total >= 100000 else " warning" ,
128
149
" values" : {" amount_total" : record.amount_total},
129
150
}
@@ -141,7 +162,7 @@ It is also possible to use "convenience placeholders" without an explicit `value
141
162
" values" : {" validity_date" : record.validity_date},
142
163
}
143
164
144
- **E) Pending activities on a task (uses env) **
165
+ **E) Pending activities on a task (uses ` env` ) **
145
166
146
167
* Model: `project.task `
147
168
* Message: `There are ${cnt} pending activities. `
@@ -152,19 +173,30 @@ It is also possible to use "convenience placeholders" without an explicit `value
152
173
cnt = env[" mail.activity" ].search_count([(" res_model" ," =" ,record._name),(" res_id" ," =" ,record.id)])
153
174
result = {" visible" : cnt > 0 , " values" : {" cnt" : cnt}}
154
175
155
- **F) HTML banner linking to the customer's last sales order **
176
+ **F) Product is missing internal reference (uses trigger fields) **
177
+
178
+ * Model: `product.template `
179
+ * Trigger Fields: `default_code `
180
+ * Message: `Make sure to set an internal reference! `
181
+ * Message Value Code:
182
+
183
+ .. code-block :: python
184
+
185
+ {" visible" : not bool (draft.default_code)}
186
+
187
+ **G) HTML banner linking to the customer's last sales order (uses trigger fields) **
156
188
157
189
* Model: `sale.order `
190
+ * Trigger Fields: `partner_id `
158
191
* Message: (leave blank; `html ` provided by Message Value Code)
159
192
* Message Value Code (multi-line with `result `):
160
193
161
194
.. code-block :: python
162
195
163
- last = model.search(
164
- [(" partner_id" , " =" , record.partner_id.id), (" id" , " <" , record.id)],
165
- order = " date_order desc, id desc" ,
166
- limit = 1 ,
167
- )
196
+ domain = [(" partner_id" , " =" , draft.partner_id.id)]
197
+ if record_id:
198
+ domain += [(" id" , " <" , record_id)]
199
+ last = model.search(domain, order = " date_order desc, id desc" , limit = 1 )
168
200
if last:
169
201
html = " <strong>Previous order:</strong> <a href='%s '>%s </a>" % (url_for(last), last.name)
170
202
result = {" visible" : True , " html" : html}
@@ -174,9 +206,23 @@ It is also possible to use "convenience placeholders" without an explicit `value
174
206
Known issues / Roadmap
175
207
======================
176
208
209
+ Banner presentation inside `<group> `
210
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
211
+
177
212
Placing a full-width inline banner inside `<group> ` is currently not supported. The
178
- banner will be limited to 50% of the group's width, and its label/value ratio will be
179
- forced to 1:1.
213
+ presentation of the banner and the child fields will be distorted.
214
+
215
+ Limitations of `draft ` eval context variable
216
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
217
+
218
+ * `draft ` is always available in the eval context, but for new records (`record_id ` =
219
+ `False `) it only contains the trigger fields from the banner rules.
220
+ * For existing records, `draft ` overlays the trigger field values on top of the
221
+ persisted record; all other fields come from `Model.new ` defaults rather than the
222
+ database.
223
+ * Only simple field types are included: `char `, `text `, `html `, `selection `, `boolean `,
224
+ `integer `, `float `, `monetary `, `date `, `datetime `, and `many2one ` (normalized to an
225
+ integer ID). **x2many/reference/other types are omitted. **
180
226
181
227
Bug Tracker
182
228
===========
@@ -202,6 +248,7 @@ Contributors
202
248
* `Quartile <https://www.quartile.co >`_:
203
249
204
250
* Yoshi Tashiro
251
+ * Aung Ko Ko Lin
205
252
206
253
Maintainers
207
254
~~~~~~~~~~~
0 commit comments