Odoo Help

2

0
3 Answers
4
Avatar

Niyas Raphy India

--Niyas Raphy--
27056
| 7 7 11
Wayanad, Kerala, India
--Niyas Raphy--

Odoo Techno Functionalist

Feel free to connect :  niyasraphyk@gmail.com

Twitter:https://twitter.com/niyasraphy
LinkedIn: https://www.linkedin.com/in/niyasraphy/
FB:https://www.facebook.com/niyasraphy123
Whatsapp : +917736136763
Happy to help :)

Niyas Raphy India
11/23/17, 1:34 AM

Hi,

To add months with todays date, you can do it like this

from datetime import datetime
from dateutil.relativedelta import relativedelta

six_months_after  = datetime.now() + relativedelta(months=6)

or in your code change the line ,

Date = datetime.datetime.now()

into

Date = datetime.now()

For writing the values into field, you have to do like this

self.end_month = six_months_after

thanks

3 Comments
Manish Kumar Bohra India
11/23/17, 2:01 AM

Hello, I am implement changes and it's value print but it's value is not reflected to my field. and changes code below :

start_month = fields.Date("start")

end_month =fields.Date("end", compute='_calculate_month')

@api.depends('start_month')

@api.multi

def _calculate_month(self):

if self.start_month:

Date_Start = datetime.now()

print"Start Date", Date_Start

six_months_after = Date_Start + relativedelta(months=6)

print"After six month", six_months_after

end_month = six_months_after

print "end month:", end_month

so anything wrong in above code?

Niyas Raphy India
11/23/17, 2:46 AM

Answer updated, please check it

Manish Kumar Bohra India
11/23/17, 2:52 AM

Thanks @Niyas, it's work for me. But one more query how can i change datenow field with custom date field because it show error when i use default date instead of datenow field. Also i use duration in month(6, 12, 24,36).

Thanks for your reply

0
Avatar

Manish Kumar Bohra India

--Manish Kumar Bohra--
11863
| 6 5 10
Bikaner, India
--Manish Kumar Bohra--


Manish Kumar Bohra India
11/23/17, 2:00 AM

Hello, I am implement changes and it's value print but it's value is not reflected to my field. and changes code below :

start_month = fields.Date("start")

end_month =fields.Date("end", compute='_calculate_month')

@api.depends('start_month', '')

@api.multi

def _calculate_month(self):

if self.start_month:

Date_Start = datetime.now()

print"Start Date", Date_Start

six_months_after = Date_Start + relativedelta(months=6)

print"After six month", six_months_after

end_month = six_months_after

print "end month:", end_month

so anything wrong in above code?

1 Comment
Niyas Raphy India
11/23/17, 2:46 AM

Do like this,

self.end_month = six_months_after.

Updated the answer

Ask a Question
Keep Informed
1 follower(s)
About This Community

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

Register
Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now