Hi,
Appreciate if you could help out with this domain for states.
Database model overview
- risk_state : Master table for all risk states in various risk assessment
- risk_flow : Flow for a particular risk assessment
- risk_flow_lines: The flow path for a particular risk assessment
Code
RiskStateModel(models.Model):
name : string
RiskFlowModel(models.Model):
name : string
risk_assessment_name: string
risk_flow_lines: One2Many( comodel = 'risk_flow_line' )
RiskFlowLine( models.Model)
inbound_state: Many2one( comodel = 'RiskStateModel' )
outbound_state : Many2Many( comodel = 'RiskStateModel')
The above setup allows me to define a RiskFlowModel for different type of risk assessments (e.g. Control Assessment, Loss Event, etc).
The issue I face is when I want to get the domain of possible states in a risk assessment i.e.
ControlAssessmentModel(model.Model)
current_state_id = Many2One( comodel = 'RiskStateModel')
domain_for_next_risk_states = Many2One( comodel = 'RiskStateModel')
For example suppose the following is setup in the database
Risk State Model
id | name |
0 | Draft |
1 | Control Assessment Required |
2 |
Control Assessment OK
|
3 |
Control Assessment Fail |
Risk Flow Model
id | Name |
1 | Control Assessment |
Risk Flow Lines
id | risk_flow_id |
inbound_state_id | risk_state_flow_id (Many2Many rel) |
1 | 1 ( i.e. Control Assessment ) | 0 (i.e. Draft) | 1 ( 1st step is a control assesment) |
2 | 1 | 1 | 2 |
Risk Flow Many2Many Model
risk_flow_line_id | outbound_state_id | comment |
1 | 1 | Draft can only go to assessment required |
2 | 2 | Assessment required can go to Control Assessment OK |
2 | 2 |
Assessment required can go to Control Assessment Fail |
How do I write the domain in the Control Assessment Model to give the available next risk assessment states?
Options
- Write a function : I can write a function that returns the following but I don't know how to get the right trigger for it
return { 'domain' : {'next_state_id_domain' : [ ('id' , 'in' , state_ids ) ]} }
2. Web domain field
I have used web domain field before but I am not sure how to modify it for this use case.
Appreciate your comments - this use case is quite practical for risk assessments when there is no fixed path as things happen all the time and you need to be able to dynamically define flows.