示例#1
0
 def try_round(amount, expected):
     digits = max(0, -int(log10(currency.rounding)))
     result = float_repr(currency.round(amount),
                         precision_digits=digits)
     self.assertEqual(
         result, expected,
         'Rounding error: got %s, expected %s' % (result, expected))
示例#2
0
 def try_round(amount, expected, digits=3, method='HALF-UP'):
     value = float_round(amount,
                         precision_digits=digits,
                         rounding_method=method)
     result = float_repr(value, precision_digits=digits)
     self.assertEqual(
         result, expected,
         'Rounding error: got %s, expected %s' % (result, expected))
示例#3
0
    def check_monetary(self, record, amount, currency, msg=None):
        # determine the possible roundings of amount
        if currency:
            ramount = currency.round(amount)
            samount = float(float_repr(ramount, currency.decimal_places))
        else:
            ramount = samount = amount

        # check the currency on record
        self.assertEqual(record.currency_id, currency)

        # check the value on the record
        self.assertIn(record.amount, [ramount, samount], msg)

        # check the value in the database
        self.cr.execute('SELECT amount FROM test_new_api_mixed WHERE id=%s',
                        [record.id])
        value = self.cr.fetchone()[0]
        self.assertEqual(value, samount, msg)
示例#4
0
    def test_revenue_multi_currency(self):
        """ Create a SO with 2 lines : one for a delivered service, one for a ordered service. Confirm
            and invoice it. For this, we use a partner having a DIFFERENT currency from the current company.
            4 timesheets are logged before invoicing : 2 for delivered, 2 for ordered.
        """
        # create SO and confirm it
        sale_order = self.env['sale.order'].create({
            'partner_id':
            self.partner_usd.id,
            'partner_invoice_id':
            self.partner_eur.id,
            'partner_shipping_id':
            self.partner_eur.id,
            'pricelist_id':
            self.pricelist_eur.id,
        })
        sale_order_line_delivered = self.env['sale.order.line'].create({
            'name':
            self.product_deliver.name,
            'product_id':
            self.product_deliver.id,
            'product_uom_qty':
            12,
            'product_uom':
            self.product_deliver.uom_id.id,
            'price_unit':
            self.product_deliver.list_price,
            'order_id':
            sale_order.id,
        })
        sale_order_line_ordered = self.env['sale.order.line'].create({
            'name':
            self.product_order.name,
            'product_id':
            self.product_order.id,
            'product_uom_qty':
            7,
            'product_uom':
            self.product_order.uom_id.id,
            'price_unit':
            self.product_order.list_price,
            'order_id':
            sale_order.id,
        })
        sale_order_line_ordered.product_id_change()
        sale_order_line_delivered.product_id_change()
        sale_order.action_confirm()

        # log timesheet on tasks
        task_delivered = self.env['project.task'].search([
            ('sale_line_id', '=', sale_order_line_delivered.id)
        ])
        task_ordered = self.env['project.task'].search([
            ('sale_line_id', '=', sale_order_line_ordered.id)
        ])

        timesheet1 = self.env['account.analytic.line'].create({
            'name':
            'ts 1',
            'unit_amount':
            5,
            'task_id':
            task_delivered.id,
            'project_id':
            task_delivered.project_id.id,
        })
        timesheet2 = self.env['account.analytic.line'].create({
            'name':
            'ts 2',
            'unit_amount':
            2,
            'task_id':
            task_delivered.id,
            'project_id':
            task_delivered.project_id.id,
        })
        timesheet3 = self.env['account.analytic.line'].create({
            'name':
            'ts 3',
            'unit_amount':
            3,
            'task_id':
            task_ordered.id,
            'project_id':
            task_ordered.project_id.id,
        })
        timesheet4 = self.env['account.analytic.line'].create({
            'name':
            'ts 4',
            'unit_amount':
            6,
            'task_id':
            task_ordered.id,
            'project_id':
            task_ordered.project_id.id,
        })

        # check theorical revenue
        # Note: conversion from EUR to USD is  *1.2833309567944147
        self.assertEquals(
            timesheet1.timesheet_invoice_type, 'billable_time',
            "Billable type on task from delivered service should be 'billabe time'"
        )
        self.assertEquals(
            timesheet2.timesheet_invoice_type, 'billable_time',
            "Billable type on task from delivered service should be 'billabe time'"
        )
        self.assertEquals(
            timesheet3.timesheet_invoice_type, 'billable_fixed',
            "Billable type on task from ordered service should be 'billabe fixed'"
        )
        self.assertEquals(
            timesheet4.timesheet_invoice_type, 'billable_fixed',
            "Billable type on task from ordered service should be 'billabe fixed'"
        )
        self.assertEquals(timesheet1.timesheet_invoice_id,
                          self.env['account.invoice'])
        self.assertEquals(timesheet2.timesheet_invoice_id,
                          self.env['account.invoice'])
        self.assertEquals(timesheet3.timesheet_invoice_id,
                          self.env['account.invoice'])
        # Same computation as the test below, since revenue is stored in company currency
        self.assertEquals(
            timesheet1.timesheet_revenue, 450,
            "Revenue computation does not return the correct amount !")
        self.assertEquals(
            timesheet2.timesheet_revenue, 180,
            "Revenue computation does not return the correct amount !")
        self.assertEquals(
            timesheet3.timesheet_revenue, 153,
            "Revenue computation does not return the correct amount !")
        self.assertEquals(
            timesheet4.timesheet_revenue, 204,
            "Revenue computation does not return the correct amount !")

        # invoice the SO
        context = {
            "active_model": 'sale.order',
            "active_ids": [sale_order.id],
            "active_id": sale_order.id,
            'open_invoices': True,
        }
        payment = self.env['sale.advance.payment.inv'].create({
            'advance_payment_method':
            'delivered',
        })
        action_invoice = payment.with_context(context).create_invoices()
        invoice_id = action_invoice['res_id']
        invoice = self.env['account.invoice'].browse(invoice_id)

        # update invoice line by setting a reduction, then validate it
        for invoice_line in invoice.invoice_line_ids:
            invoice_line.write({'price_unit': invoice_line.price_unit - 10})
        invoice.action_invoice_open()

        # check concrete revenue
        self.assertEquals(
            float_repr(timesheet1.timesheet_revenue,
                       precision_digits=2), '385.85',
            "Revenue computation on invoice validation does not return the correct revenue !"
        )
        self.assertEquals(
            float_repr(timesheet2.timesheet_revenue,
                       precision_digits=2), '154.35',
            "Revenue computation on invoice validation does not return the correct revenue !"
        )
        self.assertEquals(
            float_repr(timesheet3.timesheet_revenue,
                       precision_digits=2), '114.50',
            "Revenue computation on invoice validation does not return the correct revenue !"
        )
        self.assertEquals(
            float_repr(timesheet4.timesheet_revenue,
                       precision_digits=2), '152.68',
            "Revenue computation on invoice validation does not return the correct revenue !"
        )

        # check the invoice is well set
        self.assertEquals(timesheet1.timesheet_invoice_id, invoice)
        self.assertEquals(timesheet2.timesheet_invoice_id, invoice)
        self.assertEquals(timesheet3.timesheet_invoice_id, invoice)