我在表单中有一个日期字段,允许用户输入一个可能是任务截止日期的日期,我希望今天与截止日期和关注点有所不同:1.如果日期已过,则显示“逾期”2 .如果不是,则显示给定日期的剩余天数并添加文本说“剩下的日子是{%results of different days%}”哪个字段类型可以将整数与文本聚合
from odoo import models, fields
from odoo import api
from datetime import datetime
class todotask(models.Model):
_name='todo.task'
_description='to manage your job tasks'
name=fields.Char('Description', required=True)
gov_deprt_id=fields.Many2many('res.partner',string='Gov
Department')
company=fields.Many2one('res.partner',
string='Work For')
start_date=fields.Date('Start Date')
deadline_date=fields.Date('Deadline')
is_done=fields.Boolean('Done?')
note=fields.Text('Note')
amount=fields.Float('Cost Amount')
remaining_days=fields.Integer(string="Remaining Days")
@api.onchange('start_date', 'deadline_date', 'remaining_days')
def calculate_date(self):
while self.start_date and self.deadline_date:
d1 = datetime.strptime(str(self.start_date), '%Y-%m-%d')
d2 = datetime.strptime(str(self.deadline_date), '%Y-%m-%d')
d3 = d2 - d1
self.remaining_days ="{} and {}".format("tttt", str(d3.days))