Exemplo n.º 1
0
    def genericFormExtraClean(self, data, form):
        """Check that unique_together is fulfiled"""
        from accounting_core.models import CostCenter

        if CostCenter.objects.exclude(pk=self.pk).filter(accounting_year=get_current_year(form.truffe_request), name=data['name']).count():
            raise forms.ValidationError(_(u'Un centre de coûts avec ce nom existe déjà pour cette année comptable.'))  # Potentiellement parmi les supprimées

        if CostCenter.objects.exclude(pk=self.pk).filter(accounting_year=get_current_year(form.truffe_request), account_number=data['account_number']).count():
            raise forms.ValidationError(_(u'Un centre de coûts avec ce numéro de compte existe déjà pour cette année comptable.'))  # Potentiellement parmi les supprimées
Exemplo n.º 2
0
    def genericFormExtraClean(self, data, form):
        """Check that unique_together is fulfiled"""
        from accounting_core.models import CostCenter

        if CostCenter.objects.exclude(pk=self.pk).filter(accounting_year=get_current_year(form.truffe_request), name=data['name']).count():
            raise forms.ValidationError(_(u'Un centre de coûts avec ce nom existe déjà pour cette année comptable.'))  # Potentiellement parmi les supprimées

        if CostCenter.objects.exclude(pk=self.pk).filter(accounting_year=get_current_year(form.truffe_request), account_number=data['account_number']).count():
            raise forms.ValidationError(_(u'Un centre de coûts avec ce numéro de compte existe déjà pour cette année comptable.'))  # Potentiellement parmi les supprimées
Exemplo n.º 3
0
    def genericFormExtraClean(self, data, form):
        """Check that unique_together is fulfiled and that category is in the right accounting_year"""
        from accounting_core.models import Account

        if Account.objects.exclude(pk=self.pk).filter(accounting_year=get_current_year(form.truffe_request), name=data['name']).count():
            raise forms.ValidationError(_(u'Un compte de CG avec ce nom existe déjà pour cette année comptable.'))  # Potentiellement parmi les supprimées

        if Account.objects.exclude(pk=self.pk).filter(accounting_year=get_current_year(form.truffe_request), account_number=data['account_number']).count():
            raise forms.ValidationError(_(u'Un compte de CG avec ce numéro de compte existe déjà pour cette année comptable.'))  # Potentiellement parmi les supprimées

        if data['category'].accounting_year != get_current_year(form.truffe_request):
            raise forms.ValidationError(_(u'La catégorie choisie n\'appartient pas à la bonne année comptable.'))
Exemplo n.º 4
0
    def genericFormExtraClean(self, data, form):
        """Check that unique_together is fulfiled and that category is in the right accounting_year"""
        from accounting_core.models import Account

        if Account.objects.exclude(pk=self.pk).filter(accounting_year=get_current_year(form.truffe_request), name=data['name']).count():
            raise forms.ValidationError(_(u'Un compte de CG avec ce nom existe déjà pour cette année comptable.'))  # Potentiellement parmi les supprimées

        if Account.objects.exclude(pk=self.pk).filter(accounting_year=get_current_year(form.truffe_request), account_number=data['account_number']).count():
            raise forms.ValidationError(_(u'Un compte de CG avec ce numéro de compte existe déjà pour cette année comptable.'))  # Potentiellement parmi les supprimées

        if data['category'].accounting_year != get_current_year(form.truffe_request):
            raise forms.ValidationError(_(u'La catégorie choisie n\'appartient pas à la bonne année comptable.'))
Exemplo n.º 5
0
    def genericFormExtraClean(self, data, form):
        """Check that unique_together is fulfiled"""
        from accounting_core.models import AccountCategory

        if AccountCategory.objects.exclude(pk=self.pk).filter(
                accounting_year=get_current_year(form.truffe_request),
                name=data['name']).count():
            raise forms.ValidationError(
                _(u'Une catégorie avec ce nom existe déjà pour cette année comptable.'
                  ))  # Potentiellement parmi les supprimées

        if data['parent_hierarchique'] and data[
                'parent_hierarchique'].accounting_year != get_current_year(
                    form.truffe_request):
            raise forms.ValidationError(
                _(u'La catégorie parente choisie n\'appartient pas à la bonne année comptable.'
                  ))
Exemplo n.º 6
0
    def genericFormExtraClean(self, data, form):
        """Check that unique_together is fulfiled"""
        from accounting_core.models import AccountCategory

        if AccountCategory.objects.exclude(pk=self.pk).filter(accounting_year=get_current_year(form.truffe_request), name=data['name']).count():
            raise forms.ValidationError(_(u'Une catégorie avec ce nom existe déjà pour cette année comptable.'))  # Potentiellement parmi les supprimées

        if data['parent_hierarchique'] and data['parent_hierarchique'].accounting_year != get_current_year(form.truffe_request):
            raise forms.ValidationError(_(u'La catégorie parente choisie n\'appartient pas à la bonne année comptable.'))
Exemplo n.º 7
0
    def render(self, context):
        for (obj, user, right), nodelist in self.conditions_nodelists:

            if right is not None:  # if / elif clause
                obj = template.Variable(obj).resolve(context)
                user = template.Variable(user).resolve(context)
                right = template.Variable(right).resolve(context)

                if isinstance(obj, str):
                    new_obj = importlib.import_module('.'.join(
                        obj.split('.')[:-1]))
                    obj = getattr(new_obj, obj.split('.')[-1])

                force_static = False

                if right[0] == '!':
                    force_static = True
                    right = right[1:]

                if isinstance(obj, ModelWithRight) and not force_static:
                    match = obj.rights_can(right, user)
                elif hasattr(obj, 'static_rights_can'):
                    match = obj.static_rights_can(
                        right, user,
                        get_current_unit(context['request'])
                        if force_static else None,
                        get_current_year(context['request'])
                        if force_static else None)
                else:
                    raise Exception("?", obj, " cannot be used for rights")

            else:
                match = True

            if match:
                return nodelist.render(context)
        return ''
Exemplo n.º 8
0
    def render(self, context):
        for (obj, user, right), nodelist in self.conditions_nodelists:

            if right is not None:  # if / elif clause
                obj = template.Variable(obj).resolve(context)
                user = template.Variable(user).resolve(context)
                right = template.Variable(right).resolve(context)

                if isinstance(obj, basestring):
                    new_obj = importlib.import_module('.'.join(obj.split('.')[:-1]))
                    obj = getattr(new_obj, obj.split('.')[-1])

                force_static = False

                if right[0] == '!':
                    force_static = True
                    right = right[1:]

                if isinstance(obj, ModelWithRight) and not force_static:
                    match = obj.rights_can(right, user)
                elif hasattr(obj, 'static_rights_can'):
                    match = obj.static_rights_can(right, user, get_current_unit(context['request']) if force_static else None, get_current_year(context['request']) if force_static else None)
                else:
                    raise Exception("?", obj, " cannot be used for rights")

            else:
                match = True

            if match:
                return nodelist.render(context)
        return ''