Esempio n. 1
0
    def get_sale_base_subtotal(self):
        """Get the base subtotal of items

        Just a helper that, unlike :meth:`.get_sale_subtotal`, will
        return the total based on item's base price.

        :returns: the base subtotal
        """
        subtotal = self.get_items().sum(
            Round(LoanItem.quantity * LoanItem.base_price, DECIMAL_PRECISION))
        return currency(subtotal)
Esempio n. 2
0
    def get_total_amount(self):
        """
        Fetches the total value of the loan, that is to be paid by
        the client.

        It can be calculated as::

            Sale total = Sum(product and service prices) + surcharge +
                             interest - discount

        :returns: the total value
        """
        return currency(self.get_items().sum(
            Round(LoanItem.price * LoanItem.quantity, DECIMAL_PRECISION)) or 0)
Esempio n. 3
0
"""Views related to Daily Movement Reports"""

from storm.expr import Join, LeftJoin, Sum, Alias, Select, Coalesce
from storm.info import ClassAlias

from stoqlib.database.expr import Field, NullIf, Round
from stoqlib.domain.payment.views import InPaymentView, OutPaymentView
from stoqlib.domain.person import Branch, Client, Company, Person, SalesPerson
from stoqlib.domain.sale import Sale, SaleItem, InvoiceItemIpi
from stoqlib.lib.defaults import DECIMAL_PRECISION

_SaleItemSummary = Select(columns=[
    SaleItem.sale_id,
    Alias(
        Sum(
            Round(SaleItem.quantity * SaleItem.price + InvoiceItemIpi.v_ipi,
                  DECIMAL_PRECISION)), 'subtotal')
],
                          tables=[
                              SaleItem,
                              LeftJoin(
                                  InvoiceItemIpi,
                                  SaleItem.ipi_info_id == InvoiceItemIpi.id)
                          ],
                          group_by=[SaleItem.sale_id])

SaleItemSummary = Alias(_SaleItemSummary, '_sale_items')


class DailyInPaymentView(InPaymentView):

    SalesPersonPerson = ClassAlias(Person, 'salesperson_person')