Odoo Help
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 want to create a alert message, when i select date field as 12/12/1400
Hi i want to create a age calculator in openerp.
in my age calculator, if i select date of birth before 100 years; here i want to show a alert message like "Please select a date of birth in between 100 years... thankyou"
here i include my programs,
in my module.py
from datetime import date,datetime
from time import strptime
from dateutil import parser
from openerp.osv import osv, fields
class jebatraining(osv.osv):
_name = "age_calculator"
_description = "Age Calculator"
def onchange_getage(self,cr,uid,ids,dob,context=None):
current_date=datetime.now()
current_year=current_date.year
birth_date=parser.parse(dob)
if (current_year>=birth_date.year):
current_age=current_year-birth_date.year
else:
current_age=0
return {'value':{'age': current_age}}
_columns = {
'dob':fields.date('Date of Birth', required=True),
'age':fields.integer('Age', size=3),
}
jebatraining()
in my module_view.xml
<record id="age_calculator_form" model="ir.ui.view">
<field name="name">jebatraining.form_view</field>
<field name="model">age_calculator</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="age calculator">
<field name="dob" on_change = "onchange_getage(dob)" string="Date of Birth"/>
<field name="age" string="Age"/>
</form>
</field>
</record>
anyone help me. thanks friends................
Your onchange function should be something like this:
def onchange_getage(self,cr,uid,ids,dob,context=None):
current_date=datetime.now()
current_year=current_date.year
if current_year > dob.year + 100:
raise osv.except_osv(_('Invalid Action!'), _('This date of birth is too old!'))
birth_date=parser.parse(dob)
if (current_year>=birth_date.year):
current_age=current_year-birth_date.year
else:
current_age=0
return {'value':{'age': current_age}}
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.
RegisterOdoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.
Test it nowQuestion tools
Stats
Asked: 4/4/14, 8:42 AM |
Seen: 2426 times |
Last updated: 3/16/15, 8:10 AM |