Handle negative amounts
This commit is contained in:
parent
61e1c5ad75
commit
cecde22f67
@ -1,4 +1,4 @@
|
||||
# Copyright 2018 Onestein (<https://www.onestein.eu>)
|
||||
# Copyright 2018-2019 Onestein (<https://www.onestein.eu>)
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
|
||||
import calendar
|
||||
@ -382,9 +382,6 @@ class AccountSpread(models.Model):
|
||||
In case checks pass, invoke "def _compute_spread_board()" method.
|
||||
"""
|
||||
for spread in self:
|
||||
if spread.total_amount < 0.0:
|
||||
raise UserError(
|
||||
_("Cannot spread negative amounts of invoice lines"))
|
||||
if spread.total_amount:
|
||||
spread._compute_spread_board()
|
||||
|
||||
@ -466,16 +463,28 @@ class AccountSpread(models.Model):
|
||||
spread_mls = self.line_ids.mapped('move_id.line_ids')
|
||||
if created_moves:
|
||||
spread_mls |= created_moves.mapped('line_ids')
|
||||
if self.invoice_type in ('in_invoice', 'out_refund'):
|
||||
|
||||
spread_sign = True if self.total_amount >= 0.0 else False
|
||||
in_invoice_or_out_refund = ('in_invoice', 'out_refund')
|
||||
|
||||
if self.invoice_type in in_invoice_or_out_refund and spread_sign:
|
||||
spread_mls = spread_mls.filtered(lambda x: x.credit != 0.)
|
||||
else:
|
||||
elif self.invoice_type in in_invoice_or_out_refund:
|
||||
spread_mls = spread_mls.filtered(lambda x: x.debit != 0.)
|
||||
elif spread_sign:
|
||||
spread_mls = spread_mls.filtered(lambda x: x.debit != 0.)
|
||||
else:
|
||||
spread_mls = spread_mls.filtered(lambda x: x.credit != 0.)
|
||||
|
||||
invoice_mls = self.invoice_id.move_id.mapped('line_ids')
|
||||
if self.invoice_id.type in ('in_invoice', 'out_refund'):
|
||||
if self.invoice_id.type in in_invoice_or_out_refund and spread_sign:
|
||||
invoice_mls = invoice_mls.filtered(lambda x: x.debit != 0.)
|
||||
else:
|
||||
elif self.invoice_id.type in in_invoice_or_out_refund:
|
||||
invoice_mls = invoice_mls.filtered(lambda x: x.credit != 0.)
|
||||
elif spread_sign:
|
||||
invoice_mls = invoice_mls.filtered(lambda x: x.credit != 0.)
|
||||
else:
|
||||
invoice_mls = invoice_mls.filtered(lambda x: x.debit != 0.)
|
||||
|
||||
to_be_reconciled = self.env['account.move.line']
|
||||
if len(invoice_mls) > 1:
|
||||
|
@ -1,4 +1,4 @@
|
||||
# Copyright 2016-2018 Onestein (<https://www.onestein.eu>)
|
||||
# Copyright 2016-2019 Onestein (<https://www.onestein.eu>)
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import _, api, fields, models
|
||||
@ -84,8 +84,8 @@ class AccountInvoiceSpreadLine(models.Model):
|
||||
line_ids = [(0, 0, {
|
||||
'name': spread.name.split('\n')[0][:64],
|
||||
'account_id': spread.debit_account_id.id,
|
||||
'debit': amount,
|
||||
'credit': 0.0,
|
||||
'debit': amount if amount > 0.0 else 0.0,
|
||||
'credit': -amount if amount < 0.0 else 0.0,
|
||||
'analytic_account_id': analytic.id,
|
||||
'analytic_tag_ids': analytic_tags,
|
||||
'currency_id': not_same_curr and current_currency.id or False,
|
||||
@ -93,8 +93,8 @@ class AccountInvoiceSpreadLine(models.Model):
|
||||
}), (0, 0, {
|
||||
'name': spread.name.split('\n')[0][:64],
|
||||
'account_id': spread.credit_account_id.id,
|
||||
'credit': amount,
|
||||
'debit': 0.0,
|
||||
'credit': amount if amount > 0.0 else 0.0,
|
||||
'debit': -amount if amount < 0.0 else 0.0,
|
||||
'analytic_account_id': analytic.id,
|
||||
'analytic_tag_ids': analytic_tags,
|
||||
'currency_id': not_same_curr and current_currency.id or False,
|
||||
|
@ -1,4 +1,4 @@
|
||||
# Copyright 2017-2018 Onestein (<https://www.onestein.eu>)
|
||||
# Copyright 2017-2019 Onestein (<https://www.onestein.eu>)
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
|
||||
import datetime
|
||||
@ -501,11 +501,10 @@ class TestComputeSpreadBoard(common.TransactionCase):
|
||||
'period_type': 'month',
|
||||
'spread_date': datetime.date(2017, 1, 7)
|
||||
})
|
||||
with self.assertRaises(UserError):
|
||||
self.spread.compute_spread_board()
|
||||
|
||||
spread_lines = self.spread.line_ids
|
||||
self.assertFalse(spread_lines)
|
||||
self.assertTrue(spread_lines)
|
||||
|
||||
def test_15_compute_spread_board_line_account_deprecated(self):
|
||||
self.spread.debit_account_id.deprecated = True
|
||||
|
Loading…
Reference in New Issue
Block a user