如何添加n天到不包括国庆节日期的日期

时间:2017-05-09 12:16:22

标签: openerp

如何排除国定假日? 我使用下面的代码排除星期日



    @api.depends('date_request', 'Nbr_days')
    def _compute_date_result(self):
 
        for record in self:
            business_days_to_add = record.Nbr_days
            current_date = fields.Datetime.from_string(record.date_request)
            while business_days_to_add > 0:
                current_date += timedelta(days=1)
                weekday = current_date.weekday()
                if weekday >= 6: 
                    continue
                business_days_to_add -= 1
            record.date_perform=current_date




1 个答案:

答案 0 :(得分:0)

由于假期通常跨越整个日期,您可以执行以下操作:

iteration 0, current nodes = dhn_0_vertices_pgr
iteration 0, current edges = dhn_0
iteration 0, time = 0
iteration 0, self.current = {'edges': 'dhn_0', 'nodes': 'dhn_0_vertices_pgr'}
iteration 0, self.version = {0: ('dhn_0', 'dhn_0_vertices_pgr')}

iteration 1, current nodes = dhn_1_vertices_pgr
iteration 1, current edges = dhn_1
iteration 1, time = 1
iteration 1, self.current = {'edges': 'dhn_1', 'nodes': 'dhn_1_vertices_pgr'}
iteration 1, self.version = {0: ('dhn_0', 'dhn_0_vertices_pgr'), 1: ('dhn_1', 'dhn_1_vertices_pgr')}

iteration 2, current nodes = dhn_2_vertices_pgr
iteration 2, current edges = dhn_2
iteration 2, time = 2
iteration 2, self.current = {'edges': 'dhn_2', 'nodes': 'dhn_2_vertices_pgr'}
iteration 2, self.version = {0: ('dhn_0', 'dhn_0_vertices_pgr'), 1: ('dhn_1', 'dhn_1_vertices_pgr'), 2: ('dhn_2', 'dhn_2_vertices_pgr')}

iteration 3, current nodes = dhn_3_vertices_pgr
iteration 3, current edges = dhn_3
iteration 3, time = 3
iteration 3, self.current = {'edges': 'dhn_3', 'nodes': 'dhn_3_vertices_pgr'}
iteration 3, self.version = {0: ('dhn_0', 'dhn_0_vertices_pgr'), 1: ('dhn_1', 'dhn_1_vertices_pgr'), 2: ('dhn_2', 'dhn_2_vertices_pgr'), 3: ('dhn_3', 'dhn_3_vertices_pgr')}