示例#1
0
    def submit_success(self, appstruct):
        """
            fired on submit success, set Tvas
        """
        # First we disable the elements that are no longer part of the
        # configuration
        self.disable_elements(Product, self.get_remaining_prod_ids(appstruct))
        self.disable_elements(Tva, self.get_remaining_tva_ids(appstruct))
        self.dbsession.flush()

        for data in appstruct['tvas']:
            products = data.pop('products')
            if 'id' in data:
                tva = Tva.get(data['id'])
                merge_session_with_post(tva, data)
                tva = self.dbsession.merge(tva)
            else:
                tva = Tva()
                merge_session_with_post(tva, data)
                self.dbsession.add(tva)

            for prod in products:
                if 'id' in prod:
                    product = Product.get(prod['id'])
                    product.tva = tva
                    merge_session_with_post(product, prod)
                    self.dbsession.merge(product)
                else:
                    product = Product()
                    merge_session_with_post(product, prod)
                    product.tva = tva
                    self.dbsession.add(product)
        self.request.session.flash(self.validation_msg)
        return HTTPFound(self.request.route_path("admin_tva"))
示例#2
0
    def __call__(self):
        menus = [dict(label=u"Retour", route_name="admin_vente",
                      icon="fa fa-step-backward")]
        columns = [
            u"Libellé", u"Valeur", u"Compte CG de TVA", u"Défaut ?"
        ]

        items = Tva.query(include_inactive=True).all()

        warn_msg = None
        if items:
            if Tva.get_default() is None:
                warn_msg = (u"Aucun taux de TVA par défaut n'a été configuré."
                            u"Des problèmes peuvent être rencontré lors de "
                            u"l'édition de devis/factures")

        return dict(
            items=items,
            warn_msg=warn_msg,
            columns=columns,
            stream_columns=self.stream_columns,
            stream_actions=self.stream_actions,
            title=self.title,
            menus=menus,
            addurl=self.request.route_path(
                '/admin/vente/tvas',
                _query=dict(action="new")
            ),
        )
示例#3
0
文件: tva.py 项目: tonthon/autonomie
 def __call__(self):
     for tva in Tva.query(include_inactive=True):
         tva.default = False
         self.request.dbsession.merge(tva)
     self.context.default = True
     self.request.dbsession.merge(tva)
     return HTTPFound(TVA_URL)
示例#4
0
def has_tva_default_validator(node, value):
    """
    Validator for tva uniqueness
    """
    from autonomie.models.tva import Tva
    if Tva.get_default() is None and not value:
        raise colander.Invalid(node, TVA_NO_DEFAULT_SET_MSG)
示例#5
0
    def submit_success(self, appstruct):
        if 'amount' in appstruct:
            appstruct['tva_id'] = Tva.by_value(
                self.context.get_tvas().keys()[0]
            ).id
            self.context.record_payment(
                user_id=self.request.user.id,
                **appstruct
            )
        elif 'tvas' in appstruct:
            appstruct.pop('payment_amount')
            # si on a plusieurs tva :
            for tva_payment in appstruct['tvas']:
                bank_remittance_id = appstruct['bank_remittance_id']
                tva_payment['bank_remittance_id'] = bank_remittance_id
                tva_payment['date'] = appstruct['date']
                tva_payment['mode'] = appstruct['mode']
                tva_payment['bank_id'] = appstruct.get('bank_id')
                tva_payment['resulted'] = appstruct.get('resulted', False)
                self.context.record_payment(
                    user_id=self.request.user.id,
                    **tva_payment
                )

        self.request.dbsession.merge(self.context)
        self.notify()
        return self.redirect()
示例#6
0
def has_tva_default_validator(node, value):
    """
    Validator for tva uniqueness
    """
    from autonomie.models.tva import Tva
    if Tva.get_default() is None and not value:
        raise colander.Invalid(node, TVA_NO_DEFAULT_SET_MSG)
示例#7
0
    def submit_success(self, appstruct):
        """
            fired on submit success, set Tvas
        """
        # First we disable the elements that are no longer part of the
        # configuration
        self.disable_elements(Product, self.get_remaining_prod_ids(appstruct))
        self.disable_elements(Tva, self.get_remaining_tva_ids(appstruct))
        self.dbsession.flush()

        for data in appstruct['tvas']:
            products = data.pop('products')
            if 'id' in data:
                tva = Tva.get(data['id'])
                merge_session_with_post(tva, data)
                tva = self.dbsession.merge(tva)
            else:
                tva = Tva()
                merge_session_with_post(tva, data)
                self.dbsession.add(tva)

            for prod in products:
                if 'id' in prod:
                    product = Product.get(prod['id'])
                    product.tva = tva
                    merge_session_with_post(product, prod)
                    self.dbsession.merge(product)
                else:
                    product = Product()
                    merge_session_with_post(product, prod)
                    product.tva = tva
                    self.dbsession.add(product)
        self.request.session.flash(self.validation_msg)
        return HTTPFound(self.request.route_path("admin_tva"))
