Odoo Help


Automated Action Birthday =19

Mostafa Mohamed Abdel Monaem
on 2/10/15, 3:38 PM 1,236 views

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 name="interval_number">1</field>

<field name="interval_type">days</field>

<field name="numbercall">-1</field>

<field eval="'fci.student'" name="model"/>

<field eval="'get_age_comp'" name="function"/>

<field eval="'()'" name="args"/>



Thanks :D

Hope you read the comments on leap year... I added them at the last minute.

Stephen Mack
on 2/10/15, 5:32 PM

Thank you :) i like your logic solutions and i thought about them i hope to get some help with the code that i could insert data in 2 tables from one place :D

Mostafa Mohamed Abdel Monaem
on 2/10/15, 7:39 PM

or how can i change table record from status to another by ORM ?

Mostafa Mohamed Abdel Monaem
on 2/10/15, 7:57 PM

Stephen Mack

--Stephen Mack--

| 8 8 9
Santiago, Chile
--Stephen Mack--

Some people call me a karma whore, I only ask for 10 points if you like my answer and 15 if I happen to get it correct.

Stephen Mack
On 2/10/15, 5:21 PM

Well I can't give you python code but I can give you some logic ideas.

  1. 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.
  2. Create a search for Males born on 10 Feb 1996 (Warning: a simple date search will ignore leap year babies, see below).
  3. 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 2/10/15, 3:38 PM
Seen: 1236 times
Last updated: 3/16/15, 8:10 AM