Example #1
0
 def get_turn(self, cr, uid, ids, date, context=None):
     res = {}
     if isinstance(date, str):
         date = tu.dt(date)
     for cont in self.browse(cr, uid, ids):
         if (tu.d(cont.date_start) <= date and
             (cont.date_end == False or date <= tu.d(cont.date_end))):
             ts = filter(
                 lambda i: i.dayofweek == str(date.weekday()) or i.dayofweek
                 == '', cont.turn_id.timesheet_id)
             if len(ts) == 1:
                 ddate = tu.datetime.combine(date.date(), tu.time(0))
                 res[cont.id] = (
                     ddate + tu.timedelta(hours=ts[0].hour_from), ddate +
                     tu.timedelta(hours=24 *
                                  (ts[0].hour_from > ts[0].hour_to) +
                                  ts[0].hour_to))
             elif len(ts) > 1:
                 raise RuntimeError(
                     "More than one turn enabled at same time. See Timesheet line."
                 )
             else:
                 res[cont.id] = False
         else:
             res[cont.id] = False
     return res
Example #2
0
 def get_turn(self, cr, uid, ids, date, context=None):
     res = {}
     if isinstance(date, str):
         date = tu.dt(date)
     for cont in self.browse(cr, uid, ids):
         if (tu.d(cont.date_start) <= date and
             (cont.date_end == False or date <= tu.d(cont.date_end))):
                 ts = filter(lambda i:
                     i.dayofweek == str(date.weekday()) or i.dayofweek == '',
                                        cont.turn_id.timesheet_id)
                 if len(ts) == 1:
                     ddate = tu.datetime.combine(date.date(), tu.time(0))
                     res[cont.id] = (ddate +
                                     tu.timedelta(hours=ts[0].hour_from),
                                     ddate +
                                     tu.timedelta(hours=
                                     24 * (ts[0].hour_from >
                                           ts[0].hour_to) + ts[0].hour_to))
                 elif len(ts) > 1:
                     raise RuntimeError("More than one turn enabled at same time. See Timesheet line.")
                 else:
                     res[cont.id] = False
         else:
             res[cont.id] = False
     return res
Example #3
0
    def _inv_attendance(self, cr, uid, ids, field_name, value, arg, context=None):
        """
        Store attendance from a journal. Assign employee id and set the correct
        datetime.
        """
        jou_id = ids
        for no_se, att_id, val in value:
            if val:
                # Who is the associated journal?
                if jou_id == 0:
                    if not isinstance(ids, int):
                        raise osv.except_osv(_('Error'),
                                             _('I expect process attendance just for one journal'))
                    jou_id = ids
                jou = self.browse(cr, uid, jou_id)

                # Check date if not out of turn time.
                if not jou._date_overlaps(tu.dt(val['name']))[jou.id]:
                    an = tu.datetime.combine(tu.d(jou.date).date(), tu.dt(val['name']).time())
                    if not jou._date_overlaps(an)[jou.id]:
                        an = tu.datetime.combine(tu.d(jou.date).date() + tu.timedelta(days=1), tu.dt(val['name']).time())
                    val['name'] = tu.dt2s(an)
                    if not (jou._date_overlaps(tu.dt(val['name']))):
                        raise osv.except_osv(_('Error'),
                                             _('Attendance don\'t belong to this journal'))

        # Sort entries
        att_ids = []
        values = []
        for no_se, att_id, val in value:
            if val:
                att_ids.append(att_id)
                values.append(val) 
        att_ids.sort()
        values.sort(key=lambda i: i['name'])
        attval = dict(zip(att_ids, values))

        # Store new or modification
        for att_id, val in zip(att_ids, values):
            if val:
                if att_id == 0:
                   val['employee_id'] = jou.employee_id.id
                   self.pool.get('hr.attendance').create(cr, uid, val)
                else:
                   self.pool.get('hr.attendance').write(cr, uid, att_id, val)

        # Delete entries
        for no_se, att_id, val in value:
            if not val:
                self.pool.get('hr.attendance').unlink(cr, uid, att_id)
