Esempio n. 1
0
def upgrade():
    from sqlalchemy import Date, cast
    from datetime import date
    from autonomie.models.task.invoice import Payment
    from autonomie.models.base import DBSESSION as db

    for payment in db().query(Payment).filter(cast(Payment.created_at, Date) == date.today()):
        try:
            payment.remittance_amount = float(payment.remittance_amount) / 100000.0
            db().merge(payment)
        except:
            print(u"Erreur payment : %s (%s)" % (payment.id, payment.remittance_amount))

    from zope.sqlalchemy import mark_changed
    mark_changed(db())
Esempio n. 2
0
def upgrade():
    from sqlalchemy import Date, cast
    from datetime import date
    from autonomie.models.task.invoice import Payment
    from autonomie.models.base import DBSESSION as db

    for payment in db().query(Payment).filter(
            cast(Payment.created_at, Date) == date.today()):
        try:
            payment.amount = payment.amount / 1000
            db().merge(payment)
        except:
            print(u"Erreur payment : %s (%s)" % payment.id, payment.amount)

    from zope.sqlalchemy import mark_changed
    mark_changed(db())
Esempio n. 3
0
def refresh_cache(arguments, env):
    logger = logging.getLogger(__name__)
    if not arguments['refresh']:
        logger.exception(u"Unknown error")

    logger.debug(u"Refreshing cache")
    session = db()
    index = 0
    types = get_value(arguments, '--type')
    if types is None:
        types = ['invoice', 'estimation', 'cancelinvoice']

    this_year = datetime.date.today().year

    for task in Task.query().filter(Task.type_.in_(types)).filter(
            extract('year', Task.date) == this_year):
        try:
            cache_amounts(None, None, task)
            session.merge(task)
            index += 1
            if index % 200 == 0:
                logger.debug('flushing')
                session.flush()
        except:
            logger.exception(u"Error while caching total : {0}".format(
                task.id))
def upgrade():
    from autonomie.models.task import DiscountLine, TaskLine, Task, PaymentLine
    from autonomie.models.treasury import TurnoverProjection
    from autonomie.models.base import DBSESSION as db

    models = (
        (DiscountLine, ("amount",)),
        (TaskLine, ("cost",)),
        (Task, ("ht", "tva", "ttc", "expenses_ht", "expenses")),
        (PaymentLine, ("amount",)),
        (TurnoverProjection, ("value",)),
    )
    for model, keys in models:
        for key in keys:
            op.execute(u"Alter table {table} CHANGE {key} {key} BIGINT(20)".format(table=model.__tablename__, key=key))

    for model, keys in models:
        attrs = [getattr(model, "id")]
        attrs.extend([getattr(model, key) for key in keys])
        query = db().query(*attrs)
        if model == Task:
            query = query.filter(Task.type_.in_(("invoice", "estimation", "cancelinvoice")))
        for entry in query:
            id_ = entry[0]
            vals = entry[1:]
            f_keys = ["%s=%s" % (keys[index], 1000 * value) for index, value in enumerate(vals) if value is not None]
            key_query = ",".join(f_keys)
            if key_query.strip():
                query = "update {table} set {key_query} where id={id}".format(
                    table=model.__tablename__, key_query=key_query, id=id_
                )
                op.execute(query)
Esempio n. 5
0
def refresh_cache(arguments, env):
    logger = logging.getLogger(__name__)
    if not arguments['refresh']:
        logger.exception(u"Unknown error")

    logger.debug(u"Refreshing cache")
    session = db()
    index = 0
    types = get_value(arguments, '--type')
    if types is None:
        types = ['invoice', 'estimation', 'cancelinvoice']

    this_year = datetime.date.today().year

    for task in Task.query().filter(
        Task.type_.in_(types)
    ).filter(extract('year', Task.date) == this_year):
        try:
            cache_amounts(None, None, task)
            session.merge(task)
            index += 1
            if index % 200 == 0:
                logger.debug('flushing')
                session.flush()
        except:
            logger.exception(u"Error while caching total : {0}".format(task.id))
def upgrade():
    from autonomie.models.task import Payment
    from autonomie.models.base import DBSESSION as db

    table = Payment.__tablename__
    op.execute("Alter table {table} CHANGE amount amount BIGINT(20)".format(
        table=table))

    for entry in db().query(Payment.id, Payment.amount,
                            Payment.remittance_amount):
        id_, amount, remittance = entry
        query = "update {table} set amount={amount}, remittance_amount={remittance} where id={id}".format(
            table=table,
            amount=amount * 1000,
            remittance=format_remittance(remittance),
            id=id_,
        )
        op.execute(query)
        from zope.sqlalchemy import mark_changed
        mark_changed(db())
Esempio n. 7
0
def upgrade():
    from autonomie.models.task import Payment
    from autonomie.models.base import DBSESSION as db

    table = Payment.__tablename__
    op.execute(
        "Alter table {table} CHANGE amount amount BIGINT(20)".format(
            table=table
        )
    )

    for entry in db().query(Payment.id, Payment.amount, Payment.remittance_amount):
        id_, amount, remittance = entry
        query = "update {table} set amount={amount}, remittance_amount={remittance} where id={id}".format(
            table=table,
            amount=amount*1000,
            remittance=format_remittance(remittance),
            id=id_,
        )
        op.execute(query)
        from zope.sqlalchemy import mark_changed
        mark_changed(db())
def upgrade():
    from autonomie.models.task import (
        DiscountLine,
        TaskLine,
        Task,
        PaymentLine,
    )
    from autonomie.models.treasury import TurnoverProjection
    from autonomie.models.base import DBSESSION as db
    models = (
        (
            DiscountLine,
            ("amount", ),
        ),
        (
            TaskLine,
            ("cost", ),
        ),
        (
            Task,
            (
                'ht',
                'tva',
                'ttc',
                'expenses_ht',
                'expenses',
            ),
        ),
        (
            PaymentLine,
            ('amount', ),
        ),
        (
            TurnoverProjection,
            ('value', ),
        ),
    )
    for model, keys in models:
        for key in keys:
            op.execute(
                u"Alter table {table} CHANGE {key} {key} BIGINT(20)".format(
                    table=model.__tablename__, key=key))

    for model, keys in models:
        attrs = [getattr(model, 'id')]
        attrs.extend([getattr(model, key) for key in keys])
        query = db().query(*attrs)
        if model == Task:
            query = query.filter(
                Task.type_.in_(('invoice', 'estimation', 'cancelinvoice')))
        for entry in query:
            id_ = entry[0]
            vals = entry[1:]
            f_keys = [
                "%s=%s" % (keys[index], 1000 * value)
                for index, value in enumerate(vals) if value is not None
            ]
            key_query = ','.join(f_keys)
            if key_query.strip():
                query = "update {table} set {key_query} where id={id}".format(
                    table=model.__tablename__, key_query=key_query, id=id_)
                op.execute(query)