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.

0

AttributeError: 'module' object has no attribute 'strptime' in Odoo v8

By
Drees Far
on 7/11/15, 1:15 PM 2,502 views

Hi friends!!!

Please, i have tried this function to get the last date of an invoice of a partner:


def get_last_invoice_period(self, cr, uid, ids, partner_id, context = None):

invoice_table = self.pool.get('account.invoice')

momo_ids = invoice_table.search(cr, uid, [('partner_id', '=',partner_id)])

vals = invoice_table.read(cr,uid,momo_ids,['date_due','date_invoice','commercial_partner_id'],context=context)

print vals

ref_id = False

y = False

m = False

d_ref = datetime.strptime("2011-01-01","%Y-%m-%d")

for v in vals :

d_to = datetime.strptime(v['date_invoice'],"%Y-%m-%d")

if d_ref < d_to :

d_ref = d_to

ref_id = v['id']

y = d_to.year

m = d_to.month

print ref_id

print y

print m

return (str(y),str(m),ref_id)

But, i got this error: AttributeError: 'module' object has no attribute 'strptime' despite the fact that i have added :

from datetime import datetime, date, time

Please,who can help me i have tried this:

d_ref = datetime.strptime("2011-01-01","%Y-%m-%d")
print d_ref

and i have got:  2011-01-01 00:00:00

Please help and Thanks a lot.


1

Solanki Shamji

--Solanki Shamji--
1293
| 5 2 6
Baroda, India
--Solanki Shamji--

Hello!

Solanki Shamji
On 7/13/15, 3:24 AM

Hello,

Please check import statement if define before use.

from datetime import datetime

is a define before use.

May be this will help you.

Thanks for the answer but tall he import statements are defined in the first lines before every use

Drees Far
on 7/13/15, 4:41 AM

please see the answer in this post. http://stackoverflow.com/questions/12070193/why-is-datetime-strptime-not-working-in-this-simple-example

Solanki Shamji
on 7/13/15, 4:55 AM

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

1 follower(s)

Stats

Asked: 7/11/15, 1:15 PM
Seen: 2502 times
Last updated: 7/28/15, 9:45 AM