Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
4496 Zobrazení

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 :)

[CODE]
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'
 

[/CODE]

[CODE]
<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"/>

</record>

[/CODE]

Thanks :D

Avatar
Zrušit

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

Autor

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

Autor

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

Nejlepší odpověď

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.

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
2
zář 16
6829
0
bře 15
4081
1
bře 15
4430
2
čvc 25
2362
2
lis 24
3043