diff --git a/account_payment_partner/__init__.py b/account_payment_partner/__init__.py index 50def6204..83e553ac4 100644 --- a/account_payment_partner/__init__.py +++ b/account_payment_partner/__init__.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- -# © 2014 Akretion - Alexis de Lattre -# 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 diff --git a/account_payment_partner/models/account_invoice.py b/account_payment_partner/models/account_invoice.py index 86942cbcf..0fc72bb14 100644 --- a/account_payment_partner/models/account_invoice.py +++ b/account_payment_partner/models/account_invoice.py @@ -1,7 +1,6 @@ -# -*- coding: utf-8 -*- -# © 2014-2016 Akretion - Alexis de Lattre -# © 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 +# 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 diff --git a/account_payment_partner/models/account_move_line.py b/account_payment_partner/models/account_move_line.py index 9bdcec4e6..4bfe0ff70 100644 --- a/account_payment_partner/models/account_move_line.py +++ b/account_payment_partner/models/account_move_line.py @@ -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): diff --git a/account_payment_partner/models/res_partner.py b/account_payment_partner/models/res_partner.py index 0b6585aa0..aa60a42f8 100644 --- a/account_payment_partner/models/res_partner.py +++ b/account_payment_partner/models/res_partner.py @@ -1,9 +1,8 @@ -# -*- coding: utf-8 -*- -# © 2014 Akretion - Alexis de Lattre -# © 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 +# 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): diff --git a/account_payment_partner/readme/CONTRIBUTORS.rst b/account_payment_partner/readme/CONTRIBUTORS.rst index 95f514aae..df652cc34 100644 --- a/account_payment_partner/readme/CONTRIBUTORS.rst +++ b/account_payment_partner/readme/CONTRIBUTORS.rst @@ -7,5 +7,5 @@ * Angel Moya * `Tecnativa `_: - * Pedro M. Baeza - * Carlos Dauden + * Pedro M. Baeza + * Carlos Dauden diff --git a/account_payment_partner/readme/DESCRIPTION.rst b/account_payment_partner/readme/DESCRIPTION.rst index 27c9e82be..8ad4f4f64 100644 --- a/account_payment_partner/readme/DESCRIPTION.rst +++ b/account_payment_partner/readme/DESCRIPTION.rst @@ -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, diff --git a/account_payment_partner/readme/HISTORY.rst b/account_payment_partner/readme/HISTORY.rst index a6168b334..8424df5d0 100644 --- a/account_payment_partner/readme/HISTORY.rst +++ b/account_payment_partner/readme/HISTORY.rst @@ -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) ~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/account_payment_partner/readme/USAGE.rst b/account_payment_partner/readme/USAGE.rst index c2bbf0fbc..09ef27577 100644 --- a/account_payment_partner/readme/USAGE.rst +++ b/account_payment_partner/readme/USAGE.rst @@ -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. diff --git a/account_payment_partner/tests/__init__.py b/account_payment_partner/tests/__init__.py index 0d757b027..3449d9e90 100644 --- a/account_payment_partner/tests/__init__.py +++ b/account_payment_partner/tests/__init__.py @@ -1,2 +1 @@ - from . import test_account_payment_partner diff --git a/account_payment_partner/tests/test_account_payment_partner.py b/account_payment_partner/tests/test_account_payment_partner.py index b02016463..14ad3cb59 100644 --- a/account_payment_partner/tests/test_account_payment_partner.py +++ b/account_payment_partner/tests/test_account_payment_partner.py @@ -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) diff --git a/account_payment_partner/views/account_invoice_view.xml b/account_payment_partner/views/account_invoice_view.xml index 859e4572c..f76fac182 100644 --- a/account_payment_partner/views/account_invoice_view.xml +++ b/account_payment_partner/views/account_invoice_view.xml @@ -1,7 +1,7 @@ diff --git a/account_payment_partner/views/account_move_line.xml b/account_payment_partner/views/account_move_line.xml index 1abe8b5e1..601018111 100644 --- a/account_payment_partner/views/account_move_line.xml +++ b/account_payment_partner/views/account_move_line.xml @@ -1,8 +1,7 @@ diff --git a/account_payment_partner/views/report_invoice.xml b/account_payment_partner/views/report_invoice.xml index 1838444d8..b22767685 100644 --- a/account_payment_partner/views/report_invoice.xml +++ b/account_payment_partner/views/report_invoice.xml @@ -20,7 +20,7 @@ - +

diff --git a/account_payment_partner/views/res_partner_view.xml b/account_payment_partner/views/res_partner_view.xml index ad7ceeafe..1c7662232 100644 --- a/account_payment_partner/views/res_partner_view.xml +++ b/account_payment_partner/views/res_partner_view.xml @@ -1,7 +1,6 @@