Skip to content

Commit 4180563

Browse files
authored
Merge pull request #38 from OpenSPP/refactor-structure-michael
[IMP] indicators customization to remove view extension
2 parents 47bdbd9 + 2d13666 commit 4180563

File tree

1 file changed

+9
-74
lines changed

1 file changed

+9
-74
lines changed

docs/developer_guide/customization/customizing_indicators.md

Lines changed: 9 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ Examples:
3333

3434
## Creating Indicators in a Module
3535

36-
In this scenario, we create a complete module that adds indicators to both Individual and Group registries. This follows the same pattern as custom fields but focuses on computed indicators.
36+
In this scenario, we create a module that adds indicators to both Individual and Group registries. This follows the same pattern as custom fields but focuses on computed indicators.
37+
38+
> **Note:**
39+
> If you use the `spp_custom_field` module, all fields defined on the model will be automatically exposed in the UI. You do **not** need to manually extend views.
3740
3841
### 1. Create Module Structure
3942

@@ -46,16 +49,13 @@ spp_custom_indicators/
4649
├── models/
4750
│ ├── __init__.py
4851
│ └── res_partner.py
49-
├── views/
50-
│ ├── individual_views.xml
51-
│ └── group_views.xml
5252
└── security/
5353
└── ir.model.access.csv
5454
```
5555

5656
### 2. Define Module Manifest
5757

58-
Create a manifest file that includes the proper dependencies and data files:
58+
Declare the dependency on `spp_custom_field` (and registry modules):
5959

6060
```python
6161
{
@@ -69,11 +69,10 @@ Create a manifest file that includes the proper dependencies and data files:
6969
"depends": [
7070
"g2p_registry_group",
7171
"g2p_registry_individual",
72+
"spp_custom_field", # Ensure this is included
7273
],
7374
"data": [
74-
"views/individual_views.xml",
75-
"views/group_views.xml",
76-
# "security/ir.model.access.csv", # not needed if you do not add new models
75+
# No need for view XML if using spp_custom_field
7776
],
7877
"application": False,
7978
"installable": True,
@@ -149,72 +148,10 @@ class G2PRegistrant(models.Model):
149148
partner.z_ind_indv_age_years = max(age, 0)
150149
```
151150

152-
### 4. Create View Extensions
153-
154-
Expose the indicators on both Individuals and Groups UI by extending the existing views.
155-
156-
```xml
157-
<odoo>
158-
<!-- Individual: show age indicator in form -->
159-
<record id="view_individuals_form_custom_indicators" model="ir.ui.view">
160-
<field name="name">view_individuals_form_custom_indicators</field>
161-
<field name="model">res.partner</field>
162-
<field name="inherit_id" ref="g2p_registry_individual.view_individuals_form" />
163-
<field name="arch" type="xml">
164-
<xpath expr="//page[@name='basic_info']/group/group[1]" position="after">
165-
<group colspan="2">
166-
<field name="z_ind_indv_age_years"/>
167-
</group>
168-
</xpath>
169-
</field>
170-
</record>
171-
172-
<!-- Individual: show age indicator in tree -->
173-
<record id="view_individuals_list_tree_custom_indicators" model="ir.ui.view">
174-
<field name="name">view_individuals_list_tree_custom_indicators</field>
175-
<field name="model">res.partner</field>
176-
<field name="inherit_id" ref="g2p_registry_individual.view_individuals_list_tree" />
177-
<field name="arch" type="xml">
178-
<xpath expr="//field[@name='address']" position="after">
179-
<field name="z_ind_indv_age_years" string="Age"/>
180-
</xpath>
181-
</field>
182-
</record>
183-
184-
<!-- Group: show indicators in form -->
185-
<record id="view_groups_form_custom_indicators" model="ir.ui.view">
186-
<field name="name">view_groups_form_custom_indicators</field>
187-
<field name="model">res.partner</field>
188-
<field name="inherit_id" ref="g2p_registry_group.view_groups_form" />
189-
<field name="arch" type="xml">
190-
<xpath expr="//page[@name='basic_info']/group/group[1]" position="after">
191-
<group colspan="2">
192-
<field name="z_ind_grp_num_children"/>
193-
<field name="z_ind_grp_is_single_head_hh"/>
194-
</group>
195-
</xpath>
196-
</field>
197-
</record>
198-
199-
<!-- Group: show indicators in tree -->
200-
<record id="view_groups_list_tree_custom_indicators" model="ir.ui.view">
201-
<field name="name">view_groups_list_tree_custom_indicators</field>
202-
<field name="model">res.partner</field>
203-
<field name="inherit_id" ref="g2p_registry_group.view_groups_list_tree" />
204-
<field name="arch" type="xml">
205-
<xpath expr="//field[@name='name']" position="after">
206-
<field name="z_ind_grp_num_children" string="Children"/>
207-
<field name="z_ind_grp_is_single_head_hh" string="Single Head"/>
208-
</xpath>
209-
</field>
210-
</record>
211-
</odoo>
212-
```
213-
214-
### 5. Install and Test
151+
### 4. Install and Test
215152

216153
1. Install the module through the Apps menu.
217-
2. Open the Individual and Group registries and verify the new indicators display in both list and form views.
154+
2. Open the Individual and Group registries and verify the new indicators display in both list and form views (handled automatically by `spp_custom_field`).
218155
3. Create or update records and ensure the indicators compute correctly.
219156
4. Test filtering and searching by indicator values.
220157

@@ -387,8 +324,6 @@ class TestGroupIndicators(TransactionCase):
387324
)
388325
```
389326

390-
391-
392327
## Common Indicator Patterns
393328

394329
### Age-Based Indicators

0 commit comments

Comments
 (0)