From 87f8860982096f9030ba261c8c7175c02887a61e Mon Sep 17 00:00:00 2001 From: Ravi Gohil Date: Fri, 22 Apr 2016 16:09:05 +0530 Subject: [PATCH] [MIG] stock_calendar: migrate resource.py file + cleaning 90 percents of the file had to be migrated because of the methods interval_remove_leaves and get_leave_intervals that were migrated in the module resource --- addons/stock_calendar/models/resource.py | 23 +++++++++++------------ addons/stock_calendar/models/stock.py | 10 +++++----- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/addons/stock_calendar/models/resource.py b/addons/stock_calendar/models/resource.py index e0e2c22dc07..0ddec1b0cd5 100644 --- a/addons/stock_calendar/models/resource.py +++ b/addons/stock_calendar/models/resource.py @@ -1,10 +1,8 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -import datetime from odoo import api, fields, models -from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT, DEFAULT_SERVER_DATE_FORMAT class ResourceCalendarAttendance(models.Model): @@ -16,16 +14,16 @@ class ResourceCalendarAttendance(models.Model): class ResourceCalendarLeaves(models.Model): _inherit = "resource.calendar.leaves" - group_id = fields.Many2one('procurement.group', 'Procurement Group') + group_id = fields.Many2one('procurement.group', string="Procurement Group") class ResourceCalendar(models.Model): _inherit = "resource.calendar" # Keep as it takes into account times - def get_leave_intervals(self, cr, uid, id, resource_id=None, - start_datetime=None, end_datetime=None, - context=None): + @api.multi + def get_leave_intervals(self, resource_id=None, + start_datetime=None, end_datetime=None): """Get the leaves of the calendar. Leaves can be filtered on the resource, the start datetime or the end datetime. @@ -43,15 +41,15 @@ class ResourceCalendar(models.Model): """ # TDE FIXME: waw, overriding completely a method + changing its result # and its behavior, very nice. Please FIXME. - resource_calendar = self.browse(cr, uid, id, context=context) + self.ensure_one() leaves = [] - for leave in resource_calendar.leave_ids: + for leave in self.leave_ids: if leave.resource_id and not resource_id == leave.resource_id.id: continue - date_from = datetime.datetime.strptime(leave.date_from, DEFAULT_SERVER_DATETIME_FORMAT) + date_from = fields.Datetime.from_string(leave.date_from) if end_datetime and date_from > end_datetime: continue - date_to = datetime.datetime.strptime(leave.date_to, DEFAULT_SERVER_DATETIME_FORMAT) + date_to = fields.Datetime.from_string(leave.date_to) if start_datetime and date_to < start_datetime: continue leaves.append((date_from, date_to, leave.group_id.id)) @@ -61,7 +59,8 @@ class ResourceCalendar(models.Model): # Utility methods # -------------------------------------------------- - def interval_remove_leaves(self, cr, uid, interval, leave_intervals, context=None): + @api.model + def interval_remove_leaves(self, interval, leave_intervals): """ Utility method that remove leave intervals from a base interval: - clean the leave intervals, to have an ordered list of not-overlapping @@ -101,7 +100,7 @@ class ResourceCalendar(models.Model): att_obj = self.pool.get("resource.calendar.attendance") if leave[2]: if len(current_interval) > 2: - current_group = current_interval[2] and att_obj.browse(cr, uid, current_interval[2], context=context).group_id.id or False + current_group = current_interval[2] and att_obj.browse(current_interval[2]).group_id.id or False if leave[2] != current_group: continue if leave[1] <= current_interval[0]: diff --git a/addons/stock_calendar/models/stock.py b/addons/stock_calendar/models/stock.py index 660bd42bc05..01768f43d0d 100644 --- a/addons/stock_calendar/models/stock.py +++ b/addons/stock_calendar/models/stock.py @@ -68,7 +68,7 @@ class StockWarehouseOrderpoint(models.Model): purchase_date = False delivery_date = start_date if self.calendar_id and self.calendar_id.attendance_ids: - res = self.calendar_id._schedule_days(-1, start_date, compute_leaves=True)[0] # CLEANME + res = self.calendar_id._schedule_days(-1, start_date, compute_leaves=True) if res and res[0][0] < start_date: group_to_find = res[0][2] and Attendance.browse(res[0][2]).group_id.id delivery_date = res[0][0] @@ -76,7 +76,7 @@ class StockWarehouseOrderpoint(models.Model): if self.purchase_calendar_id and self.purchase_calendar_id.attendance_ids: while not purchase_date: found_date = found_date + relativedelta(days=-1) # won't allow to deliver within the day - res = self.purchase_calendar_id._schedule_days(-1, found_date, compute_leaves=True)[0] # CLEANME + res = self.purchase_calendar_id._schedule_days(-1, found_date, compute_leaves=True) for re in res: group = re[2] and Attendance.browse(re[2]).group_id.id found_date = re[0] @@ -94,7 +94,7 @@ class StockWarehouseOrderpoint(models.Model): now_date = datetime.utcnow() # Search first calendar day (without group) - res = self.calendar_id._schedule_days(1, new_date, compute_leaves=True)[0] # CLEANME + res = self.calendar_id._schedule_days(1, new_date, compute_leaves=True) att_group = res and res[0][2] and Attendance.browse(res[0][2]).group_id.id # If hours are smaller than the current date, search a day further if res and res[0][0] < now_date: @@ -112,7 +112,7 @@ class StockWarehouseOrderpoint(models.Model): while res and group and att_group != group and number < 100: number += 1 new_date = res[0][1] + relativedelta(days=1) - res = self.calendar_id._schedule_days(1, new_date, compute_leaves=True)[0] + res = self.calendar_id._schedule_days(1, new_date, compute_leaves=True) att_group = False for re in res: if re[2]: @@ -128,7 +128,7 @@ class StockWarehouseOrderpoint(models.Model): if res: date1 = res[0][1] new_date = res[0][1] + relativedelta(days=1) - res = self.calendar_id._schedule_days(1, new_date, compute_leaves=True)[0] + res = self.calendar_id._schedule_days(1, new_date, compute_leaves=True) if res: return (date1, res[0][1]) return (False, False)