def _get_archive_groups(self, model, domain=None, fields=None,
                         groupby="create_date", order="create_date desc"):
     if not model:
         return []
     if domain is None:
         domain = []
     if fields is None:
         fields = ['name', 'create_date']
     groups = []
     for group in request.env[model].read_group(
             domain, fields=fields, groupby=groupby, orderby=order):
         label = group[groupby]
         date_begin = date_end = None
         for leaf in group["__domain"]:
             if leaf[0] == groupby:
                 if leaf[1] == ">=":
                     date_begin = leaf[2]
                 elif leaf[1] == "<":
                     date_end = leaf[2]
         groups.append({
             'date_begin': Date.to_string(Date.from_string(date_begin)),
             'date_end': Date.to_string(Date.from_string(date_end)),
             'name': label,
             'item_count': group[groupby + '_count']
         })
     return groups
Esempio n. 2
0
 def _get_archive_groups(self, model, domain=None, fields=None,
                         groupby="create_date", order="create_date desc"):
     if not model:
         return []
     if domain is None:
         domain = []
     if fields is None:
         fields = ['name', 'create_date']
     groups = []
     for group in request.env[model].sudo().read_group(
             domain, fields=fields, groupby=groupby, orderby=order):
         label = group[groupby]
         date_begin = date_end = None
         for leaf in group["__domain"]:
             if leaf[0] == groupby:
                 if leaf[1] == ">=":
                     date_begin = leaf[2]
                 elif leaf[1] == "<":
                     date_end = leaf[2]
         groups.append({
             'date_begin': Date.to_string(Date.from_string(date_begin)),
             'date_end': Date.to_string(Date.from_string(date_end)),
             'name': label,
             'item_count': group[groupby + '_count']
         })
     return groups
Esempio n. 3
0
    def events_for_day(self, day=None, limit=None):
        """List events for a given day.

        :param day string:
            Date in a string. If ``None``, we'll search for upcoming events
            from today up to specified limit.

        :param limit int:
            How many results to return.
        """
        ref = day or Date.to_string(date.today())
        domain = [
            ("date_end", ">=", ref),
        ]
        if day:
            domain.append(("date_begin", "<=", ref))
        return request.env["event.event"].search_read(
            domain=domain,
            limit=limit,
            fields=[
                "date_begin",
                "name",
                "event_type_id",
                "website_published",
                "website_url",
            ],
        )
Esempio n. 4
0
    def days_with_events(self, start, end):
        """Let visitors know when are there going to be any events.

        :param start string:
            Search events from that date.

        :param end string:
            Search events until that date.
        """
        events = request.env["event.event"].search([
            "|",
            ("date_begin", "<=", end),
            ("date_end", ">=", start),
        ])
        days = set()
        one_day = timedelta(days=1)
        start = Date.from_string(start)
        end = Date.from_string(end)
        for event in events:
            now = max(Date.from_string(event.date_begin), start)
            event_end = min(Date.from_string(event.date_end), end)
            while now <= event_end:
                days.add(now)
                now += one_day
        return [Date.to_string(day) for day in days]
Esempio n. 5
0
 def _inverse_age(self):
     self._check_release_date()
     for perizia in self.filtered('giorni_consegna'):
         d = fDate.from_string(
             perizia.inizio_operazioni) + td(days=perizia.giorni_consegna)
         # delta = fDate.from_string(perizia.inizio_operazioni) + perizia.giorni_consegna
         perizia.fine_operazioni = fDate.to_string(d)
