コード例 #1
0
def add_lines_to_estimation(task, appstruct):
    """
        Add the lines to the current estimation
    """
    task.default_line_group.lines = []
    task.line_groups = [task.default_line_group]
    task.discounts = []
    task.payment_lines = []

    for line in appstruct['payment_lines']:
        task.payment_lines.append(PaymentLine(**line))

    for group in appstruct['groups']:
        lines = group.pop('lines', [])
        group = TaskLineGroup(**group)
        for line in lines:
            group.lines.append(TaskLine(**line))
        task.line_groups.append(group)

    for line in appstruct['lines']:
        task.default_line_group.lines.append(TaskLine(**line))

    for line in appstruct.get('discounts', []):
        task.discounts.append(DiscountLine(**line))

    return task
def upgrade():
    from autonomie.models.task import (
        TaskLine,
        TaskLineGroup,
        Task,
        Estimation,
        CancelInvoice,
        Invoice,
    )
    from autonomie_base.models.base import (
        DBSESSION,
    )

    session = DBSESSION()

    index = 0
    query = Task.query()
    query = query.with_polymorphic([Invoice, CancelInvoice, Estimation])
    query = query.filter(
        Task.type_.in_(['invoice', 'estimation', 'cancelinvoice'])
    )
    for task in query:
        group = TaskLineGroup(task_id=task.id, order=0)

        for line in task.lines:

            tline = TaskLine(
                group=group,
                order=line.rowIndex,
                description=line.description,
                cost=line.cost,
                tva=line.tva,
                quantity=line.quantity,
            )

            if hasattr(line, 'product_id'):
                tline.product_id = line.product_id
            session.add(tline)

            if index % 100 == 0:
                session.flush()

    op.alter_column(
        table_name='estimation_payment',
        column_name='rowIndex',
        new_column_name='order',
        type_=sa.Integer,
    )
コード例 #3
0
def upgrade():
    from autonomie.models.task import (
        TaskLine,
        TaskLineGroup,
        Task,
        Estimation,
        CancelInvoice,
        Invoice,
    )
    from autonomie.models.base import (
        DBSESSION,
    )

    session = DBSESSION()

    index = 0
    query = Task.query()
    query = query.with_polymorphic([Invoice, CancelInvoice, Estimation])
    query = query.filter(
        Task.type_.in_(['invoice', 'estimation', 'cancelinvoice'])
    )
    for task in query:
        group = TaskLineGroup(task_id=task.id, order=0)

        for line in task.lines:

            tline = TaskLine(
                group=group,
                order=line.rowIndex,
                description=line.description,
                cost=line.cost,
                tva=line.tva,
                quantity=line.quantity,
            )

            if hasattr(line, 'product_id'):
                tline.product_id = line.product_id
            session.add(tline)

            if index % 100 == 0:
                session.flush()

    op.alter_column(
        table_name='estimation_payment',
        column_name='rowIndex',
        new_column_name='order',
        type_=sa.Integer,
    )
コード例 #4
0
def add_lines_to_cancelinvoice(task, appstruct):
    """
        Add the lines to the current cancelinvoice
    """
    task.default_line_group.lines = []
    task.line_groups = [task.default_line_group]
    for group in appstruct['groups']:
        lines = group.pop('lines', [])
        group = TaskLineGroup(**group)
        for line in lines:
            group.lines.append(TaskLine(**line))
        task.line_groups.append(group)

    for line in appstruct['lines']:
        task.default_line_group.lines.append(TaskLine(**line))
    return task
コード例 #5
0
def invoice(project, user, customer, company, phase):
    invoice = Invoice(
        company,
        customer,
        project,
        phase,
        user,
    )
    invoice.line_groups = [TaskLineGroup(lines=[TaskLine(**LINE)])]
    for i in PAYMENTS:
        invoice.payments.append(Payment(**i))
    return invoice
コード例 #6
0
def add_lines_to_invoice(task, appstruct):
    """
        Add the lines to the current invoice
    """
    # Needed for edition only
    task.default_line_group.lines = []
    task.line_groups = [task.default_line_group]
    task.discounts = []

    for group in appstruct['groups']:
        lines = group.pop('lines', [])
        group = TaskLineGroup(**group)
        for line in lines:
            group.lines.append(TaskLine(**line))
        task.line_groups.append(group)
    for line in appstruct['lines']:
        task.default_line_group.lines.append(TaskLine(**line))

    for line in appstruct.get('discounts', []):
        task.discounts.append(DiscountLine(**line))

    return task
コード例 #7
0
ファイル: rest_api.py プロジェクト: Kilya/autonomie
    def post_load_lines_from_catalog_view(self):
        """
        View handling product to line loading

        expects sale_product_ids: [id1, id2] as POST params
        """
        logger.debug("post_load_from_catalog_view")
        sale_product_ids = self.request.json_body.get('sale_product_ids', [])
        logger.debug("sale_product_ids : %s", sale_product_ids)

        lines = []
        for id_ in sale_product_ids:
            sale_product = SaleProduct.get(id_)
            line = TaskLine.from_sale_product(sale_product)
            self.context.lines.append(line)
            lines.append(line)
        self.request.dbsession.merge(self.context)
        return lines
コード例 #8
0
    def post_load_lines_from_catalog_view(self):
        """
        View handling product to line loading

        expects sale_product_ids: [id1, id2] as POST params
        """
        logger.debug("post_load_from_catalog_view")
        sale_product_ids = self.request.json_body.get('sale_product_ids', [])
        logger.debug("sale_product_ids : %s", sale_product_ids)

        lines = []
        for id_ in sale_product_ids:
            sale_product = SaleProduct.get(id_)
            line = TaskLine.from_sale_product(sale_product)
            self.context.lines.append(line)
            lines.append(line)
        self.request.dbsession.merge(self.context)
        return lines
コード例 #9
0
def invoice(project, user, customer, company, phase):
    invoice = Invoice(
        company,
        customer,
        project,
        phase,
        user,
    )
    for key, value in INVOICE.items():
        setattr(invoice, key, value)

    for line in LINES:
        invoice.default_line_group.lines.append(TaskLine(**line))
    for discount in DISCOUNTS:
        invoice.discounts.append(DiscountLine(**discount))
    invoice.mentions = [TaskMention(label='1', title='t1', full_text='text')]

    invoice.address = customer.address

    return invoice
コード例 #10
0
def estimation(project, user, customer, company, phase):
    est = Estimation(
        company,
        customer,
        project,
        phase,
        user,
    )
    for key, value in ESTIMATION.items():
        setattr(est, key, value)
    for line in LINES:
        est.add_line(TaskLine(**line))
    for line in DISCOUNTS:
        est.discounts.append(DiscountLine(**line))
    for line in PAYMENT_LINES:
        est.payment_lines.append(PaymentLine(**line))
    est.mentions = [
        TaskMention(label='mention1', title='title1', full_text='text1')
    ]
    return est
コード例 #11
0
ファイル: conftest.py プロジェクト: tonthon/autonomie
 def make(
     cost,
     description=u"description",
     unity_label=unity.label,
     quantity=1,
     tva_value=tva.value,
     group=task_line_group,
     product=product,
 ):
     line = TaskLine(
         cost=cost,
         quantity=quantity,
         unity=unity_label,
         tva=tva_value,
         product_id=product.id,
         group=group,
     )
     dbsession.add(line)
     dbsession.flush()
     return line
コード例 #12
0
ファイル: test_lines.py プロジェクト: Orelab/autonomie
 def test_total(self):
     i = TaskLine(cost=1.25, quantity=1.25, tva=1960)
     self.assertEqual(i.total_ht(), 1.5625)
     self.assertEqual(i.total(), 1.86875)
コード例 #13
0
ファイル: test_lines.py プロジェクト: Orelab/autonomie
 def test_gen_cancelinvoiceline(self):
     line = TaskLine(**LINE)
     iline = line.gen_cancelinvoice_line()
     for i in ('order', 'tva', "description", "quantity", "unity"):
         self.assertEqual(getattr(line, i), getattr(iline, i))
     self.assertEqual(line.cost, -1 * iline.cost)
コード例 #14
0
ファイル: test_lines.py プロジェクト: Orelab/autonomie
 def test_duplicate_line(self):
     line = TaskLine(**LINE)
     dline = line.duplicate()
     for i in ('order', 'cost', 'tva', "description", "quantity", "unity"):
         self.assertEqual(getattr(dline, i), getattr(line, i))