Sorry, my last message was rejected for top-posting. 

I already solved it aided by friends from Silix.

It is not clear what you have tried. 
> Also if you want us to help you, you must provide more information. 
> What was the code you tried? What was the error? etc. 
>

I tried to used negative index -1 

(....)
    housing_conditions = fields.One2Many('gnuhealth.housing','du',
            'Housing Conditions')
    
    critical_housing = fields.Function(fields.Boolean('Vivienda Critica'),
        'get_critical_housing',searcher='search_critical_housing')

    @classmethod
    def search_critical_housing(cls,name,clause):
      res = []
      value = clause[2]
      if(cls.housing_conditions._get_size()!=0):
         this_one = cls.housing_conditions[-1].critical_housing
         res.append(('this_one',clause[1],value))
      return res
(....)

And gave me this error:

(...)
 File "/trytond/model/modelsql.py", line 1146, in convert
    expression = field.convert_domain(domain, tables, cls)
  File "/trytond/model/fields/function.py", line 64, in convert_domain
    return getattr(Model, self.searcher)(name, domain)
  File "/trytond/modules/z_DU/health.py", line 46, in 
search_critical_housing
    this_one = cls.housing_conditions[-1].critical_housing
TypeError: 'One2Many' object does not support indexing
(...)


I could solved with this

    @classmethod
    def search_critical_housing(cls, name, clause):
         cursor = Transaction().cursor
         pool = Pool()
         DomiciliaryUnit = pool.get('gnuhealth.du')
         HousingConditions = pool.get('gnuhealth.housing')
         cursor.execute('SELECT du.id '
             'FROM "' + DomiciliaryUnit._table + '" du '
                 'INNER JOIN ( '
                     'SELECT DISTINCT ON (du) du, critical_housing '
                     'FROM "' + HousingConditions._table + '" '
                     'ORDER BY du, id DESC '
                 ') last_hc '
                 'ON du.id = last_hc.du '
             'WHERE last_hc.critical_housing = TRUE')
         has_critical_housing = cursor.fetchall()
         field, op, operand = clause
         if (op, operand) in (('=', True), ('!=', False)):
             return [('id', 'in', has_critical_housing)]
         elif (op, operand) in (('=', False), ('!=', True)):
             return [('id', 'not in', has_critical_housing)]
         else:
             return []


Thanks anyway :) !!!

             Francisco

 

-- 
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/f621b415-e369-46b2-91c2-da5877f6befe%40googlegroups.com.

Reply via email to