fransuar
(Francisco Maria Moyano Casco)
May 2, 2021, 10:13pm
1
Hi,
I trying to create a shortcut Relate to a one2many using a many2one as the Eval.
To be more specific, I have 3 models
class DU(ModelSQL, ModelView):
__name__ = 'gnuhealth.du'
(.....)
members = fields.One2Many('party.party','du','Members')
(.....)
class Party(metaclass=PoolMeta):
__name__ = 'party.party'
(......)
du = fields.Many2One('gnuhealth.du', 'DU')
(......)
class Patient(ModelSQL, ModelView):
__name__ = 'gnuhealth.patient'
(......)
name = fields.Many2One('party.party', 'Name')
(......)
So, the thing is that I want to create a shortcut from the gnuhealth.patient views to the du trough the name field, but have no success on it
<record model="ir.action.act_window" id="act_du_form11">
<field name="name">Domiciliary Unit</field>
<field name="res_model">gnuhealth.du</field>
<field name="domain" eval="[('members', '=', Eval('name'))]" pyson="1"/>
</record>
<record model="ir.action.keyword"
id="act_open_du_keyword10">
<field name="keyword">form_relate</field>
<field name="model">gnuhealth.patient,-1</field>
<field name="action" ref="act_du_form11"/>
</record>
Any help would be really appreciated. Thanks
Francisco
ced
(Cédric Krier)
May 3, 2021, 8:44am
2
You can only evaluate active_id
or active_ids
in action domain but not the value of a field.
So you must adapt the domain to this constraint like for example (if a patient
field exists on party): [('members.patient', '=', Eval('active_id')]
1 Like
fransuar
(Francisco Maria Moyano Casco)
May 3, 2021, 10:30am
3
Actually, I solved it last night using a wizard. It is a lot of code, but works.
The .py is:
class OpenPatientDU(Wizard):
'Create Appointment Evaluation'
__name__ = 'wizard.gnuhealth.patient.du'
start_state = 'patient_du'
patient_du = StateAction('health_patient_fiuner.act_patient_du')
def do_patient_du(self, action):
patient = Transaction().context.get('active_id')
try:
patient_id = \
Pool().get('gnuhealth.patient').browse([patient])[0]
except:
self.raise_user_error('no_record_selected')
try:
du_id = patient_id.name.du.id
except:
self.raise_user_error('no_du')
data = {'res_id': [du_id]}
action['views'].reverse()
return action, data
@classmethod
def __setup__(cls):
super(OpenPatientDU, cls).__setup__()
cls._error_messages.update({
'no_record_selected':
'You need to select one Patient record',
'no_du':
'This patient has no du',
})
and the .xml is:
<record model="ir.action.wizard" id="act_open_patient_du">
<field name="name">Domiciliary Unit</field>
<field name="wiz_name">wizard.gnuhealth.patient.du</field>
</record>
<record model="ir.action.keyword" id="act_open_patient_du_keyword">
<field name="keyword">form_relate</field>
<field name="model">gnuhealth.patient,-1</field>
<field name="action" ref="act_open_patient_du"/>
</record>
<record model="ir.action.act_window" id="act_patient_du">
<field name="name">Domiciliary Unit</field>
<field name="res_model">gnuhealth.du</field>
</record>
<record model="ir.action.act_window.view" id="act_patient_du_form">
<field name="view" ref="health.gnuhealth_du_view"/>
<field name="sequence" eval="10"/>
<field name="act_window" ref="act_patient_du"/>
</record>
Maybe there is another better way to do it, but this one works fine to me.
ced:
You can only evaluate active_id
or active_ids
in action domain but not the value of a field.
So you must adapt the domain to this constraint like for example (if a patient
field exists on party): [('members.patient', '=', Eval('active_id')]
There is no patient field on party. Maybe it could be solved with a function field. Thanks anyway.
Best regards.