Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
1 Antworten
3348 Ansichten

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
Verwerfen
Autor Beste Antwort

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
Verwerfen
Verknüpfte Beiträge Antworten Ansichten Aktivität
1
Okt. 23
2150
1
Okt. 21
5439
1
Nov. 24
4485
0
März 24
1933
0
Jan. 24
77