Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Date Comparision doesn't work fine in openerp7

By
vivek
on 9/26/13, 9:46 AM 801 views

Hi, I have 2 dates (from date and to date) in hand. I would like to know if there's another record in the table that falls on the same range. I use openerp search function to do that

below is my code. Kindly see if my date search with operator <= is correct and is there anything that i wrongly understood.

exist_ids = self.search(cr, uid, [('partner_id','=',customer),('sys_conf_name','ilike',sys_conf_name.strip()),('contract_start_date','<=',cont_start_date),('contract_end_date','>=',cont_end_date)])
if exist_ids:
      raise osv.except_osv(_('Error!!'), "Already there exist a Contract for the same customer, same product and the same date range!!")

Thanks for your time.

0

Andreas Brueckl

--Andreas Brueckl--
5056
| 7 8 7
Vienna, Austria
--Andreas Brueckl--
OpenERP Consulting and Development
Andreas Brueckl
On 9/26/13, 10:36 AM

For date values in python and SQL you have to use the format %Y-%m-%d, e.g. "2013-09-26".

So I think the format of cont_start_date is not correct.

Hey Andreas, thanks for your reply. cont_start_date is a variable name. The actual value is exactly in the same format as you specified "2013-09-26". Please suggest me. Thanks

vivek
on 9/26/13, 10:41 AM

You only query whether there is a contract which starts before cont_start_date and ends after cont_end_date. If you want to see all overlapping contracts you have to consider also other cases!

Andreas Brueckl
on 9/26/13, 11:19 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 9/26/13, 9:46 AM
Seen: 801 times
Last updated: 3/16/15, 8:10 AM