Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM | e-Commerce | Accounting | Inventory | PoS | Project management | MRP | etc.
I've created my first module (a campsite reservation module) and have everything functioning as I'd like except I haven't been able to figure out how to make a constraint to prevent date overlap on a campsite booking.
I have two models, Campsite and Booking. I've linked to Sales for customer information. Booking contains start_date, end_date, site_id, customer_id and duration fields. When making a new booking, I'd like a constraint that checks to see if the requested campsite is already booked for the requested date range. I have some basic Python and SQL knowledge but I can't figure out a constraint that checks "incoming" dates against "existing" dates in the database. I know we're supposed to be concise, but thanks for any help!
You can use this script:-
_constraints = [
(_check_date, 'You can not book same day!', ['start_date','end_date']),
def _check_date(self, cr, uid, ids):
for item in self.browse(cr, uid, ids):
item_ids = self.search(cr, uid, [('start_date', '<=', item.end_date), ('end_date', '>=', item.start_date), ('site_id', '=', item.site_id.id), ('id', '<>', item.id)])
Hope this helps. If any querys please let me know.
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 platform 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.Register
Odoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.Test it now
|Asked: 2/12/15, 6:00 PM|
|Seen: 1256 times|
|Last updated: 3/16/15, 8:10 AM|