def upgrade():
    logger = logging.getLogger("alembic.add_compte_cg")
    op.add_column("tva", sa.Column("compte_cg", sa.String(125), default=""))
    op.add_column("tva", sa.Column("code", sa.String(125), default=""))
    op.add_column("company", sa.Column("contribution", sa.Integer))
    op.add_column("customer",
            sa.Column("compte_cg", sa.String(125), default=""))
    op.add_column("customer",
            sa.Column("compte_tiers", sa.String(125), default=""))

    # Ajout du code produit au ligne des factures et avoirs
    for table in ("invoice_line", "cancelinvoice_line"):
        op.add_column(table,
            sa.Column("product_id", sa.Integer, default=""))

    # Ajout d'un tag "exporte" aux factures et avoirs
    for table in ("invoice", "cancelinvoice"):
        op.add_column(table,
            sa.Column("exported",
                sa.Boolean()))
    # Les factures et avoirs deja validees sont considerees comme exportees
    logger.warn(u"On tag des factures comme exportees")
    for invoice in Invoice.query():
        if invoice.CAEStatus in Invoice.valid_states:
            invoice.exported = True
            DBSESSION().merge(invoice)
            logger.warn(u"officialNumber : {0.officialNumber} \
{0.financial_year}".format(invoice))

    for cinv in CancelInvoice.query():
        if cinv.CAEStatus in CancelInvoice.valid_states:
            cinv.exported = True
            DBSESSION().merge(cinv)
            logger.warn(u"officialNumber : {0.officialNumber} \
{0.financial_year}".format(cinv))
def upgrade():
    logger = logging.getLogger("alembic.add_compte_cg")
    op.add_column("tva", sa.Column("compte_cg", sa.String(125), default=""))
    op.add_column("tva", sa.Column("code", sa.String(125), default=""))
    op.add_column("company", sa.Column("contribution", sa.Integer))
    op.add_column("customer", sa.Column("compte_cg",
                                        sa.String(125),
                                        default=""))
    op.add_column("customer",
                  sa.Column("compte_tiers", sa.String(125), default=""))

    # Ajout du code produit au ligne des factures et avoirs
    for table in ("invoice_line", "cancelinvoice_line"):
        op.add_column(table, sa.Column("product_id", sa.Integer, default=""))

    # Ajout d'un tag "exporte" aux factures et avoirs
    for table in ("invoice", "cancelinvoice"):
        op.add_column(table, sa.Column("exported", sa.Boolean()))
    # Les factures et avoirs deja validees sont considerees comme exportees
    logger.warn(u"On tag des factures comme exportees")
    for invoice in Invoice.query():
        if invoice.CAEStatus in Invoice.valid_states:
            invoice.exported = True
            DBSESSION().merge(invoice)
            logger.warn(u"officialNumber : {0.officialNumber} \
{0.financial_year}".format(invoice))

    for cinv in CancelInvoice.query():
        if cinv.CAEStatus in CancelInvoice.valid_states:
            cinv.exported = True
            DBSESSION().merge(cinv)
            logger.warn(u"officialNumber : {0.officialNumber} \
{0.financial_year}".format(cinv))
Exemplo n.º 3
0
    def turnovers(self):
        """
            Return the realised turnovers
        """
        result = dict(year_total=0)
        for month in range(1, 13):

            invoices = Invoice.query().join(Task.project)
            invoices = invoices.filter(
                Project.company_id == self.request.context.id)
            date_condition = and_(
                extract('year', Invoice.taskDate) == self.year,
                extract('month', Invoice.taskDate) == month,
                Invoice.financial_year == self.year,
            )
            if month != 12:
                invoices = invoices.filter(date_condition)
            else:
                # for december, we also like to have invoices edited in january
                # and reported to the previous comptability year
                reported_condition = and_(
                    Invoice.financial_year == self.year,
                    extract('year', Invoice.taskDate) != self.year,
                )
                invoices = invoices.filter(
                    or_(date_condition, reported_condition))

            invoices = invoices.filter(
                Invoice.CAEStatus.in_(Invoice.valid_states))
            invoice_sum = sum([invoice.total_ht() for invoice in invoices])

            cinvoices = CancelInvoice.query().join(Task.project)
            cinvoices = cinvoices.filter(
                Project.company_id == self.request.context.id)
            date_condition = and_(
                extract('year', CancelInvoice.taskDate) == self.year,
                extract('month', CancelInvoice.taskDate) == month,
                CancelInvoice.financial_year == self.year,
            )
            if month != 12:
                cinvoices = cinvoices.filter(date_condition)
            else:
                reported_condition = and_(
                    CancelInvoice.financial_year == self.year,
                    extract('year', CancelInvoice.taskDate) != self.year,
                )
                cinvoices = cinvoices.filter(
                    or_(date_condition, reported_condition))

            cinvoices = cinvoices.filter(
                CancelInvoice.CAEStatus.in_(CancelInvoice.valid_states))
            cinvoice_sum = sum([cinvoice.total_ht() for cinvoice in cinvoices])

            result[month] = invoice_sum + cinvoice_sum
            result['year_total'] += result[month]
        return result