示例#8
0
 def __call__(self):
     for tva in Tva.query(include_inactive=True):
         tva.default = False
         self.request.dbsession.merge(tva)
     self.context.default = True
     self.request.dbsession.merge(tva)
     return HTTPFound(self.request.route_path('/admin/vente/tvas'))
示例#9
0
    def pre_paid_process(self, task, status, params):
        """
            Validate a payment form's data
        """
        form = get_paid_form(self.request)
        # We don't try except on the data validation, since this is done in the
        # original wrapping call (see taskaction set_status)
        appstruct = form.validate(params.items())

        if 'amount' in appstruct:
            # Les lignes de facture ne conservent pas le lien avec les objets
            # Tva, ici on en a une seule, on récupère l'objet et on le set sur
            # le amount
            appstruct['tva_id'] = Tva.by_value(
                self.context.get_tvas().keys()[0]
            ).id

        elif 'tvas' in appstruct:
            # Ce champ ne servait que pour tester las somme des valeurs saisies
            appstruct.pop('payment_amount')
            # si on a plusieurs tva :
            for tva_payment in appstruct['tvas']:
                remittance_amount = appstruct['remittance_amount']
                tva_payment['remittance_amount'] = remittance_amount
                tva_payment['date'] = appstruct['date']
                tva_payment['mode'] = appstruct['mode']
                tva_payment['bank_id'] = appstruct.get('bank_id')
                tva_payment['resulted'] = appstruct.get('resulted', False)
        else:
            raise Exception(u"On a rien à faire ici")

        logger.debug(u"In pre paid process")
        logger.debug(u"Returning : {0}".format(appstruct))
        return appstruct
示例#10
0
    def pre_paid_process(self, task, status, params):
        """
            Validate a payment form's data
        """
        form = get_paid_form(self.request)
        # We don't try except on the data validation, since this is done in the
        # original wrapping call (see taskaction set_status)
        appstruct = form.validate(params.items())

        if 'amount' in appstruct:
            # Les lignes de facture ne conservent pas le lien avec les objets
            # Tva, ici on en a une seule, on récupère l'objet et on le set sur
            # le amount
            appstruct['tva_id'] = Tva.by_value(
                self.context.get_tvas().keys()[0]
            ).id

        elif 'tvas' in appstruct:
            # Ce champ ne servait que pour tester las somme des valeurs saisies
            appstruct.pop('payment_amount')
            # si on a plusieurs tva :
            for tva_payment in appstruct['tvas']:
                remittance_amount = appstruct['remittance_amount']
                tva_payment['remittance_amount'] = remittance_amount
                tva_payment['date'] = appstruct['date']
                tva_payment['mode'] = appstruct['mode']
                tva_payment['bank_id'] = appstruct.get('bank_id')
                tva_payment['resulted'] = appstruct.get('resulted', False)
        else:
            raise Exception(u"On a rien à faire ici")

        logger.debug(u"In pre paid process")
        logger.debug(u"Returning : {0}".format(appstruct))
        return appstruct
示例#11
0
    def before(self, form):
        BaseFormView.before(self, form)
        self.request.actionmenu.add(
            ViewLink(
                label=u"Revenir à la facture",
                path="/invoices/{id}.html",
                id=self.context.id,
                _anchor="payment",
            )
        )

        appstruct = []
        for tva_value, value in self.context.topay_by_tvas().items():
            tva = Tva.by_value(tva_value)
            appstruct.append(
                {
                    'tva_id': tva.id,
                    'amount': floor_to_precision(
                        value,
                        precision=2,
                        dialect_precision=5
                    )
                }
            )

        if len(appstruct) == 1:
            form.set_appstruct(appstruct[0])
        else:
            form.set_appstruct({'tvas': appstruct})
示例#12
0
def task_options_json(request):
    """
        Returns the task form options as a dict
    """
    options = dict()
    options['tvas'] = dict(
        (tva.value, tva.__json__(request)) for tva in Tva.query().all())
    return options
示例#13
0
def company_products_options_ajax_view(context, request):
    """
    The view for company products options load

    :param obj context: The context : The company object
    :param obj request: the Pyramid's request object
    """
    return dict(tvas=Tva.query().all(), unities=WorkUnit.query().all())
