domain rule for selecting certain records

19 views
Skip to first unread message

Khurram Shahzad

unread,
Mar 19, 2018, 9:20:07 AM3/19/18
to try...@googlegroups.com
Hi All,

I have a 'AdmiittedPatient' class with following two fields:

patient = fields.One2Many('party.party','Patient')
bed_transfers = fields.One2Many('gnuhealth.bed.transfer', 'name',
        'Transfer History', readonly=True)

where  gnuhealth.bed.transfer ('BedTransfers') class has:
    bed_from = fields.Many2One('gnuhealth.hospital.bed', 'From',)
    bed_to = fields.Many2One('gnuhealth.hospital.bed', 'To',)

Now, I am trying to write a domain rule which will display those patients who were transferred to a Bed with id 15.

(Eval('15'), 'in', [Eval('bed_transfers',{}).get('bed_from', -1)])

But, it is failing with an error. Any help please?
--
 
Regards,
Khurram.

Cédric Krier

unread,
Mar 20, 2018, 12:25:05 PM3/20/18
to try...@googlegroups.com
On 2018-03-19 18:07, Khurram Shahzad wrote:
> I have a 'AdmiittedPatient' class with following two fields:
>
> patient = fields.One2Many('party.party','Patient')
> bed_transfers = fields.One2Many('gnuhealth.bed.transfer', 'name',
> 'Transfer History', readonly=True)
>
> where gnuhealth.bed.transfer ('BedTransfers') class has:
> bed_from = fields.Many2One('gnuhealth.hospital.bed', 'From',)
> bed_to = fields.Many2One('gnuhealth.hospital.bed', 'To',)
>
> Now, I am trying to write a domain rule which will display those patients
> who were transferred to a Bed with id 15.

What are you calling a "domain rule"?

> (Eval('15'), 'in', [Eval('bed_transfers',{}).get('bed_from', -1)])

Eval('15') can never work. If you want the number 15, you must type: 15


--
Cédric Krier - B2CK SPRL
Email/Jabber: cedric...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/

Khurram Shahzad

unread,
Mar 20, 2018, 1:05:06 PM3/20/18
to try...@googlegroups.com
On Tue, Mar 20, 2018 at 9:21 PM, Cédric Krier <cedric...@b2ck.com> wrote:
On 2018-03-19 18:07, Khurram Shahzad wrote:
> I have a 'AdmiittedPatient' class with following two fields:
>
> patient = fields.One2Many('party.party','Patient')
> bed_transfers = fields.One2Many('gnuhealth.bed.transfer', 'name',
>         'Transfer History', readonly=True)
>
> where  gnuhealth.bed.transfer ('BedTransfers') class has:
>     bed_from = fields.Many2One('gnuhealth.hospital.bed', 'From',)
>     bed_to = fields.Many2One('gnuhealth.hospital.bed', 'To',)
>
> Now, I am trying to write a domain rule which will display those patients
> who were transferred to a Bed with id 15.

What are you calling a "domain rule"?
Sorry, I was referring to "domain clause", I was writing in my module's view.xml file.
 

> (Eval('15'), 'in', [Eval('bed_transfers',{}).get('bed_from', -1)])

Eval('15') can never work. If you want the number 15, you must type: 15

Changing it to 15 didn't work either. In fact, 'bed_transfers' is a one2Many field. What I want is to get list  values of 'bed_from' field from every record of this one2Many field. I think, the above-given code will consider 'bed_tranfers' a dictionary and return value of 'bed_from' it.


--
Cédric Krier - B2CK SPRL
Email/Jabber: cedric...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/

--
You received this message because you are subscribed to the Google Groups "tryton" group.
To view this discussion on the web visit https://groups.google.com/d/msgid/tryton/20180320162158.GW3935%40kei.



--
 
Regards,
Khurram.

Cédric Krier

