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.
Yes, you can create your own module that:
- Adds an on_change attribute to the field in the view
- Creates a method that gets called by the on_change attribute in #1. The method returns False if the date chosen is greater than today.
For example, in your form view you would have:
<field name="my_date" on_change="onchange_date(my_date)"/>
Then in your object you would put:
from datetime import datetime from openerp.tools import DEFAULT_SERVER_DATE_FORMAT def onchange_date(self, cr, uid, ids, my_date, context=None): if datetime.strptime(my_date, DEFAULT_SERVER_DATE_FORMAT).date() > datetime.now().date(): return False return my_date
Edit: add example of constraint mentioned by Priyesh:
A constraint has the added benefit that it doesn't depend on the client interface calling the on_change method. It always gets checked when a value is written to the field.
def _check_date(self, cr, uid, ids, context=None): obj = self.browse(cr, uid, ids, context=context) if datetime.strptime(obj.my_date, DEFAULT_SERVER_DATE_FORMAT).date() > datetime.now().date(): return False return True _constraints = [(_check_date, 'Date is in the future!', [my_date])]
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: 4/2/13, 5:40 PM|
|Seen: 4114 times|
|Last updated: 3/16/15, 8:10 AM|