Esempio n. 6
0
    def get_absent_on(self, date=None):
        self.ensure_one()
        if not date:
            return None

        querying_day = date
        if isinstance(date, datetime.date):
            querying_day = Date.to_string(date)

        absent_type = self.env.ref("hr_sf.absent_holidays_status")
        absent_type_id = absent_type.id

        for holiday in self.holidays_ids:
            if not holiday.date_from or not holiday.date_to:
                continue
            if holiday.holiday_status_id.id != absent_type_id:
                continue

            if not all((holiday.morning_start_work_time,
                        holiday.morning_end_work_time,
                        holiday.afternoon_start_work_time,
                        holiday.afternoon_end_work_time)):
                return None

            dt_the_day_morning_start_work_time = datetime.datetime.strptime(
                    "%s %s" % (querying_day, holiday.morning_start_work_time), DEFAULT_SERVER_DATETIME_FORMAT)
            dt_the_day_morning_end_work_time = datetime.datetime.strptime(
                    "%s %s" % (querying_day, holiday.morning_end_work_time), DEFAULT_SERVER_DATETIME_FORMAT)
            dt_the_day_afternoon_start_work_time = datetime.datetime.strptime(
                    "%s %s" % (querying_day, holiday.afternoon_start_work_time), DEFAULT_SERVER_DATETIME_FORMAT)
            dt_the_day_afternoon_end_work_time = datetime.datetime.strptime(
                    "%s %s" % (querying_day, holiday.afternoon_end_work_time), DEFAULT_SERVER_DATETIME_FORMAT)

            dt_holiday_from = Datetime.from_string(holiday.date_from) + datetime.timedelta(hours=8)
            dt_holiday_to = Datetime.from_string(holiday.date_to) + datetime.timedelta(hours=8)

            # deal with morning first
            dt_cal_start = max(dt_the_day_morning_start_work_time, dt_holiday_from)
            dt_cal_start = min(dt_cal_start, dt_the_day_morning_end_work_time)

            dt_cal_end = min(dt_the_day_morning_end_work_time, dt_holiday_to)
            dt_cal_end = max(dt_cal_end, dt_the_day_morning_start_work_time)

            if dt_cal_end > dt_cal_start:
                return absent_type.name

            # then deal with afternoon first
            dt_cal_start = max(dt_the_day_afternoon_start_work_time, dt_holiday_from)
            dt_cal_start = min(dt_cal_start, dt_the_day_afternoon_end_work_time)

            dt_cal_end = min(dt_the_day_afternoon_end_work_time, dt_holiday_to)
            dt_cal_end = max(dt_cal_end, dt_the_day_afternoon_start_work_time)

            if dt_cal_end > dt_cal_start:
                return absent_type.name
Esempio n. 7
0
    def test_02_max_date(self):
        next_year_apr = '%s-04-01' % (int(self.today[:4]) + 1)
        delay = Date.to_string(
            Date.from_string(self.today) + timedelta(days=self.seller_delay))

        """ Test if max_incoming_stock_date is the date today plus delay
        in case there is no stock of the product. """
        self.assertEqual(self.product.max_incoming_stock_date, delay)
        self.assertEqual(self.bom_product.max_incoming_stock_date, delay)

        picking_in = self.PickingObj.create({
            'partner_id': self.partner_delta_id,
            'picking_type_id': self.picking_type_in})
        self.MoveObj.create({
            'name': self.product.name,
            'product_id': self.product.id,
            'product_uom_qty': 1,
            'product_uom': self.product.uom_id.id,
            'picking_id': picking_in.id,
            'location_id': self.supplier_location,
            'location_dest_id': self.stock_location,
            'date_expected': next_year_apr,
        })

        """ Test if date_expected is the max_incoming_stock_date
        in case there are incoming products. """
        picking_in.action_confirm()
        self.product.refresh()
        self.assertEqual(self.product.max_incoming_stock_date, next_year_apr)
        self.assertEqual(
            self.bom_product.max_incoming_stock_date, next_year_apr)

        """ Test if the max_incoming_stock_date is the date today plus
        delay in case there is stock of the product. """
        picking_in.action_done()
        self.product.refresh()
        self.assertEqual(self.product.max_incoming_stock_date, delay)
        self.assertEqual(
            self.bom_product.max_incoming_stock_date, delay)
Esempio n. 8
0
    def get_absent_on(self, date=None):
        self.ensure_one()
        if not date:
            return None

        querying_day = date
        if isinstance(date, datetime.date):
            querying_day = Date.to_string(date)

        absent_type_id = self.env.ref("hr_sf.absent_holidays_status").id

        for holiday in self.holidays_ids:
            if not holiday.date_from or not holiday.date_to:
                continue
            if holiday.holiday_status_id.id != absent_type_id:
                continue

            if not all((holiday.morning_start_work_time,
                        holiday.morning_end_work_time,
                        holiday.afternoon_start_work_time,
                        holiday.afternoon_end_work_time)):
                return None

            dt_the_day_morning_start_work_time = datetime.datetime.strptime(
                "%s %s" % (querying_day, holiday.morning_start_work_time),
                DEFAULT_SERVER_DATETIME_FORMAT)
            dt_the_day_morning_end_work_time = datetime.datetime.strptime(
                "%s %s" % (querying_day, holiday.morning_end_work_time),
                DEFAULT_SERVER_DATETIME_FORMAT)
            dt_the_day_afternoon_start_work_time = datetime.datetime.strptime(
                "%s %s" % (querying_day, holiday.afternoon_start_work_time),
                DEFAULT_SERVER_DATETIME_FORMAT)
            dt_the_day_afternoon_end_work_time = datetime.datetime.strptime(
                "%s %s" % (querying_day, holiday.afternoon_end_work_time),
                DEFAULT_SERVER_DATETIME_FORMAT)

            dt_holiday_from = Datetime.from_string(
                holiday.date_from) + datetime.timedelta(hours=8)
            dt_holiday_to = Datetime.from_string(
                holiday.date_to) + datetime.timedelta(hours=8)

            # deal with morning first
            dt_cal_start = max(dt_the_day_morning_start_work_time,
                               dt_holiday_from)
            dt_cal_start = min(dt_cal_start, dt_the_day_morning_end_work_time)

            dt_cal_end = min(dt_the_day_morning_end_work_time, dt_holiday_to)
            dt_cal_end = max(dt_cal_end, dt_the_day_morning_start_work_time)

            if dt_cal_end > dt_cal_start:
                return 1

            # then deal with afternoon first
            dt_cal_start = max(dt_the_day_afternoon_start_work_time,
                               dt_holiday_from)
            dt_cal_start = min(dt_cal_start,
                               dt_the_day_afternoon_end_work_time)

            dt_cal_end = min(dt_the_day_afternoon_end_work_time, dt_holiday_to)
            dt_cal_end = max(dt_cal_end, dt_the_day_afternoon_start_work_time)

            if dt_cal_end > dt_cal_start:
                return 1
