Skip to content

Commit 2cae18e

Browse files
[MIG] web_form_banner: Migration to 17.0
1 parent 1b75477 commit 2cae18e

File tree

5 files changed

+36
-28
lines changed

5 files changed

+36
-28
lines changed

web_form_banner/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
33
{
44
"name": "Web Form Banner",
5-
"version": "16.0.1.0.0",
5+
"version": "17.0.1.0.0",
66
"category": "Web",
77
"author": "Quartile, Odoo Community Association (OCA)",
88
"website": "https://github.com/OCA/web",

web_form_banner/models/web_form_banner_rule.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
33

44
import logging
5-
from functools import lru_cache
65
from string import Template
76

87
from dateutil import parser as dateparse
@@ -39,7 +38,7 @@ def _extract_m2o_id(v):
3938
"""Normalize many2one values to an integer id or False."""
4039
if isinstance(v, int):
4140
return v
42-
if isinstance(v, (list, tuple)) and v and isinstance(v[0], int):
41+
if isinstance(v, list | tuple) and v and isinstance(v[0], int):
4342
return v[0]
4443
if isinstance(v, dict):
4544
m2o_id = v.get("res_id") or v.get("id")
@@ -49,12 +48,12 @@ def _extract_m2o_id(v):
4948

5049

5150
def _m2m_items(value):
52-
if isinstance(value, (list, tuple)):
51+
if isinstance(value, list | tuple):
5352
return value
5453
if isinstance(value, dict):
55-
if isinstance(value.get("resIds"), (list, tuple)):
54+
if isinstance(value.get("resIds"), list | tuple):
5655
return value["resIds"]
57-
if isinstance(value.get("data"), (list, tuple)):
56+
if isinstance(value.get("data"), list | tuple):
5857
return value["data"]
5958
return None
6059

@@ -172,9 +171,8 @@ def _build_form_url(self, rec):
172171
_logger.exception("Failed building form URL for %s", rec)
173172
return ""
174173

175-
@lru_cache(maxsize=1)
174+
@api.model
176175
def _base_eval_ctx_static(self):
177-
# Only static, import-heavy items
178176
return {
179177
"time": tools.safe_eval.time,
180178
"datetime": tools.safe_eval.datetime,
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
2-
access_web_form_banner_rule_all,web_form_banner_rule_all,model_web_form_banner_rule,,1,0,0,0
2+
access_web_form_banner_rule_public,web_form_banner_rule_public,model_web_form_banner_rule,base.group_public,1,0,0,0
3+
access_web_form_banner_rule_portal,web_form_banner_rule_portal,model_web_form_banner_rule,base.group_portal,1,0,0,0
4+
access_web_form_banner_rule_user,web_form_banner_rule_user,model_web_form_banner_rule,base.group_user,1,0,0,0
35
access_web_form_banner_rule_group_system,web_form_banner_rule_group_system,model_web_form_banner_rule,base.group_system,1,1,1,1

web_form_banner/static/src/js/web_form_banner.esm.js

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
// License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
44

55
import {patch} from "@web/core/utils/patch";
6-
import {onMounted, onPatched, onWillUnmount} from "@odoo/owl";
6+
import {onMounted, onWillUnmount} from "@odoo/owl";
77
import {FormController} from "@web/views/form/form_controller";
8+
import {Record} from "@web/model/relational_model/record";
89

910
const recRoot = (c) => (c && c.model && c.model.root) || null;
1011
const childSpan = (el) => {
@@ -29,11 +30,12 @@ function normalizeValue(v) {
2930
if (v === null || v === undefined) return v; // Null/undefined
3031
const t = typeof v;
3132
if (t === "string" || t === "number" || t === "boolean") return v;
32-
if (Array.isArray(v) && v.length === 2 && typeof v[1] === "string") return v[0]; // M2o [id, name]
33+
if (Array.isArray(v))
34+
return v.length === 2 && typeof v[1] === "string" ? v[0] : [...v]; // M2o id or cloned m2m ids
3335
if (t === "object") {
3436
if (typeof v.res_id === "number") return v.res_id; // M2o snapshot
3537
if (typeof v.id === "number") return v.id; // M2o env
36-
if (Array.isArray(v.resIds)) return v.resIds; // M2m
38+
if (Array.isArray(v._currentIds)) return [...v._currentIds]; // M2m
3739
}
3840
return undefined; // Ignore others (e.g., command lists)
3941
}
@@ -119,26 +121,35 @@ function tick(ctrl) {
119121
}, 180);
120122
}
121123

122-
patch(FormController.prototype, "web_form_banner.lean", {
124+
patch(FormController.prototype, {
123125
setup() {
124-
this._super(...arguments);
126+
super.setup();
127+
this.model.__controller = this;
125128
onMounted(() => scheduleRefresh(this));
126-
onPatched(() => tick(this));
127129
onWillUnmount(() => clearTimeout(this.__wfbTimer));
128130
},
129-
async edit() {
130-
const r = await this._super(...arguments);
131-
scheduleRefresh(this);
132-
return r;
133-
},
134131
async discard() {
135-
const r = await this._super(...arguments);
132+
const r = await super.discard(...arguments);
136133
scheduleRefresh(this);
137134
return r;
138135
},
139-
async saveButtonClicked(p = {}) {
140-
const ok = await this._super(p);
136+
async save(p = {}) {
137+
const ok = await super.save(p);
141138
if (ok) scheduleRefresh(this);
142139
return ok;
143140
},
144141
});
142+
143+
const _superApplyChanges = Record.prototype._applyChanges;
144+
patch(Record.prototype, {
145+
_applyChanges(changes, serverChanges = {}) {
146+
const res = _superApplyChanges.call(this, changes, serverChanges);
147+
try {
148+
if (this.model && this.model.root === this) {
149+
const ctrl = this.model.__controller;
150+
if (ctrl) tick(ctrl);
151+
}
152+
} catch {}
153+
return res;
154+
},
155+
});

web_form_banner/views/web_form_banner_rule_views.xml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
name="web_ribbon"
3939
title="Archived"
4040
bg_color="bg-danger"
41-
attrs="{'invisible': [('active', '=', True)]}"
41+
invisible="active == True"
4242
/>
4343
<div class="oe_title">
4444
<label for="name" class="oe_edit_only" />
@@ -77,10 +77,7 @@
7777
name="message"
7878
placeholder="This is a ${severity} message."
7979
/>
80-
<field
81-
name="message_is_html"
82-
attrs="{'invisible':[('message','=',False)]}"
83-
/>
80+
<field name="message_is_html" invisible="message == False" />
8481
</group>
8582
<notebook>
8683
<page

0 commit comments

Comments
 (0)