Skip to content

Commit b9585cd

Browse files
[FIX] spp_code_generator: Fixed the action_process_entities to consider the entitles name (Household or Individual)
1 parent 0610e2a commit b9585cd

3 files changed

Lines changed: 99 additions & 23 deletions

File tree

spp_code_generator/IMPLEMENTATION_GUIDE.md

Lines changed: 51 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,20 @@ YAML File Upload → Validation → Parse → Extract Entities → Create Fields
103103
**Field Naming Convention**:
104104

105105
```
106-
YAML: "hh_id"
107-
Odoo: "z_cst_hh_id"
106+
YAML Entity: "Household", Field: "hh_id"
107+
Odoo: "x_cst_grp_hh_id"
108+
109+
YAML Entity: "Individual", Field: "person_id"
110+
Odoo: "x_cst_indv_person_id"
108111
109112
Prefix breakdown:
110-
- z_ : OpenSPP custom field prefix
113+
- x_ : Odoo custom field prefix
111114
- cst_ : Custom (not indicator)
112-
- hh_id : Original field ID from YAML
115+
- grp_ : Group/Household fields
116+
- indv_ : Individual fields
117+
- field_id : Original field ID from YAML
118+
119+
This matches the spp_custom_fields_ui module conventions for proper UI integration.
113120
```
114121

115122
**Args**:
@@ -207,22 +214,24 @@ entities:
207214
208215
For the above YAML, the following fields would be created in `res.partner`:
209216

210-
| YAML Field ID | Odoo Field Name | Type | Required |
211-
| ------------- | --------------- | --------- | -------- |
212-
| hh_id | z_cst_hh_id | Char | Yes |
213-
| province | z_cst_province | Char | No |
214-
| person_id | z_cst_person_id | Char | Yes |
215-
| birthdate | z_cst_birthdate | Date | Yes |
216-
| gender | z_cst_gender | Selection | Yes |
217+
| Entity | YAML Field ID | Odoo Field Name | Type | Required |
218+
| ---------- | ------------- | -------------------- | --------- | -------- |
219+
| Household | hh_id | x_cst_grp_hh_id | Char | Yes |
220+
| Household | province | x_cst_grp_province | Char | No |
221+
| Individual | person_id | x_cst_indv_person_id | Char | Yes |
222+
| Individual | birthdate | x_cst_indv_birthdate | Date | Yes |
223+
| Individual | gender | x_cst_indv_gender | Selection | Yes |
217224

218225
### Selection Field Example
219226

220-
For `gender` enum field:
227+
For `gender` enum field in Individual entity:
221228

222229
```python
223-
Field: z_cst_gender
230+
Field: x_cst_indv_gender
224231
Type: Selection
225232
Values: [('Female', 'Female'), ('Male', 'Male')]
233+
Target Type: indv
234+
Field Category: cst
226235
```
227236

228237
---
@@ -324,17 +333,39 @@ Completed at: 2025-10-23 10:30:15
324333
325334
### Field Naming
326335
327-
Follows OpenSPP field naming patterns:
336+
Follows `spp_custom_fields_ui` field naming patterns:
337+
338+
- `x_`: Odoo custom field prefix (standard)
339+
- `cst_`: Custom/arbitrary fields (not indicators `ind_`)
340+
- `grp_`: Group/Household entity fields
341+
- `indv_`: Individual entity fields
328342
329-
- `z_`: General prefix for custom fields
330-
- `cst_`: Custom/arbitrary fields (not indicators)
331-
- Example: `z_cst_hh_id`
343+
**Examples**:
344+
345+
- Group field: `x_cst_grp_hh_id`
346+
- Individual field: `x_cst_indv_person_id`
332347
333348
### Why This Pattern?
334349
335-
1. **z\_**: Groups all custom fields together
336-
2. **cst\_**: Distinguishes from indicators (`ind_`)
337-
3. **Prevents conflicts**: With standard Odoo fields
350+
1. **x\_**: Standard Odoo prefix for custom fields
351+
2. **cst\_**: Distinguishes from computed indicators (`ind_`)
352+
3. **grp\_/indv\_**: Entity-specific prefix for UI filtering
353+
4. **Integration**: Matches `spp_custom_fields_ui` for proper display in registry UIs
354+
5. **Prevents conflicts**: With standard Odoo and OpenSPP fields
355+
356+
### spp_custom_fields_ui Integration
357+
358+
Created fields include metadata for `spp_custom_fields_ui`:
359+
360+
- `target_type`: "grp" or "indv"
361+
- `field_category`: "cst" (custom)
362+
- `draft_name`: Original field ID from YAML
363+
364+
This ensures fields appear correctly in:
365+
366+
- Group/Household forms
367+
- Individual forms
368+
- Custom field management UI
338369
339370
---
340371

