[IMP] account_payment_partner: Add several tests

This commit is contained in:
cubells
2018-12-03 12:45:56 +01:00
committed by Thomas Binsfeld
parent 59c0a5a3d4
commit 9c4906c13b
14 changed files with 142 additions and 52 deletions

View File

@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
# © 2014 Akretion - Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import models

View File

@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
# © 2014-2016 Akretion - Alexis de Lattre <alexis.delattre@akretion.com>
# © 2014 Serv. Tecnol. Avanzados - Pedro M. Baeza
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
# Copyright 2014-16 Akretion - Alexis de Lattre <alexis.delattre@akretion.com>
# Copyright 2014 Serv. Tecnol. Avanzados - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models, _
from odoo.exceptions import ValidationError
@@ -121,12 +120,13 @@ class AccountInvoice(models.Model):
if self.partner_bank_id:
return self.partner_bank_id
if self.payment_mode_id.show_bank_account_from_journal:
if self.payment_mode_id.bank_account_link:
if self.payment_mode_id.bank_account_link == 'fixed':
return self.payment_mode_id.fixed_journal_id.bank_account_id
else:
return self.payment_mode_id.variable_journal_ids.mapped(
'bank_account_id')
if self.payment_mode_id.payment_method_id.code == 'sepa_direct_debit':
if self.payment_mode_id.payment_method_id.code == \
'sepa_direct_debit': # pragma: no cover
return (self.mandate_id.partner_bank_id or
self.partner_id.valid_mandate_id.partner_bank_id)
# Return this as empty recordset

View File

@@ -1,8 +1,7 @@
# -*- coding: utf-8 -*-
# © 2016 Akretion (https://www.akretion.com/)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
# Copyright 2016 Akretion (http://www.akretion.com/)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import models, fields
from odoo import fields, models
class AccountMoveLine(models.Model):

View File

@@ -1,9 +1,8 @@
# -*- coding: utf-8 -*-
# © 2014 Akretion - Alexis de Lattre <alexis.delattre@akretion.com>
# © 2014 Serv. Tecnol. Avanzados - Pedro M. Baeza
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
# Copyright 2014 Akretion - Alexis de Lattre <alexis.delattre@akretion.com>
# Copyright 2014 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import models, fields, api
from odoo import api, fields, models
class ResPartner(models.Model):

View File

@@ -7,5 +7,5 @@
* Angel Moya <angel.moya@domatix.com>
* `Tecnativa <https://www.tecnativa.com>`_:
* Pedro M. Baeza
* Carlos Dauden
* Pedro M. Baeza <pedro.baeza@tecnativa.com>
* Carlos Dauden <carlos.dauden@tecnativa.com>

View File

@@ -1,6 +1,4 @@
[ This file must be max 2-3 paragraphs, and is required. ]
This module adds severals fields :
This module adds severals fields:
* the *Supplier Payment Mode* and *Customer Payment Mode* on Partners,

View File

@@ -1,13 +1,3 @@
[ The change log. The goal of this file is to help readers
understand changes between version. The primary audience is
end users and integrators. Purely technical changes such as
code refactoring must not be mentioned here.
This file may contain ONE level of section titles, underlined
with the ~ (tilde) character. Other section markers are
forbidden and will likely break the structure of the README.rst
or other documents where this fragment is included. ]
10.0.1.2.0 (2018-05-24)
~~~~~~~~~~~~~~~~~~~~~~~

View File

@@ -1,12 +1,9 @@
[ This file must be present and contains the usage instructions
for end-users. As all other rst files included in the README,
it MUST NOT contain reStructuredText sections
only body text (paragraphs, lists, tables, etc). Should you need
a more elaborate structure to explain the addon, please create a
Sphinx documentation (which may include this file as a "quick start"
section). ]
You are able to add a payment mode directly on a partner.
This payment mode is automatically associated to the invoice related to the partner. This default value could be change in a draft invoice.
When you create an payment order, only invoices related to chosen payment mode are displayed.
Invoices without any payment mode are displayed to.
This payment mode is automatically associated to the invoice related to the
partner. This default value could be changed in a draft invoice.
When you create a payment order, only invoices related to chosen payment mode
are displayed.
Invoices without any payment mode are displayed too.

View File

@@ -1,2 +1 @@
from . import test_account_payment_partner

View File

