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
This commit is contained in:
Cédric Krier committed 2015-09-07 13:57:43 +02:00
1 parent c9b44e946d
commit 57bf856e48
2 files changed
+18 -6

No files matched your search

+3 -3
View File
@@ -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')
+15 -3
View File
@@ -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