Esempio n. 9
0
    def get_holiday_on(self, date=None):
        self.ensure_one()
        if not date:
            return None

        querying_day = date
        if isinstance(date, datetime.date):
            querying_day = Date.to_string(date)

        leaves = defaultdict(lambda: list(
        ))  # [None, None, datetime.timedelta()] _time = datetime.timedelta()

        absent_type_id = self.env.ref("hr_sf.absent_holidays_status").id

        for holiday in self.holidays_ids:
            if not holiday.date_from or not holiday.date_to:
                continue
            if holiday.holiday_status_id.id == absent_type_id:
                continue

            if not all((holiday.morning_start_work_time,
                        holiday.morning_end_work_time,
                        holiday.afternoon_start_work_time,
                        holiday.afternoon_end_work_time)):
                return None

            dt_the_day_morning_start_work_time = datetime.datetime.strptime(
                "%s %s" % (querying_day, holiday.morning_start_work_time),
                DEFAULT_SERVER_DATETIME_FORMAT)
            dt_the_day_morning_end_work_time = datetime.datetime.strptime(
                "%s %s" % (querying_day, holiday.morning_end_work_time),
                DEFAULT_SERVER_DATETIME_FORMAT)
            dt_the_day_afternoon_start_work_time = datetime.datetime.strptime(
                "%s %s" % (querying_day, holiday.afternoon_start_work_time),
                DEFAULT_SERVER_DATETIME_FORMAT)
            dt_the_day_afternoon_end_work_time = datetime.datetime.strptime(
                "%s %s" % (querying_day, holiday.afternoon_end_work_time),
                DEFAULT_SERVER_DATETIME_FORMAT)

            dt_holiday_from = Datetime.from_string(
                holiday.date_from) + datetime.timedelta(hours=8)
            dt_holiday_to = Datetime.from_string(
                holiday.date_to) + datetime.timedelta(hours=8)
            # deal with morning first
            dt_cal_start = max(dt_the_day_morning_start_work_time,
                               dt_holiday_from)
            dt_cal_start = min(dt_cal_start, dt_the_day_morning_end_work_time)

            dt_cal_end = min(dt_the_day_morning_end_work_time, dt_holiday_to)
            dt_cal_end = max(dt_cal_end, dt_the_day_morning_start_work_time)

            if dt_cal_end > dt_cal_start:
                leaves[holiday.holiday_status_id.name].append(
                    (dt_cal_start, dt_cal_end, dt_cal_end - dt_cal_start))
                # leaves[holiday.holiday_status_id.name][0] = dt_cal_start
                # leaves[holiday.holiday_status_id.name][1] = dt_cal_end
                # leaves[holiday.holiday_status_id.name][2] += dt_cal_end - dt_cal_start

            # then deal with afternoon first
            dt_cal_start = max(dt_the_day_afternoon_start_work_time,
                               dt_holiday_from)
            dt_cal_start = min(dt_cal_start,
                               dt_the_day_afternoon_end_work_time)

            dt_cal_end = min(dt_the_day_afternoon_end_work_time, dt_holiday_to)
            dt_cal_end = max(dt_cal_end, dt_the_day_afternoon_start_work_time)

            if dt_cal_end > dt_cal_start:
                leaves[holiday.holiday_status_id.name].append(
                    (dt_cal_start, dt_cal_end, dt_cal_end - dt_cal_start))
                # leaves[holiday.holiday_status_id.name][0] = dt_cal_start
                # leaves[holiday.holiday_status_id.name][1] = dt_cal_end
                # leaves[holiday.holiday_status_id.name][2] += dt_cal_end - dt_cal_start

        return leaves
