Reviewers: ,
Please review this at http://codereview.tryton.org/820002/
Affected files:
M trytond/modules/account_invoice/invoice.py
M trytond/modules/account_statement/statement.py
Index: trytond/modules/account_invoice/invoice.py
===================================================================
--- a/trytond/modules/account_invoice/invoice.py
+++ b/trytond/modules/account_invoice/invoice.py
@@ -598,8 +598,6 @@
with Transaction().set_context(date=invoice.currency_date):
amount_currency += Currency.compute(
invoice.company.currency, amount, invoice.currency)
- if amount_currency < _ZERO:
- amount_currency = _ZERO
res[invoice.id] = amount_currency
return res
Index: trytond/modules/account_statement/statement.py
===================================================================
--- a/trytond/modules/account_statement/statement.py
+++ b/trytond/modules/account_statement/statement.py
@@ -1,5 +1,6 @@
#This file is part of Tryton. The COPYRIGHT file at the top level of
#this repository contains the full copyright notices and license terms.
+import math
from decimal import Decimal
from trytond.model import Workflow, ModelView, ModelSQL, fields
from trytond.pyson import Eval, If
@@ -232,20 +233,16 @@
for line in self.lines or []:
if line.invoice and line.id:
amount_to_pay = invoice_id2amount_to_pay[line.invoice.id]
- if abs(line.amount) > amount_to_pay:
- res['lines'].setdefault('update', [])
- if self.journal.currency.is_zero(amount_to_pay):
- res['lines']['update'].append({
+ res['lines'].setdefault('update', [])
+ if (not self.journal.currency.is_zero(amount_to_pay)
+ and (line.amount >= 0) == (amount_to_pay <= 0)):
+ res['lines']['update'].append({
'id': line.id,
- 'invoice': None,
+ 'amount': (amount_to_pay.copy_sign(line.amount)
+ if abs(line.amount) > abs(amount_to_pay)
+ else line.amount)
})
- else:
- res['lines']['update'].append({
- 'id': line.id,
- 'amount': (amount_to_pay
- if line.amount >= 0
- else -amount_to_pay),
- })
+ if abs(line.amount) > abs(amount_to_pay):
res['lines'].setdefault('add', [])
vals = {}
for field_name, field in Line._fields.iteritems():
@@ -261,15 +258,19 @@
else:
vals[field_name] = value
del vals['id']
- vals['amount'] = (abs(line.amount)
- - amount_to_pay)
- if line.amount < 0:
- vals['amount'] = - vals['amount']
+ vals['amount'] = line.amount + amount_to_pay
vals['invoice'] = None
del vals['invoice.rec_name']
res['lines']['add'].append(vals)
- invoice_id2amount_to_pay[line.invoice.id] = \
- amount_to_pay - abs(line.amount)
+ invoice_id2amount_to_pay[line.invoice.id] = 0
+ else:
+ invoice_id2amount_to_pay[line.invoice.id] = (
+ line.amount + amount_to_pay)
+ else:
+ res['lines']['update'].append({
+ 'id': line.id,
+ 'invoice': None,
+ })
return res
@classmethod