spp_code_generator/__manifest__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@
1818
"g2p_registry_group",
1919
"g2p_registry_membership",
2020
"g2p_programs",
21+
"spp_custom_field",
22+
"spp_custom_fields_ui",
2123
],
24+
"external_dependencies": {
25+
"python": ["PyYAML"],
26+
},
2227
"data": [
2328
"security/ir.model.access.csv",
2429
"views/code_generator_views.xml",

spp_code_generator/models/code_generator.py

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,35 @@ def _get_odoo_field_type(self, yaml_field_type):
100100
}
101101
return type_mapping.get(yaml_field_type, "char")
102102

103+
def _get_entity_prefix(self, entity_name):
104+
"""
105+
Determine the field prefix based on entity type.
106+
107+
Args:
108+
entity_name (str): Name of the entity (e.g., 'Household', 'Individual')
109+
110+
Returns:
111+
str: Field prefix following OpenSPP conventions
112+
- 'x_cst_grp_' for groups/households
113+
- 'x_cst_indv_' for individuals
114+
"""
115+
entity_lower = entity_name.lower()
116+
117+
# Check if entity is a group/household
118+
if any(keyword in entity_lower for keyword in ["household", "group", "family"]):
119+
return "x_cst_grp"
120+
# Check if entity is an individual
121+
elif any(keyword in entity_lower for keyword in ["individual", "member", "person"]):
122+
return "x_cst_indv"
123+
else:
124+
# Default to group if uncertain
125+
_logger.warning(
126+
"Unknown entity type '%s', defaulting to group prefix. "
127+
"Consider using 'Household' or 'Individual' as entity names.",
128+
entity_name,
129+
)
130+
return "x_cst_grp"
131+
103132
def _create_field_from_spec(self, entity_name, field_spec):
104133
"""
105134
Create an Odoo field in res.partner based on field specification from YAML.
@@ -120,6 +149,10 @@ def _create_field_from_spec(self, entity_name, field_spec):
120149
'values': [...], # Optional: For enum types, list of allowed values
121150
'description': '...' # Optional: Help text for the field
122151
}
152+
153+
Field Naming Convention (matching spp_custom_fields_ui):
154+
- Groups/Households: x_cst_grp_{field_id}
155+
- Individuals: x_cst_indv_{field_id}
123156
"""
124157
self.ensure_one()
125158

@@ -135,9 +168,10 @@ def _create_field_from_spec(self, entity_name, field_spec):
135168
_logger.warning("Skipping field with incomplete specification: %s", field_spec)
136169
return None
137170

138-
# Prepare field name with prefix based on OpenSPP conventions
139-
# z_cst_ prefix for custom fields
140-
field_name = f"z_cst_{field_id}"
171+
# Prepare field name with prefix based on entity type
172+
# Follows spp_custom_fields_ui convention: x_cst_grp_ or x_cst_indv_
173+
prefix = self._get_entity_prefix(entity_name)
174+
field_name = f"{prefix}_{field_id}"
141175

142176
# Check if field already exists
143177
IrModelFields = self.env["ir.model.fields"]
@@ -155,6 +189,9 @@ def _create_field_from_spec(self, entity_name, field_spec):
155189
# Map YAML type to Odoo type
156190
odoo_field_type = self._get_odoo_field_type(field_type)
157191

192+
# Determine target type for spp_custom_fields_ui integration
193+
target_type = "grp" if "grp" in prefix else "indv"
194+
158195
# Prepare field values
159196
field_values = {
160197
"name": field_name,
@@ -165,6 +202,9 @@ def _create_field_from_spec(self, entity_name, field_spec):
165202
"required": is_required,
166203
"help": field_description or f"Custom field for {entity_name}: {field_label}",
167204
"state": "manual", # Manual fields can be deleted
205+
"target_type": target_type, # For spp_custom_fields_ui: 'grp' or 'indv'
206+
"field_category": "cst", # For spp_custom_fields_ui: 'cst' (custom)
207+
"draft_name": field_id, # Original field ID from YAML
168208
}
169209

170210
# Handle selection/enum fields

0 commit comments

Comments
 (0)