Exemplo n.º 1
0
 def to_python(self, value):
     if isinstance(value, Duration):
         return value
     if value:
         # if isinstance(value, basestring):
         #     return Duration(value)
         return Duration(value)
     return None
Exemplo n.º 2
0
 def to_python(self, value):
     if isinstance(value, Duration):
         return value
     if value:
         # if isinstance(value, six.string_types):
         #     return Duration(value)
         return Duration(value)
     return None
Exemplo n.º 3
0
 def get_duration(self):
     st = self.get_datetime('start')
     et = self.get_datetime('end')
     if st is None or et is None:
         return None
     if et < st:
         return None  # negative duration not supported
     return Duration(et - st)
Exemplo n.º 4
0
def working_objects():
    # was previously in working
    Company = rt.models.contacts.Company
    # Vote = rt.models.votes.Vote
    SessionType = rt.models.working.SessionType
    Session = rt.models.working.Session
    Ticket = rt.models.tickets.Ticket
    User = rt.models.users.User
    UserTypes = rt.models.users.UserTypes
    # devs = (UserTypes.developer, UserTypes.senior)
    devs = [
        p for p in UserTypes.items() if p.has_required_roles([Worker])
        and not p.has_required_roles([SiteAdmin])
    ]
    workers = User.objects.filter(user_type__in=devs)
    WORKERS = Cycler(workers)
    TYPES = Cycler(SessionType.objects.all())
    # TICKETS = Cycler(Ticket.objects.all())
    DURATIONS = Cycler([12, 138, 90, 10, 122, 209, 37, 62, 179, 233, 5])

    # every fourth ticket is unassigned and thus listed in
    # PublicTickets
    # for i, t in enumerate(Ticket.objects.exclude(private=True)):
    for i, t in enumerate(Ticket.objects.all()):
        if i % 4:
            t.assigned_to = WORKERS.pop()
            yield t

    for u in workers:

        # VOTES = Cycler(Vote.objects.filter(user=u))
        # TICKETS = Cycler(Ticket.objects.filter(assigned_to=u))
        TICKETS = Cycler(Ticket.objects.filter())
        # if len(VOTES) == 0:
        #     continue

        for offset in (0, -1, -3, -4):

            date = dd.demo_date(offset)
            worked = Duration()
            ts = datetime.datetime.combine(date, datetime.time(9, 0, 0))
            for i in range(7):
                obj = Session(ticket=TICKETS.pop(),
                              session_type=TYPES.pop(),
                              user=u)
                obj.set_datetime('start', ts)
                d = DURATIONS.pop()
                worked += d
                if offset < 0:
                    ts = DurationUnits.minutes.add_duration(ts, d)
                    obj.set_datetime('end', ts)
                yield obj
                if offset == 0 or worked > 8:
                    break

    ServiceReport = rt.models.working.ServiceReport
    welket = Company.objects.get(name="welket")
    yield ServiceReport(start_date=dd.today(-90), interesting_for=welket)
Exemplo n.º 5
0
def load_sessions(self, sar):
    self._root2tot = {}
    self._tickets = set()
    grand_tot = Duration()
    for ses in sar:
        self._tickets.add(ses.ticket)
        d = ses.get_duration() or MIN_DURATION
        grand_tot += d
        # root = ses.get_root_project()
        root = ses.get_reporting_type()
        # if ses.ticket:
        #     root = ses.ticket.reporting_type
        # else:
        #     root = None
        tot = self._root2tot.get(root, Duration()) + d
        self._root2tot[root] = tot

    self._root2tot[TOTAL_KEY] = grand_tot
Exemplo n.º 6
0
def compute_invested_time(obj, **spv):
    # spv = dict(start_date=pv.start_date, end_date=pv.end_date)
    spv.update(observed_event=dd.PeriodEvents.started)
    sar = SessionsByTicket.request(master_instance=obj, param_values=spv)
    tot = Duration()
    for obj in sar:
        d = obj.get_duration()
        if d is not None:
            tot += d
    return tot
