I have a date field in form that allows the users to enter a date which presumably the deadline of a task and I want to have difference between today with deadline and concern of: 1.if the date has passed, then show 'overdue' 2.if not, then show the number of days left the given date and add text that say 'the left day are {%results of difference days%}' which field type can aggregate integer with text
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))
Odoo Tips: http://learnopenerp.blogspot.com/