unread,
Mar 20, 2018, 2:50:06 PM3/20/18
to try...@googlegroups.com
On 2018-03-20 21:47, Khurram Shahzad wrote:
> On Tue, Mar 20, 2018 at 9:21 PM, Cédric Krier <cedric...@b2ck.com> wrote:
>
> > On 2018-03-19 18:07, Khurram Shahzad wrote:
> > > I have a 'AdmiittedPatient' class with following two fields:
> > >
> > > patient = fields.One2Many('party.party','Patient')
> > > bed_transfers = fields.One2Many('gnuhealth.bed.transfer', 'name',
> > > 'Transfer History', readonly=True)
> > >
> > > where gnuhealth.bed.transfer ('BedTransfers') class has:
> > > bed_from = fields.Many2One('gnuhealth.hospital.bed', 'From',)
> > > bed_to = fields.Many2One('gnuhealth.hospital.bed', 'To',)
> > >
> > > Now, I am trying to write a domain rule which will display those patients
> > > who were transferred to a Bed with id 15.
> >
> > What are you calling a "domain rule"?
> >
> Sorry, I was referring to "domain clause", I was writing in my module's
> view.xml file.

I do not see where you try to put this domain. Is it a
ir.action.act_window.domain ?

> > > (Eval('15'), 'in', [Eval('bed_transfers',{}).get('bed_from', -1)])
> >
> > Eval('15') can never work. If you want the number 15, you must type: 15
> >
>
> Changing it to 15 didn't work either. In fact, 'bed_transfers' is a
> one2Many field. What I want is to get list values of 'bed_from' field from
> every record of this one2Many field. I think, the above-given code will
> consider 'bed_tranfers' a dictionary and return value of 'bed_from' it.

The result of the evaluation of a One2Many is a list of id. You can not
retrieve a specific field from the list.
You need to create a Function field that provide you the right data at
the main record.

Khurram Shahzad

unread,
Mar 20, 2018, 3:25:05 PM3/20/18
to try...@googlegroups.com


On Mar 20, 2018 11:50 PM, "Cédric Krier" <cedric...@b2ck.com> wrote:
On 2018-03-20 21:47, Khurram Shahzad wrote:
> On Tue, Mar 20, 2018 at 9:21 PM, Cédric Krier <cedric...@b2ck.com> wrote:
>
> > On 2018-03-19 18:07, Khurram Shahzad wrote:
> > > I have a 'AdmiittedPatient' class with following two fields:
> > >
> > > patient = fields.One2Many('party.party','Patient')
> > > bed_transfers = fields.One2Many('gnuhealth.bed.transfer', 'name',
> > >         'Transfer History', readonly=True)
> > >
> > > where  gnuhealth.bed.transfer ('BedTransfers') class has:
> > >     bed_from = fields.Many2One('gnuhealth.hospital.bed', 'From',)
> > >     bed_to = fields.Many2One('gnuhealth.hospital.bed', 'To',)
> > >
> > > Now, I am trying to write a domain rule which will display those patients
> > > who were transferred to a Bed with id 15.
> >
> > What are you calling a "domain rule"?
> >
> Sorry, I was referring to "domain clause", I was writing in my module's
> view.xml file.

I do not see where you try to put this domain. Is it a
ir.action.act_window.domain ?

Yes, it is!

> > > (Eval('15'), 'in', [Eval('bed_transfers',{}).get('bed_from', -1)])
> >
> > Eval('15') can never work. If you want the number 15, you must type: 15
> >
>
> Changing it to 15 didn't work either. In fact, 'bed_transfers' is a
> one2Many field. What I want is to get list  values of 'bed_from' field from
> every record of this one2Many field. I think, the above-given code will
> consider 'bed_tranfers' a dictionary and return value of 'bed_from' it.

The result of the evaluation of a One2Many is a list of id. You can not
retrieve a specific field from the list.
You need to create a Function field that provide you the right data at
the main record.

Ok. I will create a function field. Thanks for the clue.

Reply all
Reply to author
Forward
0 new messages