Exemplo n.º 7
0
    def weekly_reporter(days, ar, start_date, end_date):
        Session = rt.models.working.Session
        me = ar.get_user()
        qs = Session.objects.filter(user=me,
                                    start_date__gte=start_date,
                                    end_date__lte=end_date)
        # print 20150420, start_date, end_date, qs
        d2p = dict()
        for ses in qs:
            prj = ses.ticket.project
            if prj is not None:
                while prj.parent is not None:
                    prj = prj.parent
            projects = d2p.setdefault(ses.start_date, dict())
            duration = projects.setdefault(prj, Duration())
            duration += ses.get_duration()
            projects[prj] = duration

        # print 20150420, d2p
        def fmt(delta):
            return str(Duration(delta))

        for date, projects in d2p.items():
            parts = []
            tot = Duration()
            for prj, duration in projects.items():
                if prj is None:
                    prj = "N/A"
                txt = "{0} ({1})".format(prj, fmt(duration))
                parts.append(txt)
                tot += duration
            if len(parts):
                if len(parts) == 1:
                    txt = parts[0]
                else:
                    txt = ', '.join(parts) + " = " + fmt(tot)
                txt = E.p(txt, style="text-align:right")
                days[date].append(txt)
Exemplo n.º 8
0
    def get_table_summary(self, obj, ar):
        if ar is None:
            return ''
        elems = []

        # Button for starting a session from ticket
        sar = obj.start_session.request_from(ar)
        # if ar.renderer.is_interactive and sar.get_permission():
        # if sar.get_permission():
        #     btn = sar.ar2button(obj)
        #     elems += [E.p(btn)]

        # Active sessions:
        active_sessions = []
        session_summaries = E.ul()
        qs = rt.models.working.Session.objects.filter(ticket=obj)
        tot = Duration()
        for ses in qs:
            d = ses.get_duration()
            if d is not None:
                tot += d
            if ses.end_time is None:
                txt = "{0} since {1}".format(ses.user, ses.start_time)
                lnk = ar.obj2html(ses, txt)
                sar = ses.end_session.request_from(ar)
                if sar.get_permission():
                    lnk = E.span(lnk, " ", sar.ar2button(ses))
                active_sessions.append(lnk)
            if ses.summary:
                session_summaries.insert(
                    0,
                    E.li("%s %s: %s" %
                         (ses.user,
                          naturaltime(
                              datetime.combine(ses.start_date,
                                               ses.start_time)), ses.summary)))

        # elems.append(E.p(_("Total {0} hours.").format(tot)))
        elems.append(E.p(_("Total %s hours.") % tot))

        if len(active_sessions) > 0:
            elems.append(
                E.p(ensureUtf(_("Active sessions")), ": ",
                    *join_elems(active_sessions, ', ')))
        if len(session_summaries) > 0:
            elems.append(session_summaries)

        return ar.html_text(E.div(*elems))
Exemplo n.º 9
0
    def get_duration(self):
        """Return the duration in hours."""
        if not self.start_date:
            return None
        if not self.start_time:
            return None
        if not self.end_time:
            return None

        ed = self.end_date or self.start_date

        st = datetime.datetime.combine(self.start_date, self.start_time)
        et = datetime.datetime.combine(ed, self.end_time)

        if et < st:
            return None  # negative duration not supported
        # print 20151127, repr(et), repr(st)
        return Duration(et - st)
Exemplo n.º 10
0
from lino.modlib.system.choicelists import ObservedEvent
from lino.mixins.periods import ObservedDateRange

from lino_xl.lib.tickets.roles import Triager, TicketsStaff
from lino_xl.lib.tickets.choicelists import (TicketEvents, TicketStates)
from lino_xl.lib.calview.ui import Day, Days

from .roles import Worker
from .choicelists import ReportingTypes


class TOTAL_KEY(object):
    pass


MIN_DURATION = Duration('0:01')


def ensureUtf(s):
    if sys.version_info < (3, ):
        return unicode(s)
    else:
        return str(s)


class TicketHasSessions(ObservedEvent):
    text = _("Has been worked on")

    def add_filter(self, qs, pv):
        if pv.start_date:
            qs = qs.filter(sessions_by_ticket__start_date__gte=pv.start_date)
Exemplo n.º 11
0
 def from_db_value(self, value, expression, connection, context):
     return Duration(value) if value else self.get_default()
Exemplo n.º 12
0
 def fmt(delta):
     return str(Duration(delta))
Exemplo n.º 13
0
# -*- coding: UTF-8 -*-
# Copyright 2014-2017 Rumma & Ko Ltd
# License: BSD (see file COPYING for details)


from lino.api import dd, _

from lino.utils.quantities import Duration

ZERO_DURATION = Duration('0:00')

class ReportingTypes(dd.ChoiceList):
    verbose_name = _("Reporting type")
    verbose_name_plural = _("Reporting types")


add = ReportingTypes.add_item

add('10', _("Regular"), 'regular')
add('20', _("Extra"), 'extra')
add('30', _("Free"), 'free')
# add('10', _("Worker"), 'worker')
# add('20', _("Employer"), 'employer')
# add('30', _("Customer"), 'customer')