Skip to Content
Menu
This question has been flagged
1 Reply
2343 Views

Hey, so we are trying to implement a andon system in our kanban view depending on a date field.

If the date is within 90 days we need it to be one color,

If the date is within 60 days we need it to be a different color,

if the date is within 30 days we need it to be a different color.


Ive created a cron in the model that runs with no errors however it isnt actually updating any values.

Is there somthing im missing here, thanks!


    @api.model

    def cron_andon_color_set(self):


        today = fields.Date.today()

        contracts = self.env['account.analytic.account'].search([('x_contact', '!=', False),('date_end','!=',False)])

        for record in contracts:


            if record['date_end'] != False:

                end_date = fields.Date.from_string(str(record['date_end']))

                if today-timedelta(days=90) <= end_date <= today:

                    record['x_color'] = 1

                elif today-timedelta(days=60) <= end_date <= today:

                    record['x_color'] = 2

                elif today-timedelta(days=30) <= end_date <= today:

                    record['x_color'] = 3

                else:

                    #Kinda broke if we get to here

                    record['x_color'] = False

Avatar
Discard
Author Best Answer

Solution:

    @api.model
    def cron_andon_color_set(self):
        contracts = self.env['account.analytic.account'].search([('x_contact', '!=', False),('date_end','!=',False)])

        for record in contracts:
            current_date = fields.Date.today()
            end_date = fields.Date.from_string(record['date_end'])
            difference = int((current_date - end_date).days)

            if difference >= 0:
                #We have passed this date
                record['x_color'] = 1
            else:
                #In the future
                flipped_difference = difference * -1
                if flipped_difference > 90:
                	#More than 90 days
                	#Blue
                    record['x_color'] = 4
                elif flipped_difference <= 90 and flipped_difference > 60:
                    #Between 90 and 60
                    #Green
                    record['x_color'] = 8
                elif flipped_difference <= 60 and flipped_difference > 30:
                    #Between 60 and 30
                    #Orange
                    record['x_color'] = 2
                else:
                   	#Less than 30
                    #Red
                    record['x_color'] = 1
Avatar
Discard
Related Posts Replies Views Activity
1
Oct 23
828
1
Oct 21
3740
1
Nov 24
479
0
Mar 24
556
0
Jan 24
77