This question has been flagged

Hello Everyone, 

I have to try to change string colour near the expiry date.

And expiry show approximate one month before ending date

My code below :

@api.depends('ren9','ren13')
def _compute_default_status(self):
value = {}
for rec in self:
if rec.ren9:
print "REC:::::::::::", rec.ren15, rec.ren14
end_date = datetime.strptime(rec.ren15, '%Y-%m-%d')
expr = end_date - relativedelta(months=1)
r = relativedelta(end_date, expr)
print "DATE:::::::::::::::::::,", r, expr, rec.id

if r < 1 :
print "noof", rec.id, expr
if rec.ren17:
rec.ren13 = 'near_close'
value.update(ren13=rec.ren13)
print "NEAR CLOSE::::::::::", rec.ren13
else:
rec.ren13 = 'occupied'
value.update(ren13=rec.ren13)
print "OCCUPIED::::::::::", rec.ren13
else:
rec.ren13 = 'available'
value.update(ren13=rec.ren13)

and Where 

ren9 = fields.Many2one('res.partner', string='Customer')
ren13 = fields.Selection([('available', 'Available'),
                          ('occupied', 'Occupied'),
                         ('expiry_near','Expiry')], string="Status",
                            dafault='available'
, compute='_compute_default_status', store=True)
ren14 = fields.Date('Start Date')
ren15 = fields.Date('End date')
ren16 = fields.Float('Rental Price')
ren17 = fields.Date('Expiry', compute='_calculate_month_expiry')



<tree string="Ren Ser" colors="darkred:ren13 == 'occupied'; darkgreen:ren13 == 'available'; blue:ren13 =='near_close'"/>

Thanks in Advanced  


Avatar
Discard
Author Best Answer

Hello Every one my issue is fixed and solution below :

@api.depends('ren9','ren13')
def _compute_default_status(self):
value = {}
for rec in self:
if rec.ren9:
print "REC:::::::::::", rec.ren15, rec.ren14
current_date = datetime.now()
end_date = datetime.strptime(rec.ren15, '%Y-%m-%d')
expr = end_date - relativedelta(months=1)
#r = relativedelta(end_date, expr)
r = (expr - current_date).days
print "DATE:::::::::::::::::::,", r, rec.id
print "noof", rec.id,
if rec.ren15 :
if r < 1 :
rec.ren13 = 'near_close'
value.update(ren13=rec.ren13)
print "NEAR CLOSE::::::::::", rec.ren13
else:
rec.ren13 = 'occupied'
value.update(ren13=rec.ren13)
print "OCCUPIED::::::::::", rec.ren13
else:
rec.ren13 = 'available'
value.update(ren13=rec.ren13)

Thank you 

Avatar
Discard