=== modified file 'account/account.py' --- account/account.py 2010-03-23 07:24:07 +0000 +++ account/account.py 2010-03-30 13:00:05 +0000 @@ -570,13 +571,29 @@ _order = "date_start" def _check_duration(self,cr,uid,ids): - obj_fy=self.browse(cr,uid,ids[0]) + obj_fy = self.browse(cr,uid,ids[0]) if obj_fy.date_stop < obj_fy.date_start: return False return True + def _check_fiscal_year(self, cr, uid, ids, context={}): + obj_fiscal_ids = self.search(cr, uid, [], context=context) + obj_fiscal_ids.remove(ids[0]) + data_fiscal_yr = self.browse(cr, uid, obj_fiscal_ids, context=context) + current_fiscal_yr = self.browse(cr, uid, ids, context=context)[0] + for dates in data_fiscal_yr: + # Condition to check if the current fiscal year falls in between any previously defined fiscal year + if dates.date_start <= current_fiscal_yr['date_start'] <= dates.date_stop or dates.date_start <= current_fiscal_yr['date_stop'] <= dates.date_stop: + return False + # Condition to check whether there exist any previously defined fiscal year falling in between the newly created fiscal year + elif current_fiscal_yr['date_start'] <= dates.date_start <= current_fiscal_yr['date_stop'] or current_fiscal_yr['date_start']<= dates.date_start <= current_fiscal_yr['date_stop']: + return False + return True + _constraints = [ - (_check_duration, 'Error ! The duration of the Fiscal Year is invalid. ', ['date_stop']) + (_check_duration, 'Error ! The duration of the Fiscal Year is invalid. ', ['date_stop']), + (_check_fiscal_year, 'Error ! This Fiscal Year overlaps an existing Fiscal Year',['date_start','date_stop']) + ] def create_period3(self,cr, uid, ids, context={}):