Odoo Help

Welcome!

This community 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.

1

How to Date deduction with Python ?

By
priyankahdp
on 5/5/13, 12:38 PM 6,100 views

here shows date of birth field in my openerp model

'date_of_birth': fields.date('Date of Birth'),

need to change its default date to 25years earlier.because its easier to user to pick year. ( in openerp jquery default load current 20years in list and user have to get some time to select earlier year ).

for ex :

_defaults = {
'date_of_birth':fields.date.context_today - 25years

please advice me to implement this issue (if its with python function seems good for my requirement)

---------------EDITED---------------

@ Dear Patently,

I tried it with my console.its gives a error

>>> import datetime
>>> from datetime import timedelta
>>> diff = datetime.datetime.now() - datetime.timedelta(years=42)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'years' is an invalid keyword argument for this function

I tried it with openerp in eclipse

def _dob(self, cr, uid, context=None):
    diff = datetime.datetime.now() - datetime.timedelta(years=42)
    return diff

also gives error

  File "/home/bellvantage/Documents/openerp-7.0/openerp-7/openerp/addons/bpl/bpl.py", line 47, in _dob
    diff = datetime.datetime.now() - datetime.timedelta(years=42)
TypeError: 'years' is an invalid keyword argument for this function
4

AJ Schrafel Paper Corp

--AJ Schrafel Paper Corp--
2050
| 4 5 8
Bronx, United States
--AJ Schrafel Paper Corp--

Exploring OpenERP for business

AJ Schrafel Paper Corp
On 5/5/13, 7:22 PM

try this:

import datetime
from datetime import timedelta

diff = datetime.datetime.now() - datetime.timedelta(years=42)

ur answer very helped me to my code

priyankahdp
on 5/6/13, 2:20 AM
0

priyankahdp

--priyankahdp--
1089
| 5 5 6
Colombo, Sri Lanka
--priyankahdp--
Java Developer ORACLE Python J2EE Spring Hibernate Struts & Jquery............. :-)
priyankahdp
On 5/6/13, 2:19 AM

now its works with this code

def _dob(self, cr, uid, context=None):
    today = datetime.date.today()
    past = today + relativedelta.relativedelta(years= -25)
    return past.strftime('%Y-%m-%d')

thanks all answers

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 5/5/13, 12:38 PM
Seen: 6100 times
Last updated: 3/16/15, 8:10 AM