2017-05-09 84 views
1

我该如何排除国家法定节假日? 我用下面的代码,以排除周日我该如何添加n天到排除国定假日的日期odoo

@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

回答

0

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

holiday_dates = set([dt.date() for dt in Holidays]) 
# And a few lines later in your exclusion check 
# while ... 
    if weekday >= 6 or current_date.date() in holiday_dates: 
     continue 
+0

,每年我应该改变的假期? – Borealis

+0

如果有假期改变日期,或假期被添加/删除 - 那么是的。否则,您可以修改代码来仅比较月份和日期部分。 – dgeorgiev