Example #4
0
 def __getitem__(self, name):
     if name in self._local_cache:
         return self._local_cache[name]
     if name in self._cache:
         ret = self._cache[name]
         if isinstance(ret, bool):
             return ret
         field = self._field[name]
         if field["type"] in ["char", "int", "float", "selection"]:
             _r = ret
         elif field["type"] in ["datetime"]:
             _r = tu.dt(ret)
         elif field["type"] in ["date"]:
             _r = tu.d(ret)
         elif field["type"] in ["many2one"]:
             _r = Interface(*(self._parms + (ret[0], field["relation"])))
         elif field["type"] in ["many2many", "one2many"]:
             _r = map(lambda a: Interface(*(self._parms + a)), zip(ret, [field["relation"]] * len(ret)))
         else:
             raise NotImplementedError, "Not implemented for %s of type %s (%s)." % (name, field["type"], str(ret))
         self._local_cache[name] = _r
         return _r
     else:
         # raise ValueError, "Not exists %s in object." % name
         return False
 def __getitem__(self, name):
     if name in self._local_cache:
         return self._local_cache[name]
     if name in self._cache:
         ret = self._cache[name]
         if isinstance(ret, bool): return ret
         field = self._field[name]
         if field['type'] in ['char', 'int', 'float', 'selection']:
             _r = ret
         elif field['type'] in ['datetime']:
             _r = tu.dt(ret)
         elif field['type'] in ['date']:
             _r = tu.d(ret)
         elif field['type'] in ['many2one']:
             _r = Interface(*(self._parms + (ret[0], field['relation'])))
         elif field['type'] in ['many2many', 'one2many']:
             _r = map(lambda a: Interface(*(self._parms + a)),
                      zip(ret, [field['relation']] * len(ret)))
         else:
             raise NotImplementedError, \
                 "Not implemented for %s of type %s (%s)." % (name,
                                                              field['type'],
                                                             str(ret))
         self._local_cache[name] = _r
         return _r
     else:
         # raise ValueError, "Not exists %s in object." % name
         return False
Example #6
0
    def _get_holidays(self, cr, uid, ids, field_name, arg, context=None):
        """
        Generate list of attendance associated to the this journal.
        """
        res = {}
	data = self.read(cr, uid, ids, ['employee_id', 'date', 'turn_start', 'turn_end'], context=context)
	for d in data:
            turn_start = d['turn_start']
            turn_end = d['turn_end']
            employee_id = d['employee_id'][0]
	    date = d['date']
	    _id = d['id']
            if turn_start:
                date_start, date_end = turn_start, turn_end
            else:
                date_start, date_end = date, tu.dt2s(tu.d(date) +
                                                         tu.timedelta(days=1))

            sql_req= """
            SELECT H.id AS func_id
            FROM hr_holidays as H
            WHERE
              (H.employee_id = %d OR H.employee_id is Null) AND
              (H.date_from, H.date_to) OVERLAPS
              ('%s'::timestamp, '%s'::timestamp)
            """ % (employee_id, date_start, date_end)
            cr.execute(sql_req)
            sql_res = cr.fetchall()

            if len(sql_res) > 0:
                res[_id] = map(lambda (i,): i, sql_res)
            else:
                res[_id] = []
        return res
Example #7
0
    def build(self, cr, uid, date_from, date_to, emp_ids=[], context=None):
        pool_emp = self.pool.get("hr.employee")
        pool_line = self.pool.get("hr.aa.payroll.line")
        pool_con = self.pool.get("hr.contract")

        pr_name = "%s - %s" % (date_from, date_to)
        pr_id = self.create(cr, uid, {"name": pr_name, "date_from": date_from, "date_to": date_to})

        emps = pool_emp.browse(cr, uid, emp_ids)
        for emp in emps:
            con_id = emp.get_valid_contract(tu.d(date_from))[emp.id]
            con = pool_con.browse(cr, uid, con_id, context=context)
            pool_line.create(
                cr,
                uid,
                {
                    "name": "%s (%s)" % (emp.name, pr_name),
                    "employee_id": emp.id,
                    "payroll_id": pr_id,
                    "wage_type_id": con.wage_type_id.id,
                    "wage": con.wage,
                },
            )

        return pr_id
Example #8
0
    def compute(self, cr, uid, ids, context=None):
        lines_to_compute = []
        for payroll in self.browse(cr, uid, ids, context=context):
            if payroll.state == "draft":
                self.pool.get("hr.aa.journal").build(
                    cr, uid, tu.dt2s(tu.d(payroll.date_from)), tu.dt2s(tu.d(payroll.date_to)), context=context
                )
                lines_to_compute += [l.id for l in payroll.line_ids]
        import cProfile

        cProfile.runctx(
            'self.pool.get("hr.aa.payroll.line").compute(cr, uid, lines_to_compute)',
            {"self": self, "cr": cr, "uid": uid, "lines_to_compute": lines_to_compute},
            None,
            "/tmp/compute.pstats",
        )
        return True
Example #9
0
    def _get_turn_start(self, cr, uid, ids, field_name, arg, context=None):
        res = {}
        for journal in self.browse(cr, uid, ids):
            if journal.turn_id:
		wd_l = [ str(tu.d(journal.date).weekday()), '' ]
                ts = filter(lambda i:
                                i.dayofweek in wd_l,
                                journal.turn_id.timesheet_id)
                if len(ts) == 1:
                    res[journal.id] = tu.dt2s(tu.d(journal.date) +
                                        tu.timedelta(hours=ts[0].hour_from))
                elif len(ts) > 1:
                    raise osv.except_osv(_('Error'), _('Overlaped turn for the journal %s.') % journal.name)
                else:
                    res[journal.id] = False
            else:
                res[journal.id] = False
        return res