Example #1
0
    def gen_cancelinvoice(self, user):
        """
            Return a cancel invoice with self's informations
        """
        cancelinvoice = CancelInvoice(
            user=user,
            company=self.company,
            project=self.project,
            customer=self.customer,
            phase_id=self.phase_id,
            address=self.address,
            workplace=self.workplace,
            description=self.description,
            invoice=self,
            expenses_ht=-1 * self.expenses_ht,
            financial_year=self.financial_year,
            display_units=self.display_units,
            business_type_id=self.business_type_id,
            business_id=self.business_id,
        )

        cancelinvoice.line_groups = []
        for group in self.line_groups:
            cancelinvoice.line_groups.append(
                group.gen_cancelinvoice_group()
            )
        order = self.get_next_row_index()

        for discount in self.discounts:
            discount_line = TaskLine(
                cost=discount.amount,
                tva=discount.tva,
                quantity=1,
                description=discount.description,
                order=order,
                unity='',
            )
            discount_line.product_id = Product.first_by_tva_value(discount.tva)
            order += 1
            cancelinvoice.default_line_group.lines.append(discount_line)

        for index, payment in enumerate(self.payments):
            paid_line = TaskLine(
                cost=math_utils.reverse_tva(
                    payment.amount,
                    payment.tva.value,
                    False,
                ),
                tva=payment.tva.value,
                quantity=1,
                description=u"Paiement {0}".format(index + 1),
                order=order,
                unity='NONE',
            )
            paid_line.product_id = Product.first_by_tva_value(payment.tva.value)
            order += 1
            cancelinvoice.default_line_group.lines.append(paid_line)
        cancelinvoice.mentions = self.mentions
        cancelinvoice.payment_conditions = u"Réglé"
        return cancelinvoice
Example #2
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"))
Example #3
0
    def gen_cancelinvoice(self, user):
        """
            Return a cancel invoice with self's informations
        """
        cancelinvoice = CancelInvoice(
            user=user,
            company=self.company,
            project=self.project,
            customer=self.customer,
            phase_id=self.phase_id,
            address=self.address,
            workplace=self.workplace,
            description=self.description,
            invoice=self,
            expenses_ht=-1 * self.expenses_ht,
            financial_year=self.financial_year,
            display_units=self.display_units,
            business_type_id=self.business_type_id,
            business_id=self.business_id,
        )

        cancelinvoice.line_groups = []
        for group in self.line_groups:
            cancelinvoice.line_groups.append(
                group.gen_cancelinvoice_group()
            )
        order = self.get_next_row_index()

        for discount in self.discounts:
            discount_line = TaskLine(
                cost=discount.amount,
                tva=discount.tva,
                quantity=1,
                description=discount.description,
                order=order,
                unity='',
            )
            discount_line.product_id = Product.first_by_tva_value(discount.tva)
            order += 1
            cancelinvoice.default_line_group.lines.append(discount_line)

        for index, payment in enumerate(self.payments):
            paid_line = TaskLine(
                cost=math_utils.reverse_tva(
                    payment.amount,
                    payment.tva.value,
                    False,
                ),
                tva=payment.tva.value,
                quantity=1,
                description=u"Paiement {0}".format(index + 1),
                order=order,
                unity='NONE',
            )
            paid_line.product_id = Product.first_by_tva_value(payment.tva.value)
            order += 1
            cancelinvoice.default_line_group.lines.append(paid_line)
        cancelinvoice.mentions = self.mentions
        cancelinvoice.payment_conditions = u"Réglé"
        return cancelinvoice
Example #4
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"))
Example #5
0
def get_product_choices():
    """
        Return data structure for product code select widget options
    """
    return [(p.id, u"{0} ({1} - {2})".format(
        p.name, p.compte_cg, p.tva.name),)
            for p in Product.query()]
Example #6
0
 def _account_invoiceline(self, amount, description, tva=1960):
     """
         Return an account invoiceline
     """
     line = TaskLine(cost=amount, description=description, tva=tva)
     line.product_id = Product.first_by_tva_value(tva)
     return line
Example #7
0
def get_product_choices():
    """
        Return data structure for product code select widget options
    """
    return [(
        p.id,
        u"{0} ({1} - {2})".format(p.name, p.compte_cg, p.tva.name),
    ) for p in Product.query()]
Example #8
0
 def _get_task_line(cls, cost, description, tva):
     from autonomie.models.task.task import TaskLine
     from autonomie.models.tva import Product
     line = TaskLine(cost=cost,
                     description=description,
                     tva=tva,
                     quantity=1)
     line.product_id = Product.first_by_tva_value(tva)
     return line
Example #9
0
def product_match_tva_validator(form, line_value):
    product_id = line_value.get('product_id')
    product = Product.get(product_id)
    if product.tva.value != line_value['tva']:
        exc = colander.Invalid(
            form,
            u"Le code produit doit correspondre à la TVA associée",
        )
        raise exc
Example #10
0
def json_products(request):
    """
    Return the product objects available for this form

    :param obj request: The current request object
    :returns: List of Product objects in their json repr
    """
    query = Product.query()
    return [item.__json__(request) for item in query]
Example #11
0
def product_match_tva_validator(form, line_value):
    product_id = line_value.get('product_id')
    product = Product.get(product_id)
    if product.tva.value != line_value['tva']:
        exc = colander.Invalid(
            form,
            u"Le code produit doit correspondre à la TVA associée",
        )
        raise exc
Example #12
0
def json_products(request):
    """
    Return the product objects available for this form

    :param obj request: The current request object
    :returns: List of Product objects in their json repr
    """
    query = Product.query()
    return [item.__json__(request) for item in query]
Example #13
0
    def post_format(self, entry, edit, attributes):
        """
        Associate a newly created element to the parent group
        """
        if not edit:
            entry.group = self.context

        if 'tva' in attributes and 'product_id' not in attributes and \
                entry.tva is not None:
            entry.product_id = Product.first_by_tva_value(entry.tva)
        return entry
Example #14
0
    def post_format(self, entry, edit, attributes):
        """
        Associate a newly created element to the parent group
        """
        if not edit:
            entry.group = self.context

        if 'tva' in attributes and 'product_id' not in attributes and \
                entry.tva is not None:
            entry.product_id = Product.first_by_tva_value(entry.tva)
        return entry
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(),
        products=Product.query().all(),
        training_type=TrainingTypeOptions.query().all(),
    )
Example #16
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(),
        products=Product.query().all(),
        training_type=TrainingTypeOptions.query().all(),
    )
Example #17
0
 def _get_task_line(cls, cost, description, tva):
     from autonomie.models.task.task import TaskLine
     from autonomie.models.tva import Product
     line = TaskLine(cost=cost, description=description, tva=tva, quantity=1)
     line.product_id = Product.first_by_tva_value(tva)
     return line
Example #18
0
def product_without_tva(dbsession):
    from autonomie.models.tva import Product
    product = Product(name='product', compte_cg='122')
    dbsession.add(product)
    dbsession.flush()
    return product
Example #19
0
 def factory(name, tva, compte_cg='122'):
     product = Product(name=name, tva_id=tva.id, compte_cg=compte_cg)
     dbsession.add(product)
     dbsession.flush()
     return product
Example #20
0
def product(tva, dbsession):
    from autonomie.models.tva import Product
    product = Product(name='product', compte_cg='122', tva_id=tva.id)
    dbsession.add(product)
    dbsession.flush()
    return product