Esempio n. 10
0
 def _inverse_age_days(self):
     today = fDate.from_string(fDate.today())
     for person in self.filtered('birthday'):
         d = td(days=person.age_days)
         person.birthday = fDate.to_string(today - d)
Esempio n. 11
0
    def get_attendance_detail_line(self, dt_date):
        self.ensure_one()
        if not isinstance(dt_date, datetime.date):
            return None

        OfficialHoliday = self.env["hr.official_holiday"]

        dt_str = Date.to_string(dt_date)

        overtime_durations = self.get_overtime_hours_on(date_from=dt_str, date_to=dt_str)
        if dt_date.weekday() in (5, 6) and not overtime_durations:
            return None

        line = dict()
        line['name'] = self.name
        line['emp_dep'] = self.department_id.name
        line['emp_code'] = self.internal_code
        line['date'] = dt_date.strftime(DEFAULT_SERVER_DATE_FORMAT)  # + " %A" Date.to_string(dt)

        start_work_time = self.get_start_work_time_on(dt_str)
        line["start_work_time"] = start_work_time.strftime(DEFAULT_SERVER_TIME_FORMAT) \
            if start_work_time else None

        end_work_time = self.get_end_work_time_on(dt_str)
        line["end_work_time"] = end_work_time.strftime(DEFAULT_SERVER_TIME_FORMAT) \
            if end_work_time else None

        late_minutes = self.get_late_minutes_on(dt_str)
        line["late_minutes"] = round(late_minutes, 2) if late_minutes else None

        early_minutes = self.get_early_minutes_on(dt_str)
        line["early_minutes"] = round(early_minutes, 2) if early_minutes else None

        work_duration = self.get_work_duration_on(dt_str)
        line["work_duration"] = round(work_duration, 2) if work_duration else None

        # overtime_durations = self.get_overtime_hours_on(date_from=dt_str, date_to=dt_str)

        if overtime_durations:
            line["overtime_stage1"] = overtime_durations.get("stage1", None)
            line["overtime_stage2"] = overtime_durations.get("stage2", None)
            line["overtime_stage3"] = overtime_durations.get("stage3", None)

        # line["overtime_hours"] = round(overtime_hours, 2)

        leaves = self.get_holiday_on(dt_str)
        line["holiday_detail"] = leaves

        all_leaves = list()
        if leaves:
            for l in leaves.values():
                all_leaves.extend(l)
        holiday_total = round(sum(l[2].seconds / 3600.0 for l in all_leaves), 2)
        line["holiday_total"] = holiday_total

        official_holiday = OfficialHoliday.get_official_holiday_on(dt_str)
        line["official_holiday"] = official_holiday

        absent = self.get_absent_on(dt_str)

        if leaves:
            line["summary"] = string.join(
                    set(leaves.keys() + ([absent] if absent else []) + ([official_holiday] if official_holiday else [])),
                    ",")
        else:
            line["summary"] = None

        if not official_holiday and holiday_total < 8.0:
            line["forget_card"] = self.get_forget_card_on(dt_str)
        else:
            line["forget_card"] = None
        return line
Esempio n. 12
0
	publisher_city = fields.Char(
		'Publisher City',
		related='publisher_id.city')


	_sql_constraints = [
		('name_uniq',
		'UNIQUE (name)',
		'Book title must be unique.')
		]

def _inverse_age(self): today =
	fDate.from_string(fDate.today())
	for book in self.filtered('date_release'):
	d = td(days=book.age_days) - today
	book.date_release = fDate.to_string(d)

def _search_age(self, operator, value):
	today = fDate.from_string(fDate.today())
	value_days = td(days=value)
	value_date = fDate.to_string(today - value_days)
	return [('date_release', operator, value_date)]


