Create a shortcut Relate to a one2many using a many2one as Eval

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('','du','Members')

class Party(metaclass=PoolMeta):
    __name__ = ''
   du = fields.Many2One('gnuhealth.du', 'DU')

class Patient(ModelSQL, ModelView):
   __name__ = 'gnuhealth.patient'
  name = fields.Many2One('', '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 model="ir.action.keyword"
            <field name="keyword">form_relate</field>
            <field name="model">gnuhealth.patient,-1</field>
            <field name="action" ref="act_du_form11"/>

Any help would be really appreciated. Thanks

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

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')
            patient_id = \
            du_id =

        data = {'res_id': [du_id]}
        return action, data
    def __setup__(cls):
        super(OpenPatientDU, cls).__setup__()
                'You need to select one Patient record',
                '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 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 model="ir.action.act_window" id="act_patient_du">
            <field name="name">Domiciliary Unit</field>
            <field name="res_model">gnuhealth.du</field>

        <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"/>

Maybe there is another better way to do it, but this one works fine to me.

There is no patient field on party. Maybe it could be solved with a function field. Thanks anyway.
Best regards.