示例#1
0
    def load_mbr(self, row, **kw):

        p1 = self.get_customer(row.idpar)
        if p1 is None:
            dd.logger.debug("Failed to load MBR %s : " "No idpar", row)
            return
        p2 = self.get_customer(row.idpar2)

        if p2 is not None:
            contact_role = self.contact_roles.get(row.idpls.strip())
            if contact_role is not None:
                kw = dict()
                p = mti.get_child(p1, Company)
                if p is None:
                    dd.logger.debug(
                        "Failed to load MBR %s : "
                        "idpar is not a company", row)
                    return
                kw.update(company=p)
                p = mti.get_child(p2, Person)
                if p is None:
                    dd.logger.debug(
                        "Failed to load MBR %s : "
                        "idpar2 is not a person", row)
                    return
                kw.update(person=p)
                kw.update(type=contact_role)
                return Role(**kw)

            role = self.household_roles.get(row.idpls.strip())
            if role is not None:
                household = mti.get_child(p1, Household)
                if household is None:
                    dd.logger.debug(
                        "Failed to load MBR %s : "
                        "idpar is not a household", row)
                    return
                person = mti.get_child(p2, Person)
                if person is None:
                    dd.logger.debug(
                        "Failed to load MBR %s : idpar2 is not a person", row)
                    return
                return households_Member(household=household,
                                         person=person,
                                         role=role)
            dd.logger.debug("Failed to load MBR %s : idpar2 is not empty", row)
            return

        try:
            lst = List.objects.get(ref=row.idpls.strip())
        except List.DoesNotExist:
            dd.logger.debug("Failed to load MBR %s : unknown idpls", row)
            return
        kw.update(list=lst)
        kw.update(remark=row.remarq)
        kw.update(partner=p1)
        return Member(**kw)
示例#2
0
文件: models.py 项目: khchine5/voga
    def get_invoiceables_for_plan(cls, plan, partner=None):
        """Yield all enrolments for which the given plan and partner should
        generate an invoice.

        """
        qs = cls.objects.filter(**{
            cls.invoiceable_date_field + '__lte': plan.max_date or plan.today})
        if plan.course is not None:
            qs = qs.filter(course__id=plan.course.id)
        else:
            qs = qs.filter(course__state=CourseStates.active)
        if partner is None:
            partner = plan.partner
        if partner:
            pupil = get_child(partner, rt.models.courses.Pupil)
            # pupil = partner.get_mti_child('pupil')
            if pupil:  # isinstance(partner, rt.models.courses.Pupil):
                q1 = models.Q(
                    pupil__invoice_recipient__isnull=True, pupil=pupil)
                q2 = models.Q(pupil__invoice_recipient=partner)
                qs = cls.objects.filter(models.Q(q1 | q2))
            else:
                # if the partner is not a pupil, then it might still
                # be an invoice_recipient
                qs = cls.objects.filter(pupil__invoice_recipient=partner)
                
        # dd.logger.info("20160513 %s (%d rows)", qs.query, qs.count())
        for obj in qs.order_by(cls.invoiceable_date_field):
            # dd.logger.info('20160223 %s', obj)
            yield obj
示例#3
0
    def disable_delete(self, ar=None):
        """Overrides :meth:`lino.core.model.Model.disable_delete`.

        In case of polymorphy, the user can ask to delete any MTI
        instance of a polymorphic entity. Deleting one instance will
        delete all other instances as well.

        Before deleting one polymorphic instance, we ask all other
        instances for their vetos.

        Cascade-related objects are deleted independently of the
        instance that initiated deletion.

        """
        # ask all other forms of this for vetos:
        for m in self._mtinav_models:
            if m is not self.__class__:
                obj = mti.get_child(self, m)
                if obj is not None:
                    ignore_models = set(self._mtinav_models)
                    ignore_models.remove(m)
                    msg = m._lino_ddh.disable_delete_on_object(
                        obj, ignore_models)
                    if msg is not None:
                        return msg

        # Now ask my own model, ignoring all other forms because they
        # have been asked.
        ignore_models = set(self._mtinav_models)
        ignore_models.remove(self.__class__)
        return self.__class__._lino_ddh.disable_delete_on_object(
            self, ignore_models=ignore_models)
