Skip to content

Commit 1ea278a

Browse files
committed
[FIX] event selection
1 parent 206b2b5 commit 1ea278a

12 files changed

+906
-29
lines changed

spp_event_spec_loader/DEPLOYMENT_FIX.md

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
## Issue
44

5-
**Error**: "The model name must start with 'x_'."
5+
**Error**: "The model name must start with 'x\_'."
66

77
## Root Cause
88

9-
Odoo requires all manually created models (models with `state='manual'`) to have technical names that start with `x_`. This is an Odoo core constraint to distinguish manually created models from code-based models.
9+
Odoo requires all manually created models (models with `state='manual'`) to have technical names that start
10+
with `x_`. This is an Odoo core constraint to distinguish manually created models from code-based models.
1011

1112
When users define models in YAML like:
13+
1214
```yaml
1315
model: "spp.event.house.visit"
1416
```
@@ -24,6 +26,7 @@ The module now **automatically converts** model names to comply with Odoo's requ
2426
### Automatic Conversion
2527

2628
**User writes in YAML**:
29+
2730
```yaml
2831
event_types:
2932
- id: "house_visit"
@@ -32,6 +35,7 @@ event_types:
3235
```
3336

3437
**System automatically converts to**:
38+
3539
```python
3640
model_name: "x_spp_event_house_visit"
3741
```
@@ -57,18 +61,18 @@ model_name: "x_spp_event_house_visit"
5761
def _deploy_model(self):
5862
"""Create the dynamic event model"""
5963
self.ensure_one()
60-
64+
6165
# Ensure model name starts with x_ for manual models (Odoo requirement)
6266
model_name = self.technical_name
6367
if not model_name.startswith("x_"):
6468
# Convert spp.event.xxx to x_spp_event_xxx
6569
model_name = "x_" + model_name.replace(".", "_")
66-
_logger.info("Converting model name from %s to %s (Odoo requirement)",
70+
_logger.info("Converting model name from %s to %s (Odoo requirement)",
6771
self.technical_name, model_name)
68-
72+
6973
# Check if model already exists
7074
existing_model = self.env["ir.model"].search([("model", "=", model_name)], limit=1)
71-
75+
7276
# ... rest of the code uses model_name
7377
```
7478

@@ -78,12 +82,12 @@ def _deploy_model(self):
7882
def _deploy_views(self):
7983
"""Create tree and form views for the event type"""
8084
self.ensure_one()
81-
85+
8286
# Ensure we're using the correct model name (with x_ prefix)
8387
model_name = self.technical_name
8488
if not model_name.startswith("x_"):
8589
model_name = "x_" + model_name.replace(".", "_")
86-
90+
8791
# Generate views using converted model_name
8892
# ...
8993
```
@@ -95,16 +99,19 @@ def _deploy_views(self):
9599
### What Users See
96100

97101
1. **Write YAML with readable names**:
102+
98103
```yaml
99104
model: "spp.event.house.visit"
100105
```
101106

102107
2. **System logs conversion** (in server logs):
108+
103109
```
104110
Converting model name from spp.event.house.visit to x_spp_event_house_visit (Odoo requirement)
105111
```
106112

107113
3. **Deployment succeeds**:
114+
108115
```
109116
Created model x_spp_event_house_visit (ID: 123)
110117
```
@@ -114,6 +121,7 @@ def _deploy_views(self):
114121
### What Users Need to Know
115122

116123
✅ **Nothing changes for users!**
124+
117125
- Write model names as before: `spp.event.{name}`
118126
- System handles the conversion automatically
119127
- No manual intervention needed
@@ -124,12 +132,14 @@ def _deploy_views(self):
124132
## Benefits
125133

126134
### For Users:
135+
127136
- ✅ Write human-readable model names
128137
- ✅ No need to understand Odoo's `x_` requirement
129138
- ✅ No manual name conversion needed
130139
- ✅ Existing YAML files work without modification
131140

132141
### For System:
142+
133143
- ✅ Complies with Odoo core requirements
134144
- ✅ Models deploy successfully
135145
- ✅ No constraint violations
@@ -142,22 +152,26 @@ def _deploy_views(self):
142152
### Why Odoo Requires `x_` Prefix
143153

144154
Odoo uses naming conventions to distinguish:
155+
145156
- **Code-based models**: Defined in Python modules (e.g., `res.partner`, `account.move`)
146157
- **Manual models**: Created via UI or API (`ir.model`) - **MUST** start with `x_`
147158

148159
This prevents:
160+
149161
- Name conflicts with core Odoo models
150162
- Accidental override of system models
151163
- Confusion between module models and custom models
152164

153165
### Field Naming
154166

155167
Fields also follow similar rules:
168+
156169
- Manual fields must start with `x_`
157170
- Already implemented in the module
158171
- All dynamic fields use `x_` prefix
159172

160173
**Example**:
174+
161175
```python
162176
{
163177
"name": "x_summary", # ✅ Correct
@@ -173,22 +187,26 @@ Fields also follow similar rules:
173187

174188
### Test Cases Covered:
175189

176-
1. ✅ **Model without x_ prefix**
190+
1. ✅ **Model without x\_ prefix**
191+
177192
- Input: `spp.event.house.visit`
178193
- Output: `x_spp_event_house_visit`
179194
- Result: SUCCESS
180195

181196
2. ✅ **Model with dots**
197+
182198
- Input: `spp.event.compliance.check`
183199
- Output: `x_spp_event_compliance_check`
184200
- Result: SUCCESS
185201

186-
3. ✅ **Model already with x_**
202+
3. ✅ **Model already with x\_**
203+
187204
- Input: `x_custom_model`
188205
- Output: `x_custom_model` (no change)
189206
- Result: SUCCESS
190207

191208
4. ✅ **View deployment**
209+
192210
- Views created with converted model name
193211
- Result: SUCCESS
194212

@@ -205,10 +223,12 @@ Fields also follow similar rules:
205223
If you have already deployed event types (before this fix):
206224

207225
**Option 1: Keep existing models** (Recommended)
226+
208227
- Existing models with old names will continue to work
209228
- New deployments will use the correct naming
210229

211230
**Option 2: Redeploy**
231+
212232
1. Undeploy existing event types
213233
2. Delete old models via: Settings → Technical → Database Structure → Models
214234
3. Deploy again with automatic conversion
@@ -225,6 +245,7 @@ If you have already deployed event types (before this fix):
225245
## Documentation Updates
226246

227247
Updated files:
248+
228249
1. ✅ `README.rst` - Added model naming explanation
229250
2. ✅ `USAGE_GUIDE.md` - Added examples with conversions
230251
3. ✅ `program_spec_template.yaml` - Added conversion notes
@@ -238,25 +259,29 @@ Updated files:
238259
### Before Fix
239260

240261
**YAML**:
262+
241263
```yaml
242264
event_types:
243265
- model: "spp.event.house.visit"
244266
```
245267

246268
**Deployment**:
269+
247270
```
248271
❌ ERROR: The model name must start with 'x_'.
249272
```
250273
251274
### After Fix
252275
253276
**YAML** (same):
277+
254278
```yaml
255279
event_types:
256280
- model: "spp.event.house.visit"
257281
```
258282

259283
**Deployment**:
284+
260285
```
261286
✅ Converting model name from spp.event.house.visit to x_spp_event_house_visit
262287
✅ Created model x_spp_event_house_visit (ID: 123)
@@ -276,7 +301,6 @@ event_types:
276301

277302
---
278303

279-
**Version**: 17.0.1.0.2
280-
**Date**: November 2024
304+
**Version**: 17.0.1.0.2
305+
**Date**: November 2024
281306
**Status**: ✅ Resolved
282-

0 commit comments

Comments
 (0)