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 have a table called students and i need to check male students ages every day to know if they are more than 19 or not .i know i should run cron function to check the birth dates every day but i need to get the values in the birth dates column , do some operations to get the age more than 19 or not , add the students that have age more than 19 to another table.
here is what i did :D help me with what within the comments please :)
def get_age_comp(self, cr, uid, birth_date,gender , context=None):
# birth_date and gender are names of columns in fci.students table like :
#'birth_date': fields.date(string='Birth Date', required=True)
#'gender': fields.selection([('m', 'Male'), ('f', 'Female')], string='Gender', required=True)
student_obj = self.pool.get('fci.student')
current_date = datetime.now()
current_year = current_date.year
birth_dates = parser.parse(birth_date)
current_age = current_year - birth_dates.year
gender = student_obj.search(cr, uid, [('gender', '=', True), ('gender', 'like', 'm')])
if current_age > 19 & gender=='m':
#i don't know if i do it right and i need to insert these students (name ,age ) to table called 'stat'
<record id="ir_cron_actions" model="ir.cron">
<field name="name">Check age Job</field>
<field eval="True" name="active"/>
<field name="user_id" ref="base.user_root"/>
<field eval="'fci.student'" name="model"/>
<field eval="'get_age_comp'" name="function"/>
<field eval="'()'" name="args"/>
Well I can't give you python code but I can give you some logic ideas.
- Calculate the date that a student turns 19 based on todays date.
- Today is 10 Feb 2015
- People born 10 Feb 1996 turn 19 today.
- Create a search for Males born on 10 Feb 1996 (Warning: a simple date search will ignore leap year babies, see below).
- If you really must copy them to another table then perform that action.
- Personally I think it's smarter to have a status field in your student table that you have set to: underage, mail_card, card_mailed, delayed.
- Then your cron job could search for Males with a status of underage, born on or before 10 Feb 1996 (I like on or before because it handles leap year babies. It also handles the system being down and having to catch up with missed processing days). It could then set the status to mail_card. Then your other job to mail the card would set the status to card_mailed and when they register their status would be set to delayed.
- Of course you should probably have a status_date field so you know the date the status was changed.
Just my ideas...
Oh and you may want one other quality assurance cron job that searches for any records that are not one of the four statuses and sends a report to the person in charge. Just incase some bad data creeps into the system.
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/10/15, 3:38 PM|
|Seen: 1066 times|
|Last updated: 3/16/15, 8:10 AM|