如果输入的月份大于当前月份,我想提出错误

时间:2017-05-15 05:03:50

标签: python python-2.7

def generate_leave(self, cr, uid,ids, fields, context=None):
        if context is None:
            context = {}
        month_split = self.browse( cr, uid,ids)
        print "\n\n\n\n\n\n DATEE",month_split.name 
        dt =  datetime.strptime(month_split.name, "%Y-%m-%d")
        year = dt.year
        print "\n\n\n\n YER",year
        month = dt.month
        print "\n\n\n MNTH",month
        hrme=self.pool.get('acm.lev')
        fds = hrme.search(cr,uid,[('no_of_months' ,'=', dt.month),('no_of_year' ,'=', dt.year)])
        print "\n\n\n\n\n TEST FDS",fds
        if month == (dt.month + 1) % 12 or 12 :
            raise osv.except_osv(_("Warning!"),_("Please choose months properly."))

工作正常。
但是如果我选择2月也会显示相同的加注错误,在我的情况下,只有当输入的月份大于当前月份时,我才想要出现错误。
如果它小于当前月份,则加注错误不应该抛出。

1 个答案:

答案 0 :(得分:0)

我已经解决了。 首先,我们要获取“当前月”,然后我们想要给出“当前月”,如:

if month > datetime.now().month : 
 raise osv.except_osv(_("Warning!"),_("Please choose months properly."))

-