不支持的操作数类型

不支持的操作数类型

本文介绍了Odoo 12无法启动自定义模块-TypeError:-不支持的操作数类型-:“ tuple”和“ datetime.timedelta”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于odoo来说,iam的新尝试是,我想减去datetime.timedelta(days = 90),它距离license_renewal_date =(2021,6,6)90天,但我尝试时我会在错误下面得到这个错误

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)

错误:

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

在Odoo py文件中:

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)

更新:
i仍然有更新遇到相同的错误,有人帮助他

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)


推荐答案

您不能仅使用元组(2021,6,6)

 license_renewal_date = (2021,6,6)

为此您必须使用对象 datetime

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

这都是您的问题

现在它可以正常工作了:

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)

这篇关于Odoo 12无法启动自定义模块-TypeError:-不支持的操作数类型-:“ tuple”和“ datetime.timedelta”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 14:25