Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
5 Odpowiedzi
544 Widoki

Hi everybody !!!!

Please i have twi fields date and i want to compare them. How can i doo it please help please

Awatar
Odrzuć

Thanks a lot for your help :) But what i want to compare is the two fields in hr.contract which are date how can i convert them to datetime if i am going to use them ??

Hi, In my answer both start and end are date fields....

Najlepsza odpowiedź

Hi,

You can compare date by:- (  here lets assume that i assigned dates field to "start_date" and "end_date")

            start = datetime.strptime(start_date, DEFAULT_SERVER_DATE_FORMAT)
            end = datetime.strptime(end_date, DEFAULT_SERVER_DATE_FORMAT)
            delta = end - start
            num_of_days= delta.days


Then you can use delta.days to get number of days


Please don't forget to import following:-

import time

from dateutil.relativedelta import relativedelta

from datetime import datetime

from openerp.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT


Hope this helps...

Awatar
Odrzuć
Autor Najlepsza odpowiedź

Thanks guys for your answers but both of them don't work.

what is object.birthdate because it shows me an error AttributeError: type object 'object' has no attribute 'birthdate'

Please help guys

Awatar
Odrzuć

Hi Abdelwahed, can you check now? I updated the Answer. Hope it helps.. let me know if any probs..

Najlepsza odpowiedź

Try like below code , im not sure ..it may helps..

also add this in xml file 

class hr_contract(osv.Model):

         _inherit='hr.contract'


    _columns={

                   'date1':fields.date('Date'),

                    'date2':fields.date('Date2')

                    'days':fields.function(_get_days, string="Sub Model", type='char', store=True)

                      }


def _get_days(self, cr, uid, ids, field_name, arg, context=None):*

res = {}

for val in self.browse(cr, uid, ids, context):

start_day= datetime.strptime(val.date1 ,DEFAULT_SERVER_DATE_FORMAT)

end_day=datetime.strptime(time.strftime(DEFAULT_SERVER_DATE_FORMAT), DEFAULT_SERVER_DATE_FORMAT)

delta = (end - start ).days

return delta

 

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
4
paź 16
31722
1
wrz 15
4364
1
cze 15
1257
0
kwi 15
973
2
kwi 15
1270