示例#14
0
def task_options_json(request):
    """
        Returns the task form options as a dict
    """
    options = dict()
    options['tvas'] = dict((tva.value, tva.__json__(request)) \
            for tva in Tva.query().all())
    return options
示例#15
0
    def _populate_expenses(self):
        """
            Add the expenses to our object
        """
        if self.invoice.expenses > 0 or self.invoice.expenses_ht > 0:
            if self.expense_tva_compte_cg is None:
                self.expense_tva_compte_cg = Tva.get_default().compte_cg
                self.expense_tva_code = Tva.get_default().code

            prod = self.get_product(
                        self.compte_cgs["compte_frais_annexes"],
                        self.expense_tva_compte_cg,
                        self.expense_tva_code
                        )
            ht_expense = self.invoice.get_expense_ht()
            ttc_expense = self.invoice.expenses_amount()
            prod['tva'] = ht_expense.tva_amount()
            prod['ht'] = ttc_expense + ht_expense.total_ht()
示例#16
0
def get_default_tva():
    """
        Return the default tva
    """
    default_tva = Tva.get_default()
    if default_tva:
        return default_tva.value
    else:
        return 1960
示例#17
0
def json_tvas(request):
    """
    Return the tva objects available for this form

    :param obj request: The current request object
    :returns: List of Tva objects in their json repr
    """
    query = Tva.query()
    return [item.__json__(request) for item in query]
示例#18
0
def deferred_default_tva(node, kw):
    """
        return a tva widget
    """
    default_tva = Tva.get_default()
    if default_tva is not None:
        return unicode(default_tva.value)
    else:
        return colander.null
示例#19
0
def json_tvas(request):
    """
    Return the tva objects available for this form

    :param obj request: The current request object
    :returns: List of Tva objects in their json repr
    """
    query = Tva.query()
    return [item.__json__(request) for item in query]
示例#20
0
def deferred_default_tva(node, kw):
    """
        return a tva widget
    """
    default_tva = Tva.get_default()
    if default_tva is not None:
        return unicode(default_tva.value)
    else:
        return colander.null
示例#21
0
    def validate_amount_by_tva(values):
        tva_id = values.get('tva_id')
        tva = Tva.get(tva_id)
        if tva is None:
            return u"Tva inconnue"
        amount = values.get('amount')
        if amount > tva_parts[tva.value]:
            return u"Le montant de l'encaissement doit être inférieur à la \
part de cette Tva dans la facture"
        return True
示例#22
0
文件: tva.py 项目: tonthon/autonomie
 def more_template_vars(self, result):
     result['nodata_msg'] = u"Aucun taux de TVA n'a été configuré"
     if result['items']:
         if Tva.get_default() is None:
             result['warn_msg'] = (
                 u"Aucun taux de TVA par défaut n'a été configuré. "
                 u"Des problèmes peuvent être rencontrés lors de "
                 u"l'édition de devis/factures."
             )
     return result
示例#23
0
    def validate_amount_by_tva(values):
        tva_id = values.get('tva_id')
        tva = Tva.get(tva_id)
        if tva is None:
            return u"Tva inconnue"
        amount = values.get('amount')
        if amount > tva_parts[tva.value]:
            return u"Le montant de l'encaissement doit être inférieur à la \
part de cette Tva dans la facture"

        return True
示例#24
0
def company_products_options_ajax_view(context, request):
    """
    The view for company products options load

    :param obj context: The context : The company object
    :param obj request: the Pyramid's request object
    """
    return dict(
        tvas=Tva.query().all(),
        unities=WorkUnit.query().all()
    )
示例#25
0
    def validate_amount_by_tva(values):
        tva_id = values.get('tva_id')
        tva = Tva.get(tva_id)
        if tva is None:
            return u"Tva inconnue"
        amount = values.get('amount')
        # Fix #433 : encaissement et tva multiples
        # Add a tolerance for 5 € of difference
        if amount > tva_parts[tva.value] + PAYMENT_EPSILON:
            return u"Le montant de l'encaissement doit être inférieur à la \
part de cette Tva dans la facture"
        return True
示例#26
0
    def _paid_form(self):
        """
            return the form for payment registration
        """
        form = get_paid_form(self.request, self.formcounter)
        appstruct = []
        for tva_value, value in self.context.topay_by_tvas().items():
            tva = Tva.by_value(tva_value)
            appstruct.append({'tva_id': tva.id, 'amount': value})
            form.set_appstruct({'tvas': appstruct})

        self.formcounter = form.counter
        return form
