Skip to content

Commit

Permalink
Add credit control payment slip integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nbessi committed Dec 2, 2014
1 parent 893a053 commit ec8d09c
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 2 deletions.
4 changes: 2 additions & 2 deletions l10n_ch_credit_control_payment_slip_report/payment_slip.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ def _compute_amount_hook(self):
('state', 'in', ('to_be_sent', 'sent'))]
)
if credit_lines:
return amount + sum(line.dunning_fees_amount
for line in credit_lines)
amount += sum(line.dunning_fees_amount
for line in credit_lines)
return amount
25 changes: 25 additions & 0 deletions l10n_ch_credit_control_payment_slip_report/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: Nicolas Bessi
# Copyright 2014 Camptocamp SA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import test_payment_slip_report

fast_suite = [
test_payment_slip_report
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: Nicolas Bessi
# Copyright 2014 Camptocamp SA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import openerp.tests.common as test_common


class TestPaymentSlipReport(test_common.TransactionCase):

def setUp(self):
super(TestPaymentSlipReport, self).setUp()
company = self.env.ref('base.main_company')
self.assertTrue(company)
partner = self.env.ref('base.main_partner')
self.assertTrue(partner)
self.bank = self.env['res.bank'].create(
{
'name': 'BCV',
'ccp': '01-1234-1',
'bic': '234234',
'clearing': '234234',
}
)
self.bank_account = self.env['res.partner.bank'].create(
{
'partner_id': partner.id,
'owner_name': partner.name,
'street': partner.street,
'city': partner.city,
'zip': partner.zip,
'state': 'bvr',
'bank': self.bank.id,
'bank_name': self.bank.name,
'bank_bic': self.bank.bic,
'acc_number': 'R 12312123',
'bvr_adherent_num': '1234567',
'print_bank': True,
'print_account': True,
'print_partner': True,
}
)

self.invoice = self.env['account.invoice'].create(
{
'partner_id': self.env.ref('base.res_partner_12').id,
'reference_type': 'none',
'name': 'A customer invoice',
'account_id': self.env.ref('account.a_recv').id,
'type': 'out_invoice',
}
)

self.env['account.invoice.line'].create(
{
'product_id': False,
'quantity': 1,
'price_unit': 862.50,
'invoice_id': self.invoice.id,
'name': 'product that cost 862.50 all tax included',
}
)
self.invoice.signal_workflow('invoice_open')
self.invoice.refresh()
self.assertEqual(self.invoice.amount_total, 862.50)

def test_fees_propagation(self):
"""Test that dunning fees are propagated in payment slip"""
move_line = self.env['account.move.line'].search(
[('invoice', '=', self.invoice.id),
('account_id.type', 'in', ('payable', 'receivable'))],
)
self.assertTrue(len(move_line), 1)

lvl = self.env.ref('account_credit_control.3_time_1')
credit_line = self.env['credit.control.line'].create(
{'move_line_id': move_line.id,
'date_due': '2000-01-01',
'partner_id': self.env.ref('base.res_partner_12').id,
'channel': 'email',
'date': '2000-01-01',
'balance_due': 100.00,
'amount_due': 100.00,
'balance': 100.00,
'policy_level_id': lvl.id,
'state': 'to_be_sent'}
)
slip = self.env['l10n_ch.payment_slip'].search(
[('move_line_id', '=', move_line.id)]
)
self.assertEqual(slip.amount_total, 862.50)
credit_line.write({'dunning_fees_amount': 30000})
slip.refresh()
self.assertEqual(slip.amount_total, 30862.50)

def test_priniting(self):
"""Test that we can print the report"""
move_line = self.env['account.move.line'].search(
[('invoice', '=', self.invoice.id),
('account_id.type', 'in', ('payable', 'receivable'))],
)
self.assertTrue(len(move_line), 1)

lvl = self.env.ref('account_credit_control.3_time_1')
credit_line = self.env['credit.control.line'].create(
{'move_line_id': move_line.id,
'date_due': '2000-01-01',
'partner_id': self.env.ref('base.res_partner_12').id,
'channel': 'email',
'date': '2000-01-01',
'balance_due': 100.00,
'amount_due': 100.00,
'balance': 100.00,
'policy_level_id': lvl.id,
'state': 'to_be_sent'}
)
report_name = 'slip_from_credit_control'
report_obj = self.env['report'].with_context(
active_ids=credit_line.ids)
return report_obj.get_action(credit_line, report_name)

0 comments on commit ec8d09c

Please sign in to comment.