1

I'm using GNU Health on Tryton and want to do a domain search in a view using PYSON and fields related to the current user. The problem is that I don't know how to reference the fields related to the current user.

I want to check if the user is_healthprof and if that's the case filter using the lastname field of the current user as health professional lastname so that the user will only see the data related to him. I tried the following code in my xml view file but as I don't know how to do the trick is not working.

<field name="domain">[('appointment_date', '>=', DateTime(hour=0, minute=0, second=0, microsecond=0)),(If(Eval('party.party.is_healthprof', -1),('healthprof.lastname','=',party.party.lastname)))]</field>
vvvvv
  • 25,404
  • 19
  • 49
  • 81

1 Answers1

0

Instead of using a domain you should add an access rule that depends on the is_healthproft flag of the user. See:

http://doc.tryton.org/3.8/trytond/doc/topics/access_rights.html?highlight=access

Using access rules will enforce the domain for every operation on the model, so if the user accesses the model for a relation field or for a different action, the access rule will also apply.

BTW, instead of creating a flag in the user to indicate if is healthproft, i think it's better to create a user group for Healtproft and associate the users with this group (and so the access group).

Hope it helps.

pokoli
  • 1,045
  • 7
  • 15
  • So just add the acces rule (as mentioned in the doc) to this user group. – pokoli Mar 27 '16 at 18:36
  • I did as you said but I'm not able to reference the proper 'id'. I added the domain [('healthprof', '=', user.id)] but the 'id' I get is the one included at the the table res_user as an internal user. I have to reference to the one included in the gnuhealth_healthprofessional table (gnuhealth_healthprofessional.id) that is linked to party_party.id by gnuhealth_healthprofessional.name. The id at party_party is connected to the internal user by party_party.internal_user. I tried to follow the documentation but I'm a newbie and can't make it work. Thanks in advanced – Carlos Ibrahim Arias Apr 15 '16 at 17:02
  • You have to use the relations to get the proper id. Something like: [('healthprof', '=', user.party.gnu_professional.id)] – pokoli Apr 18 '16 at 06:56
  • Thanks pokoli but I can't make it work. Anyway, trying to find a workaround, do you know how can I get the party.id if we have, as in this case, the user.id? – Carlos Ibrahim Arias May 05 '16 at 21:19
  • The only way to access the party is through the relations as I explained in the previous message. – pokoli May 09 '16 at 07:08
  • I tried with [('healthprof', '=', user.party.gnu_professional.id)] as explained but it's not working. I also tried [('healthprof', '=', user.party.id)] and [('healthprof', '=', user.party_party.id)] but they don't work as the previous example. I've also tried with eval but I don't really understand how it works and I always get the message 'The domain of the rule is incorrect'. That's why I asked the example to get the party id as an example of referring to a child in order to understand how to use relations – Carlos Ibrahim Arias May 09 '16 at 15:15