Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How Utility method removes leave intervals from a base interval in openerp

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 250
    Comment on it

    In openerp It will first clean the leave intervals, to have an ordered list of not-overlapping intervals and initiate the current interval to be the base interval then before finishing skip the current interval and go to next beginning after the current interval: skip and get out of the loop because we are outside range. Use this code in your own module in .py file,

    def remove_leaves(self, cr, uid, interval, leave_intervals, context=None):         
            if not interval:
                return interval
            if leave_intervals is None:
                leave_intervals = []
            intervals = []
            leave_intervals = self.interval_clean(leave_intervals)
            current_interval = [interval[0], interval[1]]
            for leave in leave_intervals:
                if leave[1] <= current_interval[0]:
                    continue
                if leave[0] >= current_interval[1]:
                    break
                if current_interval[0] < leave[0] < current_interval[1]:
                    current_interval[1] = leave[0]
                    intervals.append((current_interval[0], current_interval[1]))
                    current_interval = [leave[1], interval[1]]
                # if current_interval[0] <= leave[1] <= current_interval[1]:
                if current_interval[0] <= leave[1]:
                    current_interval[0] = leave[1]
            if current_interval and current_interval[0] < interval[1]:  
                intervals.append((current_interval[0], current_interval[1]))
            return intervals
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: