Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
1 Ответить
3291 Представления

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

Аватар
Отменить
Автор Лучший ответ

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
Аватар
Отменить
Related Posts Ответы Просмотры Активность
1
окт. 23
2078
1
окт. 21
5356
1
нояб. 24
4226
0
мар. 24
1854
0
янв. 24
77