@@ -132,6 +132,49 @@ class TestAccountPaymentPartner(common.SavepointCase):
[('user_type_id', '=', cls.acct_type_expenses.id),
('company_id', '=', cls.company.id)],
limit=1)
cls.journal_bank = cls.env['res.partner.bank'].create({
'acc_number': 'GB95LOYD87430237296288',
'partner_id': cls.env.user.company_id.id,
})
cls.journal = cls.env['account.journal'].create({
'name': 'BANK TEST',
'code': 'TEST',
'type': 'bank',
'bank_account_id': cls.journal_bank.id,
})
mode_in = cls.env['account.payment.mode'].create({
'name': 'Payment Mode Inbound',
'payment_method_id':
cls.env.ref('account.account_payment_method_manual_in').id,
'bank_account_link': 'fixed',
'fixed_journal_id': cls.journal.id,
})
method_out = cls.env.ref('account.account_payment_method_manual_out')
method_out.bank_account_required = True
cls.mode_out = cls.env['account.payment.mode'].create({
'name': 'Payment Mode Outbound',
'payment_method_id': method_out.id,
'bank_account_link': 'fixed',
'fixed_journal_id': cls.journal.id,
})
cls.partner = cls.env['res.partner'].create({
'name': 'Test Partner',
'customer': True,
'customer_payment_mode_id': mode_in.id,
})
cls.supplier = cls.env['res.partner'].create({
'name': 'Test Supplier',
'supplier': True,
'supplier_payment_mode_id': cls.mode_out.id,
})
cls.supplier_bank = cls.env['res.partner.bank'].create({
'acc_number': 'GB18BARC20040131665123',
'partner_id': cls.supplier.id,
})
cls.supplier_invoice = cls.env['account.invoice'].create({
'partner_id': cls.supplier.id,
'type': 'in_invoice',
})
def _create_invoice(self):
@@ -313,3 +356,72 @@ class TestAccountPaymentPartner(common.SavepointCase):
self.customer.customer_payment_mode_id,
self.customer_payment_mode
)
def test_partner_onchange(self):
customer_invoice = self.env['account.invoice'].create({
'partner_id': self.partner.id,
'type': 'out_invoice',
})
customer_invoice._onchange_partner_id()
self.assertEqual(customer_invoice.payment_mode_id,
self.partner.customer_payment_mode_id)
self.supplier_invoice._onchange_partner_id()
self.assertEqual(self.supplier_invoice.partner_bank_id,
self.supplier_bank)
vals = {'partner_id': False, 'type': 'out_invoice'}
invoice = self.env['account.invoice'].new(vals)
invoice._onchange_partner_id()
self.assertFalse(invoice.payment_mode_id)
vals = {'partner_id': False, 'type': 'in_invoice'}
invoice = self.env['account.invoice'].new(vals)
invoice._onchange_partner_id()
self.assertFalse(invoice.partner_bank_id)
def test_payment_mode_id_change(self):
self.supplier_invoice.payment_mode_id = self.mode_out.id
self.supplier_invoice.payment_mode_id_change()
self.assertEqual(self.supplier_invoice.partner_bank_id,
self.supplier_bank)
self.mode_out.payment_method_id.bank_account_required = False
self.supplier_invoice.payment_mode_id = self.mode_out.id
self.supplier_invoice.payment_mode_id_change()
self.assertFalse(self.supplier_invoice.partner_bank_id)
self.supplier_invoice.payment_mode_id = False
self.supplier_invoice.payment_mode_id_change()
self.assertFalse(self.supplier_invoice.partner_bank_id)
def test_print_report(self):
self.env['account.invoice.line'].create({
'invoice_id': self.supplier_invoice.id,
'name': 'Product Text',
'price_unit': 10.0,
'account_id': self.env.ref('l10n_generic_coa.1_conf_o_income').id,
})
self.supplier_invoice.action_invoice_open()
self.assertEqual(
self.supplier_invoice.move_id.line_ids[0].payment_mode_id,
self.supplier_invoice.payment_mode_id)
(res, _) = report.render_report(
self.env.cr, self.env.uid,
[self.supplier_invoice.id], 'account.report_invoice', {})
self.assertRegexpMatches(res, self.supplier_bank.acc_number)
self.supplier_invoice.partner_bank_id = False
self.supplier_invoice.payment_mode_id\
.show_bank_account_from_journal = True
(res, _) = report.render_report(
self.env.cr, self.env.uid,
[self.supplier_invoice.id], 'account.report_invoice', {})
self.assertRegexpMatches(res, self.journal_bank.acc_number)
payment_mode = self.supplier_invoice.payment_mode_id
self.supplier_invoice.payment_mode_id = False
payment_mode.bank_account_link = 'variable'
payment_mode.variable_journal_ids = [
(6, 0, [self.journal.id])]
self.supplier_invoice.payment_mode_id = payment_mode.id
self.supplier_invoice.payment_mode_id_change()
(res, _) = report.render_report(
self.env.cr, self.env.uid,
[self.supplier_invoice.id], 'account.report_invoice', {})
self.assertRegexpMatches(
res, self.journal_bank.acc_number)

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
© 2014-2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
Copyright 2014-16 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo>

View File

@@ -1,8 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
© 2016 Akretion (https://www.akretion.com/)
@author Alexis de Lattre <alexis.delattre@akretion.com>
Copyright 2016 Akretion (http://www.akretion.com/)
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
-->

View File

@@ -20,7 +20,7 @@
<span t-esc="partner_bank.acc_number[:o.payment_mode_id.show_bank_account_chars] + '*' * (len(partner_bank.acc_number) - o.payment_mode_id.show_bank_account_chars)"/>
</t>
<t t-elif="o.payment_mode_id.show_bank_account == 'last'">
<span t-esc="'*' * (len(partner_bank.acc_number) - o.payment_mode_id.show_bank_account_chars) + partner_bank.acc_number[o.payment_mode_id.show_bank_account_chars:]"/>
<span t-esc="'*' * (len(partner_bank.acc_number) - o.payment_mode_id.show_bank_account_chars) + partner_bank.acc_number[-o.payment_mode_id.show_bank_account_chars:]"/>
</t>
</p>
</t>

View File

@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
© 2014-2016 Akretion (https://www.akretion.com/)
@author Alexis de Lattre <alexis.delattre@akretion.com>
Copyright 2014-2016 Akretion (http://www.akretion.com/)
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
-->