示例#4
0
    def disable_delete(self, ar=None):
        """Overrides :meth:`lino.core.model.Model.disable_delete`.

        In case of polymorphy, the user can ask to delete any MTI
        instance of a polymorphic entity. Deleting one instance will
        delete all other instances as well.

        Before deleting one polymorphic instance, we ask all other
        instances for their vetos.

        Cascade-related objects are deleted independently of the
        instance that initiated deletion.

        """
        # ask all other forms of this for vetos:
        for m in self._mtinav_models:
            if m is not self.__class__:
                obj = mti.get_child(self, m)
                if obj is not None:
                    ignore_models = set(self._mtinav_models)
                    ignore_models.remove(m)
                    msg = m._lino_ddh.disable_delete_on_object(
                        obj, ignore_models)
                    if msg is not None:
                        return msg

        # Now ask my own model, ignoring all other forms because they
        # have been asked.
        ignore_models = set(self._mtinav_models)
        ignore_models.remove(self.__class__)
        return self.__class__._lino_ddh.disable_delete_on_object(
            self, ignore_models=ignore_models)
示例#5
0
文件: desktop.py 项目: khchine5/xl
 def param_defaults(self, ar, **kw):
     kw = super(MyCoursesGiven, self).param_defaults(ar, **kw)
     u = ar.get_user()
     if isinstance(u, teacher_model):
         pass
     elif u.partner is not None:
         u = get_child(u.partner, teacher_model)
     kw['teacher'] = u
     return kw
示例#6
0
文件: desktop.py 项目: einarfelix/xl
 def param_defaults(self, ar, **kw):
     kw = super(MyCoursesGiven, self).param_defaults(ar, **kw)
     kw.update(show_exposed=dd.YesNo.yes)
     u = ar.get_user()
     if isinstance(u, teacher_model):
         pass
     elif u.partner is not None:
         u = get_child(u.partner, teacher_model)
     kw['teacher'] = u
     return kw
示例#7
0
 def get_mti_buttons(self, ar):
     forms = []
     for m in self._mtinav_models:
         if self.__class__ is m:
             forms.append(unicode(m._meta.verbose_name))
         else:
             obj = mti.get_child(self, m)
             if obj is not None:
                 forms.append(ar.obj2html(obj, m._meta.verbose_name))
     return forms
示例#8
0
    def get_mti_leaf(self):
        """
        Return the specialized form of this voucher.

        For example if we have :class:`ml.ledger.Voucher` instance, we
        can get the actual document (Invoice, PaymentOrder,
        BankStatement, ...) by calling this method.


        """
        return mti.get_child(self, self.journal.voucher_type.model)
示例#9
0
 def obj2href(self, ar, *args, **kwargs):
     # a = super(Polymorphic, self).get_detail_action(ar)
     a = self.get_detail_action(ar)
     if a is not None:
         return super(Polymorphic, self).obj2href(ar, *args, **kwargs)
     for m in self._mtinav_models:
         if m is not self.__class__:
             obj = mti.get_child(self, m)
             if obj is not None:
                 if obj.get_detail_action(ar) is not None:
                     return obj.obj2href(ar, *args, **kwargs)
示例#10
0
文件: models.py 项目: khchine5/cosi
    def get_mti_leaf(self):
        """
        Return the specialized form of this voucher.

        For example if we have :class:`ml.ledger.Voucher` instance, we
        can get the actual document (Invoice, PaymentOrder,
        BankStatement, ...) by calling this method.


        """
        return mti.get_child(self, self.journal.voucher_type.model)
示例#11
0
文件: models.py 项目: khchine5/voga
    def get_invoiceables_for_plan(cls, plan, partner=None):
        qs = cls.objects.filter(**{
            cls.invoiceable_date_field + '__lte': plan.max_date or plan.today})

        if partner:
            company = get_child(partner, rt.modules.contacts.Company)
            if company:
                qs = qs.filter(company=company)
            else:
                return
        for obj in qs.order_by(cls.invoiceable_date_field):
            yield obj
示例#12
0
    def get_generators_for_plan(cls, plan, partner=None):
        qs = cls.objects.all()
        # filter(**{
        #     cls.invoiceable_date_field + '__lte': plan.max_date or plan.today})

        if partner:
            company = get_child(partner, rt.models.contacts.Company)
            if company:
                qs = qs.filter(company=company)
            else:
                return cls.objects.none()
        return qs.order_by('id')
示例#13
0
    def get_mti_buttons(self, ar):
        """"""
        elems = []
        if ar is None:
            return elems
        sep = None
        for m in self._mtinav_models:
            item = None
            if self.__class__ is m:
                item = [E.b(str(m._meta.verbose_name))]
            else:
                obj = mti.get_child(self, m)
                if obj is None:
                    # parent link field
                    p = m._meta.parents.get(self.__class__, None)
                    if p is not None:
                        item = [str(m._meta.verbose_name)]
                        k = InsertChild.name_prefix + m.__name__.lower()
                        ba = ar.actor.get_action_by_name(k)
                        if ba and ba.get_row_permission(ar, self, None):
                            # btn = ar.row_action_button(self, ba, _("+"))
                            btn = ar.row_action_button(self, ba, _(u"➕"))
                            # Heavy Plus Sign U+2795
                            # btn = ar.row_action_button(self, ba,
                            #                            icon_name='add')
                            item += [" [", btn, "]"]

                else:
                    da = obj.get_detail_action(ar)
                    if da is not None:
                        item = [ar.obj2html(obj, m._meta.verbose_name)]
                        # no DeleteChild for my parents
                        if self.__class__ in m.mro():
                            k = DeleteChild.name_prefix + m.__name__.lower()
                            ba = ar.actor.get_action_by_name(k)
                            if ba and ba.get_row_permission(ar, self, None):
                                btn = ar.row_action_button(self, ba, _(u"❌"))
                                # Cross Mark U+274C
                                item += [" [", btn, "]"]

            if item is not None:
                if sep is None:
                    sep = ', '
                else:
                    elems.append(sep)
                elems += item
        return elems