@api.model
	def _referencable_models(self):
	models = self.env['res.request.link'].search([])
	return [(x.object, x.name) for x in models]

	ref_doc_id = fields.Reference(
	selection='_referencable_models',
Esempio n. 13
0
 def _inverse_age(self):
     today = fDate.from_string(fDate.today())
     for book in self.filtered('date_release'):
         d = td(days=book.age_days) - today
         book.date_release = fDate.to_string(d)
Esempio n. 14
0
    def get_attendance_detail(self,
                              date_from=None,
                              date_to=None,
                              filter_by_employee=None,
                              employee_ids=None):
        CAL_START_TIME = datetime.datetime.now()
        print "开始计算出勤明细表:", CAL_START_TIME
        if any((date_from, date_to)) and not all((date_from, date_to)):
            return "miss date_from or date_to"

        if not date_from and not date_to:
            now = datetime.datetime.now()
            date_from = datetime.datetime(now.year, now.month, 1)
            date_to = datetime.datetime(date_from.year, date_from.month + 1, 1)
        elif date_from and date_to:
            date_from = Date.from_string(date_from)
            date_to = Date.from_string(date_to)

        Employee = self.env["hr.employee"].sudo()

        emp_attendances_values = []

        employee_search_domain = []
        if filter_by_employee and employee_ids:
            employee_search_domain.append(("id", "in", employee_ids))
        all_employees = Employee.search(employee_search_domain)

        for emp in all_employees:
            dt = date_from
            emp_lines = list()
            while dt <= date_to:
                dt_str = Date.to_string(dt)

                overtime_hours = emp.get_overtime_hours_on(date_from=dt_str,
                                                           date_to=dt_str)
                if dt.weekday() in (5, 6) and (emp.responsibility
                                               or not overtime_hours):
                    dt += datetime.timedelta(days=1)
                    continue

                line = dict()
                line['name'] = emp.name
                line['emp_dep'] = emp.department_id.name
                line['emp_code'] = emp.internal_code
                line['date'] = dt.strftime(
                    DEFAULT_SERVER_DATE_FORMAT)  # + " %A" Date.to_string(dt)

                start_work_time = emp.get_start_work_time_on(dt_str)
                line["start_work_time"] = start_work_time.strftime(DEFAULT_SERVER_TIME_FORMAT) \
                    if start_work_time else None

                end_work_time = emp.get_end_work_time_on(dt_str)
                line["end_work_time"] = end_work_time.strftime(DEFAULT_SERVER_TIME_FORMAT) \
                    if end_work_time else None

                late_minutes = emp.get_late_minutes_on(dt_str)
                line["late_minutes"] = round(late_minutes,
                                             2) if late_minutes else None

                early_minutes = emp.get_early_minutes_on(dt_str)
                line["early_minutes"] = round(early_minutes,
                                              2) if early_minutes else None

                work_duration = emp.get_work_duration_on(dt_str)
                line["work_duration"] = round(work_duration,
                                              2) if work_duration else None

                line["overtime_hours"] = round(overtime_hours, 2)

                leaves = emp.get_holiday_on(dt_str)
                all_leaves = list()
                for l in leaves.values():
                    all_leaves.extend(l)
                line["holiday_total"] = round(
                    sum(l[2].seconds / 3600.0 for l in all_leaves), 2)

                absent_for_summary = []
                absent = emp.get_absent_on(dt_str)
                if absent:
                    absent_for_summary.append(_("absent"))
                line["summary"] = string.join(
                    set(leaves.keys() + absent_for_summary), ",")
                line["forget_card"] = emp.get_forget_card_on(dt_str)

                emp_attendances_values.append(line)
                emp_lines.append(line)
                dt += datetime.timedelta(days=1)

            if emp_lines:
                emp_total_line = dict()
                emp_total_line["name"] = None
                emp_total_line['emp_dep'] = None
                emp_total_line['emp_code'] = None
                emp_total_line['date'] = '小计'
                emp_total_line['end_work_time'] = None
                emp_total_line['start_work_time'] = None
                emp_total_line['late_minutes'] = sum(l["late_minutes"] or 0
                                                     for l in emp_lines)
                emp_total_line['early_minutes'] = sum(l["early_minutes"] or 0
                                                      for l in emp_lines)
                emp_total_line["work_duration"] = sum(l["work_duration"] or 0
                                                      for l in emp_lines)
                emp_total_line["late_minutes"] = sum(l["late_minutes"] or 0
                                                     for l in emp_lines)

                emp_total_line["overtime_hours"] = sum(l["overtime_hours"] or 0
                                                       for l in emp_lines)
                emp_total_line["holiday_total"] = sum(l["holiday_total"] or 0
                                                      for l in emp_lines)
                emp_total_line["summary"] = string.join(
                    set(l["summary"] for l in emp_lines))
                emp_total_line["forget_card"] = sum(l["forget_card"] or 0
                                                    for l in emp_lines)
                emp_attendances_values.append(emp_total_line)

        CAL_END_TIME = datetime.datetime.now()
        print "结束时间:", CAL_END_TIME
        print "耗时:", CAL_END_TIME - CAL_START_TIME
        return emp_attendances_values
Esempio n. 15
0
    def get_attendance_detail_line(self, dt_date):
        self.ensure_one()
        if not isinstance(dt_date, datetime.date):
            return None

        OfficialHoliday = self.env["hr.official_holiday"]

        dt_str = Date.to_string(dt_date)

        overtime_durations = self.get_overtime_hours_on(date_from=dt_str,
                                                        date_to=dt_str)
        if dt_date.weekday() in (5, 6) and not overtime_durations:
            return None

        line = dict()
        line['name'] = self.name
        line['emp_dep'] = self.department_id.name
        line['emp_code'] = self.internal_code
        line['date'] = dt_date.strftime(
            DEFAULT_SERVER_DATE_FORMAT)  # + " %A" Date.to_string(dt)

        start_work_time = self.get_start_work_time_on(dt_str)
        line["start_work_time"] = start_work_time.strftime(DEFAULT_SERVER_TIME_FORMAT) \
            if start_work_time else None

        end_work_time = self.get_end_work_time_on(dt_str)
        line["end_work_time"] = end_work_time.strftime(DEFAULT_SERVER_TIME_FORMAT) \
            if end_work_time else None

        late_minutes = self.get_late_minutes_on(dt_str)
        line["late_minutes"] = round(late_minutes, 2) if late_minutes else None

        early_minutes = self.get_early_minutes_on(dt_str)
        line["early_minutes"] = round(early_minutes,
                                      2) if early_minutes else None

        work_duration = self.get_work_duration_on(dt_str)
        line["work_duration"] = round(work_duration,
                                      2) if work_duration else None

        # overtime_durations = self.get_overtime_hours_on(date_from=dt_str, date_to=dt_str)

        if overtime_durations:
            line["overtime_stage1"] = overtime_durations.get("stage1", None)
            line["overtime_stage2"] = overtime_durations.get("stage2", None)
            line["overtime_stage3"] = overtime_durations.get("stage3", None)

        # line["overtime_hours"] = round(overtime_hours, 2)

        leaves = self.get_holiday_on(dt_str)
        line["holiday_detail"] = leaves

        all_leaves = list()
        if leaves:
            for l in leaves.values():
                all_leaves.extend(l)
        holiday_total = round(sum(l[2].seconds / 3600.0 for l in all_leaves),
                              2)
        line["holiday_total"] = holiday_total

        official_holiday = OfficialHoliday.get_official_holiday_on(dt_str)
        line["official_holiday"] = official_holiday

        absent = self.get_absent_on(dt_str)

        if leaves:
            line["summary"] = string.join(
                set(leaves.keys() + ([absent] if absent else []) +
                    ([official_holiday] if official_holiday else [])), ",")
        else:
            line["summary"] = None

        if not official_holiday and holiday_total < 8.0:
            line["forget_card"] = self.get_forget_card_on(dt_str)
        else:
            line["forget_card"] = None
        return line
Esempio n. 16
0
    def get_holiday_on(self, date=None):
        self.ensure_one()
        if not date:
            return None

        querying_day = date
        if isinstance(date, datetime.date):
            querying_day = Date.to_string(date)

        leaves = defaultdict(lambda: list())  # [None, None, datetime.timedelta()] _time = datetime.timedelta()

        absent_type_id = self.env.ref("hr_sf.absent_holidays_status").id

        for holiday in self.holidays_ids:
            if not holiday.date_from or not holiday.date_to:
                continue
            if holiday.holiday_status_id.id == absent_type_id:
                continue

            if not all((holiday.morning_start_work_time,
                        holiday.morning_end_work_time,
                        holiday.afternoon_start_work_time,
                        holiday.afternoon_end_work_time)):
                return None

            dt_the_day_morning_start_work_time = datetime.datetime.strptime(
                    "%s %s" % (querying_day, holiday.morning_start_work_time), DEFAULT_SERVER_DATETIME_FORMAT)
            dt_the_day_morning_end_work_time = datetime.datetime.strptime(
                    "%s %s" % (querying_day, holiday.morning_end_work_time), DEFAULT_SERVER_DATETIME_FORMAT)
            dt_the_day_afternoon_start_work_time = datetime.datetime.strptime(
                    "%s %s" % (querying_day, holiday.afternoon_start_work_time), DEFAULT_SERVER_DATETIME_FORMAT)
            dt_the_day_afternoon_end_work_time = datetime.datetime.strptime(
                    "%s %s" % (querying_day, holiday.afternoon_end_work_time), DEFAULT_SERVER_DATETIME_FORMAT)

            dt_holiday_from = Datetime.from_string(holiday.date_from) + datetime.timedelta(hours=8)
            dt_holiday_to = Datetime.from_string(holiday.date_to) + datetime.timedelta(hours=8)
            # deal with morning first
            dt_cal_start = max(dt_the_day_morning_start_work_time, dt_holiday_from)
            dt_cal_start = min(dt_cal_start, dt_the_day_morning_end_work_time)

            dt_cal_end = min(dt_the_day_morning_end_work_time, dt_holiday_to)
            dt_cal_end = max(dt_cal_end, dt_the_day_morning_start_work_time)

            if dt_cal_end > dt_cal_start:
                leaves[holiday.holiday_status_id.name].append((dt_cal_start, dt_cal_end, dt_cal_end - dt_cal_start))
                # leaves[holiday.holiday_status_id.name][0] = dt_cal_start
                # leaves[holiday.holiday_status_id.name][1] = dt_cal_end
                # leaves[holiday.holiday_status_id.name][2] += dt_cal_end - dt_cal_start

            # then deal with afternoon first
            dt_cal_start = max(dt_the_day_afternoon_start_work_time, dt_holiday_from)
            dt_cal_start = min(dt_cal_start, dt_the_day_afternoon_end_work_time)

            dt_cal_end = min(dt_the_day_afternoon_end_work_time, dt_holiday_to)
            dt_cal_end = max(dt_cal_end, dt_the_day_afternoon_start_work_time)

            if dt_cal_end > dt_cal_start:
                leaves[holiday.holiday_status_id.name].append((dt_cal_start, dt_cal_end, dt_cal_end - dt_cal_start))
                # leaves[holiday.holiday_status_id.name][0] = dt_cal_start
                # leaves[holiday.holiday_status_id.name][1] = dt_cal_end
                # leaves[holiday.holiday_status_id.name][2] += dt_cal_end - dt_cal_start

        return leaves
 def _search_age(self, operator, value):
     today = fDate.from_string(fDate.today())
     value_days = td(days=value)
     value_date = fDate.to_string(today - value_days)
     return [('date_release', operator, value_date)]
 def _inverse_age(self):
     today = fDate.from_string(fDate.today())
     for book in self.filtered('date_release'):
         d = td(days=book.age_days) - today
         book.date_release = fDate.to_string(d)
Esempio n. 19
0
 def _search_age(operator, value):
     today = fDate.from_string(fDate.today())
     value_days = td(days=value)
     value_date = fDate.to_string(today - value_days)
     return [('date_release', operator, value_date)]
Esempio n. 20
0
    def get_attendance_detail(self, date_from=None, date_to=None, filter_by_employee=None, employee_ids=None):
        CAL_START_TIME = datetime.datetime.now()
        print "开始计算出勤明细表:", CAL_START_TIME
        if any((date_from, date_to)) and not all((date_from, date_to)):
            return "miss date_from or date_to"

        if not date_from and not date_to:
            now = datetime.datetime.now()
            date_from = datetime.datetime(now.year, now.month, 1)
            date_to = datetime.datetime(date_from.year, date_from.month + 1, 1)
        elif date_from and date_to:
            date_from = Date.from_string(date_from)
            date_to = Date.from_string(date_to)

        Employee = self.env["hr.employee"].sudo()

        emp_attendances_values = []

        employee_search_domain = []
        if filter_by_employee and employee_ids:
            employee_search_domain.append(("id", "in", employee_ids))
        all_employees = Employee.search(employee_search_domain)

        for emp in all_employees:
            dt = date_from
            emp_lines = list()
            while dt <= date_to:
                dt_str = Date.to_string(dt)

                overtime_hours = emp.get_overtime_hours_on(date_from=dt_str, date_to=dt_str)
                if dt.weekday() in (5, 6) and (emp.responsibility or not overtime_hours):
                    dt += datetime.timedelta(days=1)
                    continue

                line = dict()
                line['name'] = emp.name
                line['emp_dep'] = emp.department_id.name
                line['emp_code'] = emp.internal_code
                line['date'] = dt.strftime(DEFAULT_SERVER_DATE_FORMAT)  # + " %A" Date.to_string(dt)

                start_work_time = emp.get_start_work_time_on(dt_str)
                line["start_work_time"] = start_work_time.strftime(DEFAULT_SERVER_TIME_FORMAT) \
                    if start_work_time else None

                end_work_time = emp.get_end_work_time_on(dt_str)
                line["end_work_time"] = end_work_time.strftime(DEFAULT_SERVER_TIME_FORMAT) \
                    if end_work_time else None

                late_minutes = emp.get_late_minutes_on(dt_str)
                line["late_minutes"] = round(late_minutes, 2) if late_minutes else None

                early_minutes = emp.get_early_minutes_on(dt_str)
                line["early_minutes"] = round(early_minutes, 2) if early_minutes else None

                work_duration = emp.get_work_duration_on(dt_str)
                line["work_duration"] = round(work_duration, 2) if work_duration else None

                line["overtime_hours"] = round(overtime_hours, 2)

                leaves = emp.get_holiday_on(dt_str)
                all_leaves = list()
                for l in leaves.values():
                    all_leaves.extend(l)
                line["holiday_total"] = round(sum(l[2].seconds / 3600.0 for l in all_leaves),2)

                absent_for_summary = []
                absent = emp.get_absent_on(dt_str)
                if absent:
                    absent_for_summary.append(_("absent"))
                line["summary"] = string.join(set(leaves.keys() + absent_for_summary), ",")
                line["forget_card"] = emp.get_forget_card_on(dt_str)

                emp_attendances_values.append(line)
                emp_lines.append(line)
                dt += datetime.timedelta(days=1)

            if emp_lines:
                emp_total_line = dict()
                emp_total_line["name"] = None
                emp_total_line['emp_dep'] = None
                emp_total_line['emp_code'] = None
                emp_total_line['date'] = '小计'
                emp_total_line['end_work_time'] = None
                emp_total_line['start_work_time'] = None
                emp_total_line['late_minutes'] = sum(l["late_minutes"] or 0 for l in emp_lines)
                emp_total_line['early_minutes'] = sum(l["early_minutes"] or 0 for l in emp_lines)
                emp_total_line["work_duration"] = sum(l["work_duration"] or 0 for l in emp_lines)
                emp_total_line["late_minutes"] = sum(l["late_minutes"] or 0 for l in emp_lines)

                emp_total_line["overtime_hours"] = sum(l["overtime_hours"] or 0 for l in emp_lines)
                emp_total_line["holiday_total"] = sum(l["holiday_total"] or 0 for l in emp_lines)
                emp_total_line["summary"] = string.join(set(l["summary"] for l in emp_lines))
                emp_total_line["forget_card"] = sum(l["forget_card"] or 0 for l in emp_lines)
                emp_attendances_values.append(emp_total_line)

        CAL_END_TIME = datetime.datetime.now()
        print "结束时间:", CAL_END_TIME
        print "耗时:", CAL_END_TIME - CAL_START_TIME
        return emp_attendances_values
Esempio n. 21
0
 def _search_age_days(self, operator, value):
     today = fDate.from_string(fDate.today())
     value_days = td(days=value)
     value_date = fDate.to_string(today - value_days)
     print '>>>>>>>>>', [('birthday', operator, value_date)]
     return [('birthday', operator, value_date)]
Esempio n. 22
0
    def test_01_max_date(self):
        next_year = '%s-01-01' % (int(self.today[:4]) + 1)
        next_year_feb = '%s-02-01' % (int(self.today[:4]) + 1)
        next_year_feb6 = '%s-02-06' % (int(self.today[:4]) + 1)

        delay = Date.to_string(
            Date.from_string(self.today) + timedelta(days=self.seller_delay))
        self.assertEqual(
            self.product.max_incoming_stock_date, delay)
        self.product.max_incoming_stock_date_override = True
        self.product.max_incoming_stock_date_override_value = next_year
        self.assertEqual(
            self.product.max_incoming_stock_date, next_year)
        self.assertEqual(
            self.bom_product.max_incoming_stock_date, next_year)
        self.product.max_incoming_stock_date_override = False
        picking_in = self.PickingObj.create({
            'partner_id': self.partner_delta_id,
            'picking_type_id': self.picking_type_in})
        self.MoveObj.create({
            'name': self.product.name,
            'product_id': self.product.id,
            'product_uom_qty': 1,
            'product_uom': self.product.uom_id.id,
            'picking_id': picking_in.id,
            'location_id': self.supplier_location,
            'location_dest_id': self.stock_location,
            'date_expected': next_year_feb,
        })
        picking_in.action_confirm()
        self.assertEqual(self.product.max_incoming_stock_date, next_year_feb)
        self.assertEqual(
            self.bom_product.max_incoming_stock_date, next_year_feb)
        self.product.max_incoming_stock_date_override = True
        self.product.max_incoming_stock_date_override_value = self.today
        self.assertEqual(self.product.max_incoming_stock_date, self.today)
        self.env['product.product'].reset_max_incoming_date_override()
        self.assertEqual(self.product.max_incoming_stock_date, next_year_feb)

        # When a product has to be ordered, add supplier lead time to max date
        # expected of running orders
        picking_out = self.PickingObj.create({
            'partner_id': self.partner_delta_id,
            'picking_type_id': self.picking_type_out})
        move = self.MoveObj.create({
            'name': self.product.name,
            'product_id': self.product.id,
            'product_uom_qty': 1,
            'product_uom': self.product.uom_id.id,
            'picking_id': picking_out.id,
            'location_dest_id': self.customer_location,
            'location_id': self.stock_location,
            'date_expected': next_year,
        })
        picking_out.action_confirm()
        self.product.refresh()
        self.assertEqual(self.product.max_incoming_stock_date, next_year_feb)

        # Test that we can modify the picking's max_date (#2800)
        # Call _register_hook manually because tests run before Odoo does
        self.env['stock.picking']._register_hook()
        picking_out.write({'max_date': next_year_feb6})
        self.assertEqual(move.date_expected, next_year_feb6 + ' 00:00:00')
        self.assertEqual(picking_out.max_date, next_year_feb6 + ' 00:00:00')