Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
5 Răspunsuri
550 Vizualizări

Hi everybody !!!!

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

Imagine profil
Abandonează

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

Cel mai bun răspuns

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

Imagine profil
Abandonează
Autor Cel mai bun răspuns

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

Imagine profil
Abandonează

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

Cel mai bun răspuns

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

 

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
4
oct. 16
31726
1
sept. 15
4367
1
iun. 15
1260
0
apr. 15
973
2
apr. 15
1272