Feeding search results to a domain criteria

42 views
Skip to first unread message

Khurram Shahzad

unread,
Jun 13, 2017, 1:24:25 AM6/13/17
to try...@googlegroups.com
Dear All,

I have defined a domain for a filed as follows:

blood_bags = fields.Many2Many('anth.request-bag', 'blood_request', 'blood_bag', 'Blood Bags', required=True, domain=[('state','=','cross_matched'), ('id', 'in', [1,2])])

Consider condition ('id', 'in', [1,2]) where I have hard-coded values 1 & 2. Is there a way that I can search a model and use the returned list here dynamically.
--
 
Regards,
Khurram.

Cédric Krier

unread,
Jun 13, 2017, 2:35:06 AM6/13/17
to try...@googlegroups.com
If those records have been created using XML data then you can use the
pyson.Id [1]. Otherwise you have to find a way to express the domain
using dot notation.


[1] http://doc.tryton.org/4.4/trytond/doc/ref/pyson.html?#trytond.pyson.Id

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

Sergi Almacellas Abellana

unread,
Jun 13, 2017, 3:15:34 AM6/13/17
to try...@googlegroups.com
El 13/06/17 a les 07:24, Khurram Shahzad ha escrit:
If the domain is applied on the field, you should use a One2Many
function field (which will do the compute and return the ids), and use
the following domain:

[('state', '=', 'cross_matched'), ('id', 'in',
Eval('your_function_field', [])]

Having said taht, I'm wondering why you want to use the ids, if you are
going to use a search clause on target model. You can use the '.' to
perform joins domain clauses. For example: Using 'direct_field.name'
will search on the name fields of the records related by the
'direct_field' field. Of course, the direct field must be a relation one.

Hope it helps.

--
Sergi Almacellas Abellana
www.koolpi.com
Twitter: @pokoli_srk

Khurram Shahzad

unread,
Jun 14, 2017, 3:16:34 AM6/14/17
to try...@googlegroups.com
Dear Cedric & Sergi,

Thanks for your responses.
These records have not been created using xml file.

The method by Sergi didn't work as well.

Infact, I want to search records on the basis of 'origin' model as well as 'target' model. Simply, I want to return those 'blood_bag' model objects whose 'state' is 'cross_matched' AND they have been cross-matched against 'blood_request'. The blood_request model is related to blood_bag.

Regards,
Khurram.

Cédric Krier

unread,
Jun 14, 2017, 3:45:06 AM6/14/17
to try...@googlegroups.com
On 2017-06-14 12:16, Khurram Shahzad wrote:
> Infact, I want to search records on the basis of 'origin' model as well as
> 'target' model. Simply, I want to return those 'blood_bag' model objects
> whose 'state' is 'cross_matched' AND they have been cross-matched against
> 'blood_request'. The blood_request model is related to blood_bag.

Without having the database schema/models, it is not possible to help
you.
Reply all
Reply to author
Forward
0 new messages