How to compare Date using Between


I’m working with a query using Between to compare my dates, but i got this error

Traceback (most recent call last):
  File "/home/julio/Development/workspace-python/tryton/facturacion/trytond/trytond/protocols/", line 181, in _dispatch
    result = rpc.result(meth(*c_args, **c_kwargs))
  File "/home/julio/Development/workspace-python/tryton/facturacion/trytond/trytond/model/", line 159, in wrapper
    return func(cls, *args, **kwargs)
  File "/home/julio/Development/workspace-python/tryton/facturacion/trytond/trytond/model/", line 674, in create
  File "/home/julio/Development/workspace-python/tryton/facturacion/trytond/trytond/model/", line 76, in wrapper
    return func(*args, **kwargs)
  File "/home/julio/Development/workspace-python/tryton/facturacion/trytond/trytond/model/", line 1344, in _validate
  File "/home/julio/Development/workspace-python/tryton/facturacion/trytond/trytond/modules/account_invoice_py/", line 143, in validate
  File "/home/julio/Development/workspace-python/tryton/facturacion/trytond/trytond/backend/postgresql/", line 69, in execute
    cursor.execute(self, sql, args)
psycopg2.ProgrammingError: can't adapt type 'Date'

My query:

                                                    Between(cls.begin_date,stamped.begin_date, stamped.end_date),  
                                                    Between(cls.end_date,  stamped.begin_date, stamped.end_date)

All my fields are fields.Date.

I am newbie using python-sql and still don’t understand it well.

Thanks for your help…

You can not use Field instance in SQL query, you must use Column which can be retrieve from sql_column method.
Anyway I do not see why using plain SQL query when you can do the same using with the parameter count=True.

I just try with sql plain because until now that was the only way that I known. I will try to convert my dates fields to build my query.

Search method allows only And operator? Or can I use OR too?

Both see Domain — trytond latest documentation

So I just need treat it like I do with domain parameter of fields? :thinking:

Yes, domains are used to build search filters and also field constraints.

It worked.

I used search and my code looks so clean and readable with it.


1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.