示例#27
0
def get_default_tva():
    """
        Return the default tva
    """
    try:
        default_tva = Tva.get_default()
    except:
        default_tva = None

    if default_tva:
        return default_tva.value
    else:
        return 1960
示例#28
0
    def _paid_form(self):
        """
            return the form for payment registration
        """
        form = get_paid_form(self.request, self.formcounter)
        appstruct = []
        for tva_value, value in self.context.topay_by_tvas().items():
            tva = Tva.by_value(tva_value)
            appstruct.append({'tva_id': tva.id, 'amount': value})
            form.set_appstruct({'tvas': appstruct})

        self.formcounter = form.counter
        return form
示例#29
0
def tva_product_validator(node, value):
    product_id = value.get('product_id')
    if product_id is not None:
        tva_id = value.get('tva_id')
        if tva_id is not None:
            tva = Tva.get(tva_id)
            if product_id not in [p.id for p in tva.products]:
                exc = colander.Invalid(
                    node, u"Ce produit ne correspond pas à la TVA configurée")
                exc['product_id'] = u"Le code produit doit correspondre à la \
                    TVA configurée pour cette prestation"

                raise exc
示例#30
0
def get_default_tva():
    """
        Return the default tva
    """
    try:
        default_tva = Tva.get_default()
    except:
        default_tva = None

    if default_tva:
        return default_tva.value
    else:
        return 1960
示例#31
0
    def validate_amount_by_tva(values):
        tva_id = values.get('tva_id')
        tva = Tva.get(tva_id)
        if tva is None:
            return u"Tva inconnue"
        amount = values.get('amount')
        # Fix #433 : encaissement et tva multiples
        # Add a tolerance for 5 € of difference
        if amount > tva_parts[tva.value] + PAYMENT_EPSILON:
            return u"Le montant de l'encaissement doit être inférieur à la \
part de cette Tva dans la facture"

        return True
示例#32
0
    def get_tva_objects(cls, task_obj):
        """
        :param task_obj: The Task object we want to collect tvas for
        :returns: tva stored by amount
        :rtype: dict
        """
        tva_values = set()
        for group in task_obj.line_groups:
            for line in group.lines:
                tva_values.add(line.tva)

        tvas = Tva.query().filter(Tva.value.in_(list(tva_values))).all()
        return dict([(tva.value, tva) for tva in tvas])
示例#33
0
    def before(self, form):
        """
            Add appstruct to the current form object
        """
        appstruct = []
        for tva in Tva.query().all():
            struct = tva.appstruct()
            struct['products'] = [product.appstruct()
                    for product in tva.products]
            appstruct.append(struct)

        form.set_appstruct({'tvas':appstruct})
        populate_actionmenu(self.request)
        log.debug("AdminTva struct: %s", appstruct)
示例#34
0
    def before(self, form):
        """
            Add appstruct to the current form object
        """
        appstruct = []
        for tva in Tva.query().all():
            struct = tva.appstruct()
            struct['products'] = [
                product.appstruct() for product in tva.products
            ]
            appstruct.append(struct)

        form.set_appstruct({'tvas': appstruct})
        populate_actionmenu(self.request)
        log.debug("AdminTva struct: %s", appstruct)
示例#35
0
    def get_tva_objects(cls, task_obj):
        """
        :param task_obj: The Task object we want to collect tvas for
        :returns: tva stored by amount
        :rtype: dict
        """
        tva_values = set()
        for group in task_obj.line_groups:
            for line in group.lines:
                tva_values.add(line.tva)

        tvas = Tva.query().filter(
            Tva.value.in_(list(tva_values))
        ).all()
        return dict([(tva.value, tva) for tva in tvas])
示例#36
0
def tva_product_validator(node, value):
    """
    Validator checking that tva and product_id matches
    """
    product_id = value.get('product_id')
    if product_id is not None:
        tva_id = value.get('tva_id')
        if tva_id is not None:
            tva = Tva.get(tva_id)
            if product_id not in [p.id for p in tva.products]:
                exc = colander.Invalid(
                    node,
                    u"Ce produit ne correspond pas à la TVA configurée"
                )
                exc['product_id'] = u"Le code produit doit correspondre à la \
                    TVA configurée pour cette prestation"
                raise exc
示例#37
0
def deferred_tva_id_validator(node, kw):
    ctx = kw['request'].context
    if isinstance(ctx, Payment):
        invoice = ctx.parent
    else:
        invoice = ctx
    values = []
    for tva_value in invoice.topay_by_tvas().keys():
        values.append(Tva.by_value(tva_value))

    def validator(node, value):
        if value not in [v.id for v in values]:
            raise colander.Invalid(
                node,
                u"Ce taux de tva n'est pas utilisé dans la facture",
            )

    return validator
