问题
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