示例#14
0
    def get_mti_buttons(self, ar):
        """"""
        elems = []
        if ar is None:
            return elems
        sep = None
        for m in self._mtinav_models:
            item = None
            if self.__class__ is m:
                item = [E.b(str(m._meta.verbose_name))]
            else:
                obj = mti.get_child(self, m)
                if obj is None:
                    # parent link field
                    p = m._meta.parents.get(self.__class__, None)
                    if p is not None:
                        item = [str(m._meta.verbose_name)]
                        k = InsertChild.name_prefix + m.__name__.lower()
                        ba = ar.actor.get_action_by_name(k)
                        if ba and ba.get_row_permission(ar, self, None):
                            # btn = ar.row_action_button(self, ba, _("+"))
                            btn = ar.row_action_button(self, ba, _(u"➕"))
                            # Heavy Plus Sign U+2795
                            # btn = ar.row_action_button(self, ba,
                            #                            icon_name='add')
                            item += [" [", btn, "]"]

                else:
                    item = [ar.obj2html(obj, m._meta.verbose_name)]
                    # no DeleteChild for my parents
                    if self.__class__ in m.mro():
                        k = DeleteChild.name_prefix + m.__name__.lower()
                        ba = ar.actor.get_action_by_name(k)
                        if ba and ba.get_row_permission(ar, self, None):
                            # btn = ar.row_action_button(self, ba, _("-"))
                            btn = ar.row_action_button(self, ba, _(u"❌"))
                            # Cross Mark U+274C
                            item += [" [", btn, "]"]

            if item is not None:
                if sep is None:
                    sep = ', '
                else:
                    elems.append(sep)
                elems += item
        return elems
示例#15
0
    def load_mbr(self, row, **kw):
        p1 = self.get_customer(row.idpar)
        if p1 is None:
            dd.logger.debug(
                "Failed to load MBR %s : "
                "No idpar", row)
            return
        p2 = self.get_customer(row.idpar2)

        if p2 is not None:
            if row.idpls.strip() == 'M':
                c1 = mti.get_child(p1, Company)
                c2 = mti.get_child(p2, Company)
                if c1 and c2:
                    if c2.parent is None:
                        c2.parent = c1
                        return c2
            
            contact_role = self.contact_roles.get(row.idpls.strip())
            if contact_role is not None:
                kw = dict()
                p = mti.get_child(p1, Company)
                if p is None:
                    dd.logger.debug(
                        "Failed to load MBR %s : "
                        "idpar is not a company", row)
                    return
                kw.update(company=p)
                p = mti.get_child(p2, Person)
                if p is None:
                    dd.logger.debug(
                        "Failed to load MBR %s : "
                        "idpar2 is not a person", row)
                    return
                kw.update(person=p)
                kw.update(type=contact_role)
                return Role(**kw)

            role = self.household_roles.get(row.idpls.strip())
            if role is not None:
                household = mti.get_child(p1, Household)
                if household is None:
                    dd.logger.debug(
                        "Failed to load MBR %s : "
                        "idpar is not a household", row)
                    return
                person = mti.get_child(p2, Person)
                if person is None:
                    dd.logger.debug(
                        "Failed to load MBR %s : idpar2 is not a person", row)
                    return
                return households_Member(
                    household=household,
                    person=person,
                    role=role)
            dd.logger.debug(
                "Failed to load MBR %s : idpar2 is not empty", row)
            return

        try:
            lst = List.objects.get(ref=row.idpls.strip())
        except List.DoesNotExist:
            dd.logger.debug(
                "Failed to load MBR %s : unknown idpls", row)
            return
        kw.update(list=lst)
        kw.update(remark=row.remarq)
        kw.update(partner=p1)
        return Member(**kw)
示例#16
0
 def get_mti_leaf(self):
     return mti.get_child(self, self.journal.voucher_type.model)
示例#17
0
 def get_mti_leaf(self):
     return mti.get_child(self, self.journal.voucher_type.model)