Exemplo n.º 4
0
    def turnovers(self):
        """
            Return the realised turnovers
        """
        result = dict(year_total=0)
        for month in range(1, 13):

            invoices = Invoice.query().join(Project)
            invoices = invoices.filter(
                Project.company_id==self.request.context.id
                )
            invoices = invoices.filter(
                extract('year', Invoice.taskDate)==self.year
                )
            invoices = invoices.filter(
                extract('month', Invoice.taskDate)==month
                )
            invoices = invoices.filter(
                Invoice.CAEStatus.in_(Invoice.valid_states)
                )
            invoice_sum = sum([invoice.total_ht() for invoice in invoices])

            cinvoices = CancelInvoice.query().join(Project)
            cinvoices = cinvoices.filter(
                    Project.company_id==self.request.context.id
                    )
            cinvoices = cinvoices.filter(
                    extract('year', CancelInvoice.taskDate)==self.year
                    )
            cinvoices = cinvoices.filter(
                    extract('month', CancelInvoice.taskDate)==month
                    )
            cinvoices = cinvoices.filter(
                    CancelInvoice.CAEStatus.in_(CancelInvoice.valid_states)
                    )
            cinvoice_sum = sum([cinvoice.total_ht() for cinvoice in cinvoices])

            result[month] = invoice_sum + cinvoice_sum
            result['year_total'] += result[month]
        return result
Exemplo n.º 5
0
    def turnovers(self):
        """
            Return the realised turnovers
        """
        result = dict(year_total=0)
        for month in range(1, 13):

            invoices = Invoice.query().join(Task.project)
            invoices = invoices.filter(
                Project.company_id==self.request.context.id
                )
            date_condition = and_(
                    extract('year', Invoice.taskDate)==self.year,
                    extract('month', Invoice.taskDate)==month,
                    Invoice.financial_year==self.year,
                    )
            if month != 12:
                invoices = invoices.filter(date_condition)
            else:
                # for december, we also like to have invoices edited in january
                # and reported to the previous comptability year
                reported_condition = and_(
                        Invoice.financial_year==self.year,
                        extract('year', Invoice.taskDate)!=self.year,
                    )
                invoices = invoices.filter(
                        or_(date_condition, reported_condition)
                    )

            invoices = invoices.filter(
                Invoice.CAEStatus.in_(Invoice.valid_states)
                )
            invoice_sum = sum([invoice.total_ht() for invoice in invoices])

            cinvoices = CancelInvoice.query().join(Task.project)
            cinvoices = cinvoices.filter(
                    Project.company_id==self.request.context.id
                    )
            date_condition = and_(
                    extract('year', CancelInvoice.taskDate)==self.year,
                    extract('month', CancelInvoice.taskDate)==month,
                    CancelInvoice.financial_year==self.year,
                    )
            if month != 12:
                cinvoices = cinvoices.filter(date_condition)
            else:
                reported_condition = and_(
                    CancelInvoice.financial_year==self.year,
                    extract('year', CancelInvoice.taskDate)!=self.year,
                    )
                cinvoices = cinvoices.filter(
                        or_(date_condition, reported_condition)
                        )

            cinvoices = cinvoices.filter(
                    CancelInvoice.CAEStatus.in_(CancelInvoice.valid_states)
                    )
            cinvoice_sum = sum([cinvoice.total_ht() for cinvoice in cinvoices])

            result[month] = invoice_sum + cinvoice_sum
            result['year_total'] += result[month]
        return result