From 57bf856e484d97615c642db7d253e19115983057 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 7 Sep 2015 13:57:43 +0200 Subject: [PATCH] Fix computation of invoice amount on effort The amount must be proportional to the effort hours of the work because the invoice line could have been grouped. issue4946 review19431002 --- tests/scenario_project_invoice_timesheet.rst | 6 +++--- work.py | 18 +++++++++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/tests/scenario_project_invoice_timesheet.rst b/tests/scenario_project_invoice_timesheet.rst index 3256ecb7ae..1b4d6a21d5 100644 --- a/tests/scenario_project_invoice_timesheet.rst +++ b/tests/scenario_project_invoice_timesheet.rst @@ -168,7 +168,7 @@ Invoice project:: >>> project.duration_to_invoice datetime.timedelta(0) >>> project.invoiced_amount - Decimal('100.000000000000') + Decimal('100.00') Create more timesheets:: @@ -188,7 +188,7 @@ Check project duration:: >>> project.duration_to_invoice datetime.timedelta(0, 14400) >>> project.invoiced_amount - Decimal('100.000000000000') + Decimal('100.00') Invoice again project:: @@ -199,4 +199,4 @@ Invoice again project:: >>> project.duration_to_invoice datetime.timedelta(0) >>> project.invoiced_amount - Decimal('180.000000000000') + Decimal('180.00') diff --git a/work.py b/work.py index 2d097f62e2..f7d46b8b81 100644 --- a/work.py +++ b/work.py @@ -145,6 +145,7 @@ class Work: def _get_invoiced_amount_effort(works): pool = Pool() InvoiceLine = pool.get('account.invoice.line') + Currency = pool.get('currency.currency') invoice_lines = InvoiceLine.browse([ w.invoice_line.id for w in works @@ -153,9 +154,14 @@ class Work: id2invoice_lines = dict((l.id, l) for l in invoice_lines) amounts = {} for work in works: + currency = work.company.currency if work.invoice_line: invoice_line = id2invoice_lines[work.invoice_line.id] - amounts[work.id] = invoice_line.amount + invoice_currency = (invoice_line.invoice.currency + if invoice_line.invoice else invoice_line.currency) + amounts[work.id] = Currency.compute(invoice_currency, + Decimal(str(work.effort_hours)) * invoice_line.unit_price, + currency) else: amounts[work.id] = Decimal(0) return amounts @@ -164,6 +170,7 @@ class Work: def _get_invoiced_amount_timesheet(works): pool = Pool() InvoiceLine = pool.get('account.invoice.line') + Currency = pool.get('currency.currency') invoice_lines = InvoiceLine.browse([ t.invoice_line.id for w in works @@ -173,13 +180,18 @@ class Work: id2invoice_lines = dict((l.id, l) for l in invoice_lines) amounts = {} for work in works: + currency = work.company.currency amounts[work.id] = Decimal(0) for timesheet_line in work.work.timesheet_lines: if not timesheet_line.invoice_line: continue invoice_line = id2invoice_lines[timesheet_line.invoice_line.id] - amounts[work.id] += (invoice_line.unit_price - * Decimal(str(timesheet_line.hours))) + invoice_currency = (invoice_line.invoice.currency + if invoice_line.invoice else invoice_line.currency) + amounts[work.id] += Currency.compute(invoice_currency, + (Decimal(str(timesheet_line.hours)) + * invoice_line.unit_price), + currency) return amounts @staticmethod