Odoo 12 can't start Custom Module - TypeError: unsupported operand type(s) for -: 'tuple' and 'datetime.timedelta'

拜拜、爱过 提交于 2020-06-17 13:12:06

问题


iam new to odoo what iam trying to do is , i want to minus datetime.timedelta(days = 90) that is 90 days from the license_renewal_date = (2021,6,6) how to do it , but when i try iam getting this below error

before_90_days = datetime.datetime.now().date() - datetime.timedelta(days = 90)
datetime.date(2020, 3, 11)

license_renewal_date = (2021,6,6)

exp_90_days = license_renewal_date - datetime.timedelta(days = 90)

Error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for -: 'tuple' and 'datetime.timedelta'

in Odoo py file:

license_renewal_date = fields.Date("Renewal Date",track_visibility='onchange')

def exp_date1(self):
    before_90_days = datetime.datetime.now().date()- datetime.timedelta(days = 90)
    exp_90days = self.env['(crm.lead.extended)'].search([('(license_renewal_date)','=',before_90_days)])
    template = self.env.ref('crm_extended.create_crm_lead_mail_template')
    template.send_mail(rec.id, force_send=True)   

Update : i have update still getting the same error some one help me with his

@ api.multi
def exp_date1 (self):

    testDateOnly = license_renewal_date.date;

    before_90_days = testDateOnly - datetime.timedelta (days = 90)

    # before_90_days = datetime.datetime.now (). date () - datetime.timedelta (days = 90)

    exp_90days = self.env ['(crm.lead.extended)']. search ([('(license_renewal_date)', '=', before_90_days)])

    template = self.env.ref ('crm_extended.create_crm_lead_mail_template')

    template.send_mail (self.id, force_send = True) 

回答1:


You can't create object datetime using only tuple (2021,6,6)

 license_renewal_date = (2021,6,6)

You have to use object datetime for this

 license_renewal_date = datetime.datetime(2021, 6, 6).date()

And this is all your problem.

Now it works without error:

import datetime

before_90_days = datetime.datetime.now().date() - datetime.timedelta(days=90)

print(before_90_days)

license_renewal_date = datetime.datetime(2021, 6, 6).date()

exp_90_days = license_renewal_date - datetime.timedelta(days=90)

print(exp_90_days)


来源:https://stackoverflow.com/questions/62284033/odoo-12-cant-start-custom-module-typeerror-unsupported-operand-types-for

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!