示例#38
0
def deferred_tva_id_validator(node, kw):
    ctx = kw['request'].context
    if isinstance(ctx, Payment):
        invoice = ctx.parent
    else:
        invoice = ctx
    values = []
    for tva_value in invoice.topay_by_tvas().keys():
        values.append(Tva.by_value(tva_value))

    def validator(node, value):
        if value not in [v.id for v in values]:
            raise colander.Invalid(
                node,
                u"Ce taux de tva n'est pas utilisé dans la facture",
            )

    return validator
示例#39
0
    def submit_success(self, appstruct):
        if 'amount' in appstruct:
            appstruct['tva_id'] = Tva.by_value(
                self.context.get_tvas().keys()[0]).id
            self.context.record_payment(user_id=self.request.user.id,
                                        **appstruct)
        elif 'tvas' in appstruct:
            appstruct.pop('payment_amount')
            # si on a plusieurs tva :
            for tva_payment in appstruct['tvas']:
                bank_remittance_id = appstruct['bank_remittance_id']
                tva_payment['bank_remittance_id'] = bank_remittance_id
                tva_payment['date'] = appstruct['date']
                tva_payment['mode'] = appstruct['mode']
                tva_payment['bank_id'] = appstruct.get('bank_id')
                tva_payment['resulted'] = appstruct.get('resulted', False)
                self.context.record_payment(user_id=self.request.user.id,
                                            **tva_payment)

        self.request.dbsession.merge(self.context)
        self.notify()
        return self.redirect()
示例#40
0
    def before(self, form):
        BaseFormView.before(self, form)
        self.request.actionmenu.add(
            ViewLink(
                label=u"Revenir à la facture",
                path="/invoices/{id}.html",
                id=self.context.id,
                _anchor="payment",
            ))

        appstruct = []
        for tva_value, value in self.context.topay_by_tvas().items():
            tva = Tva.by_value(tva_value)
            appstruct.append({
                'tva_id':
                tva.id,
                'amount':
                floor_to_precision(value, precision=2, dialect_precision=5)
            })

        if len(appstruct) == 1:
            form.set_appstruct(appstruct[0])
        else:
            form.set_appstruct({'tvas': appstruct})
示例#41
0
文件: sage.py 项目: Orelab/autonomie
 def __init__(self, invoice, config=None, default_tva=None):
     self.products = {}
     self.invoice = invoice
     self.config = config or {}
     self.default_tva = default_tva or Tva.get_default()
示例#42
0
def tva(dbsession):
    tva = Tva(name='TVA 20%', value=2000, default=1)
    dbsession.add(tva)
    dbsession.flush()
    return tva
示例#43
0
 def get_tva(self):
     return Tva.query(include_inactive=True).filter(Tva.value == self.tva)
示例#44
0
 def __init__(self, invoice, config=None, default_tva=None):
     self.products = {}
     self.invoice = invoice
     self.config = config or {}
     self.default_tva = default_tva or Tva.get_default()
     self.tvas = self.invoice.get_tvas_by_product()
示例#45
0
 def validator(node, value):
     if not Tva.unique_value(value, current_id):
         raise colander.Invalid(node, TVA_UNIQUE_VALUE_MSG)
示例#46
0
def add_tva(value, default=False):
    t = Tva(name="%s %%" % (value/100.0), value=value, default=default)
    session = DBSESSION()
    session.add(t)
    session.flush()
示例#47
0
 def tvas(self):
     return Tva.query().all()
示例#48
0
 def tvas(self):
     return Tva.query().all()
示例#49
0
def tva(dbsession):
    from autonomie.models.tva import Tva
    tva = Tva(value=2000, name='20%', default=True)
    dbsession.add(tva)
    dbsession.flush()
    return tva
示例#50
0
文件: tva.py 项目: tonthon/autonomie
 def load_items(self):
     return Tva.query(include_inactive=True).all()
示例#51
0
def get_tva_choices():
    """
        Return data structure for tva select widget options
    """
    return [(unicode(tva.value), tva.name)for tva in Tva.query()]
示例#52
0
 def validator(node, value):
     if not Tva.unique_value(value, current_id):
         raise colander.Invalid(node, TVA_UNIQUE_VALUE_MSG)
示例#53
0
 def factory(value, name, default=True):
     tva = Tva(value=value, name=name, default=default)
     dbsession.add(tva)
     dbsession.flush()
     return tva