Hello
i am very new to odoo and i am using the odoo 10 framework. i am presently trying to add number of days to current date in order to get expiry date. Below is my code.
class Payment(models.Model):
_inherit = 'account.voucher'
number_days = fields.Integer(string="Days")
effective_date = fields.Date(string="Effective Date")
expiry_date = fields.Date(string="Expiry Date")
@api.one
@api.onchange("effective_date", "number_days")
def _onchange_expiry_date(self):
strftime = "%Y-%m-%d"
number_days = datetime.timedelta()
effective_date = datetime.date(self.effective_date,strftime)
expiry_date = datetime.date(self.expiry_date,strftime)
self.expiry_date = self.effective_date + timedelta(days=self.number_days)
I keep getting this error
Traceback (most recent call last): File "C:\Program Files (x86)\Odoo 10.0\server\odoo\http.py", line 641, in _handle_exception File "C:\Program Files (x86)\Odoo 10.0\server\odoo\http.py", line 683, in dispatch File "C:\Program Files (x86)\Odoo 10.0\server\odoo\http.py", line 333, in _call_function File "C:\Program Files (x86)\Odoo 10.0\server\odoo\service\model.py", line 101, in wrapper File "C:\Program Files (x86)\Odoo 10.0\server\odoo\http.py", line 326, in checked_call File "C:\Program Files (x86)\Odoo 10.0\server\odoo\http.py", line 941, in __call__ File "C:\Program Files (x86)\Odoo 10.0\server\odoo\http.py", line 506, in response_wrap File "C:\Program Files (x86)\Odoo 10.0\server\odoo\addons\web\controllers\main.py", line 890, in call_kw File "C:\Program Files (x86)\Odoo 10.0\server\odoo\addons\web\controllers\main.py", line 882, in _call_kw File "C:\Program Files (x86)\Odoo 10.0\server\odoo\api.py", line 689, in call_kw File "C:\Program Files (x86)\Odoo 10.0\server\odoo\api.py", line 680, in call_kw_multi File "C:\Program Files (x86)\Odoo 10.0\server\odoo\models.py", line 5510, in onchange File "C:\Program Files (x86)\Odoo 10.0\server\odoo\models.py", line 5408, in _onchange_eval File "<decorator-gen-267>", line 2, in _onchange_expiry_date File "C:\Program Files (x86)\Odoo 10.0\server\odoo\api.py", line 369, in loop File "C:\Program Files (x86)\Odoo 10.0\server\odoo\addons\subscription\models\subscription.py", line 61, in _onchange_expiry_date TypeError: an integer is required
Playing with dates in python:
1- http://learnopenerp.blogspot.com/2018/02/python-timedelta.html
2- http://learnopenerp.blogspot.com/2018/02/python-strftime-datetime-formatting.html
3- http://learnopenerp.blogspot.com/2018/01/python-date-manipulation.html