From 16b3cd6a9633f9598ac64e22c5bdf4b0fdfcb50d Mon Sep 17 00:00:00 2001 From: etobella Date: Mon, 16 Oct 2017 16:28:26 +0200 Subject: [PATCH] [MIG] account_payment_mandate: Migration to 11.0 --- account_banking_mandate/README.rst | 8 +-- account_banking_mandate/__manifest__.py | 4 +- .../models/account_banking_mandate.py | 7 +- .../models/account_invoice.py | 8 +-- .../models/account_move_line.py | 2 +- .../models/account_payment_line.py | 2 +- .../models/account_payment_method.py | 2 +- .../models/bank_payment_line.py | 2 +- account_banking_mandate/models/res_partner.py | 2 +- .../models/res_partner_bank.py | 2 +- .../security/mandate_security.xml | 2 +- account_banking_mandate/tests/__init__.py | 1 + .../tests/test_invoice_mandate.py | 65 +++++++++++++++++++ account_banking_mandate/tests/test_mandate.py | 3 +- .../views/account_banking_mandate_view.xml | 3 +- .../views/account_invoice_view.xml | 2 +- .../views/account_move_line.xml | 2 +- .../views/account_payment_line.xml | 2 +- .../views/bank_payment_line_view.xml | 2 +- account_banking_mandate/views/res_partner.xml | 2 +- .../views/res_partner_bank_view.xml | 2 +- 21 files changed, 99 insertions(+), 26 deletions(-) create mode 100644 account_banking_mandate/tests/test_invoice_mandate.py diff --git a/account_banking_mandate/README.rst b/account_banking_mandate/README.rst index 3b5d39c9a..4edff4f4d 100644 --- a/account_banking_mandate/README.rst +++ b/account_banking_mandate/README.rst @@ -34,7 +34,7 @@ To use this module, see menu "Accounting > payment > SEPA direct debit mandates" .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/173/9.0 + :target: https://runbot.odoo-community.org/runbot/173/11.0 Known issues / Roadmap ====================== @@ -65,12 +65,12 @@ Contributors Maintainer ---------- -.. image:: http://odoo-community.org/logo.png +.. image:: https://odoo-community.org/logo.png :alt: Odoo Community Association - :target: http://odoo-community.org + :target: https://odoo-community.org This module is maintained by the OCA. OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. -To contribute to this module, please visit http://odoo-community.org. +To contribute to this module, please visit https://odoo-community.org. diff --git a/account_banking_mandate/__manifest__.py b/account_banking_mandate/__manifest__.py index 42969b563..f06a45a39 100644 --- a/account_banking_mandate/__manifest__.py +++ b/account_banking_mandate/__manifest__.py @@ -2,12 +2,12 @@ # © 2014 Compassion CH - Cyril Sester # © 2014 Tecnativa - Pedro M. Baeza # © 2015-2016 Akretion - Alexis de Lattre -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). { 'name': 'Account Banking Mandate', 'summary': 'Banking mandates', - 'version': '10.0.1.1.2', + 'version': '11.0.1.0.1', 'license': 'AGPL-3', 'author': "Compassion CH, " "Tecnativa, " diff --git a/account_banking_mandate/models/account_banking_mandate.py b/account_banking_mandate/models/account_banking_mandate.py index 884809606..8224c0d1a 100644 --- a/account_banking_mandate/models/account_banking_mandate.py +++ b/account_banking_mandate/models/account_banking_mandate.py @@ -2,7 +2,7 @@ # © 2014 Compassion CH - Cyril Sester # © 2014 Serv. Tecnol. Avanzados - Pedro M. Baeza # © 2015-2016 Akretion - Alexis de Lattre -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from odoo import models, fields, api, _ from odoo.exceptions import UserError, ValidationError @@ -22,6 +22,11 @@ class AccountBankingMandate(models.Model): format = fields.Selection( [('basic', 'Basic Mandate')], default='basic', required=True, string='Mandate Format', track_visibility='onchange') + type = fields.Selection( + [('generic', 'Generic Mandate')], + string='Type of Mandate', + track_visibility='onchange' + ) partner_bank_id = fields.Many2one( comodel_name='res.partner.bank', string='Bank Account', track_visibility='onchange') diff --git a/account_banking_mandate/models/account_invoice.py b/account_banking_mandate/models/account_invoice.py index 7adb49f10..9d2aff82d 100644 --- a/account_banking_mandate/models/account_invoice.py +++ b/account_banking_mandate/models/account_invoice.py @@ -2,7 +2,7 @@ # © 2014 Compassion CH - Cyril Sester # © 2014 Serv. Tecnol. Avanzados - Pedro M. Baeza # © 2016 Akretion (Alexis de Lattre ) -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from odoo import models, fields, api @@ -36,7 +36,7 @@ class AccountInvoice(models.Model): onchanges = { '_onchange_partner_id': ['mandate_id'], } - for onchange_method, changed_fields in onchanges.items(): + for onchange_method, changed_fields in list(onchanges.items()): if any(f not in vals for f in changed_fields): invoice = self.new(vals) getattr(invoice, onchange_method)() @@ -84,8 +84,8 @@ class AccountInvoice(models.Model): return res @api.onchange('payment_mode_id') - def payment_mode_id_change(self): - super(AccountInvoice, self).payment_mode_id_change() + def _onchange_payment_mode_id(self): + super(AccountInvoice, self)._onchange_payment_mode_id() if ( self.payment_mode_id and self.payment_mode_id.payment_type == 'inbound' and diff --git a/account_banking_mandate/models/account_move_line.py b/account_banking_mandate/models/account_move_line.py index 8306ca1e4..a3b80011b 100644 --- a/account_banking_mandate/models/account_move_line.py +++ b/account_banking_mandate/models/account_move_line.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # © 2016 Akretion (http://www.akretion.com/) -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from odoo import models, fields, api diff --git a/account_banking_mandate/models/account_payment_line.py b/account_banking_mandate/models/account_payment_line.py index 61969d93d..d4677ac6d 100644 --- a/account_banking_mandate/models/account_payment_line.py +++ b/account_banking_mandate/models/account_payment_line.py @@ -2,7 +2,7 @@ # © 2014 Compassion CH - Cyril Sester # © 2014 Serv. Tecnol. Avanzados - Pedro M. Baeza # © 2015-2016 Akretion - Alexis de Lattre -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from odoo import models, fields, api, _ from odoo.exceptions import ValidationError, UserError diff --git a/account_banking_mandate/models/account_payment_method.py b/account_banking_mandate/models/account_payment_method.py index 4bf1f4309..66a10e2af 100644 --- a/account_banking_mandate/models/account_payment_method.py +++ b/account_banking_mandate/models/account_payment_method.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # © 2016 Akretion (Alexis de Lattre ) -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from odoo import models, fields diff --git a/account_banking_mandate/models/bank_payment_line.py b/account_banking_mandate/models/bank_payment_line.py index 3d0d1b329..4b583a71c 100644 --- a/account_banking_mandate/models/bank_payment_line.py +++ b/account_banking_mandate/models/bank_payment_line.py @@ -2,7 +2,7 @@ # © 2014 Compassion CH - Cyril Sester # © 2014 Serv. Tecnol. Avanzados - Pedro M. Baeza # © 2015-2016 Akretion - Alexis de Lattre -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from odoo import models, fields, api diff --git a/account_banking_mandate/models/res_partner.py b/account_banking_mandate/models/res_partner.py index bcc7b3dd7..b9fae1890 100644 --- a/account_banking_mandate/models/res_partner.py +++ b/account_banking_mandate/models/res_partner.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # © 2016 Akretion (Alexis de Lattre ) -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from odoo import models, fields, api diff --git a/account_banking_mandate/models/res_partner_bank.py b/account_banking_mandate/models/res_partner_bank.py index c693ab280..01263410e 100644 --- a/account_banking_mandate/models/res_partner_bank.py +++ b/account_banking_mandate/models/res_partner_bank.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # © 2014 Compassion CH - Cyril Sester # © 2014 Serv. Tecnol. Avanzados - Pedro M. Baeza -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from odoo import models, fields diff --git a/account_banking_mandate/security/mandate_security.xml b/account_banking_mandate/security/mandate_security.xml index 2b88bb12b..bff46c5e5 100644 --- a/account_banking_mandate/security/mandate_security.xml +++ b/account_banking_mandate/security/mandate_security.xml @@ -1,7 +1,7 @@ diff --git a/account_banking_mandate/tests/__init__.py b/account_banking_mandate/tests/__init__.py index df3d8d352..15cf9fc57 100644 --- a/account_banking_mandate/tests/__init__.py +++ b/account_banking_mandate/tests/__init__.py @@ -1,3 +1,4 @@ # -*- coding: utf-8 -*- from . import test_mandate +from . import test_invoice_mandate diff --git a/account_banking_mandate/tests/test_invoice_mandate.py b/account_banking_mandate/tests/test_invoice_mandate.py new file mode 100644 index 000000000..485e2507f --- /dev/null +++ b/account_banking_mandate/tests/test_invoice_mandate.py @@ -0,0 +1,65 @@ +# -*- coding: utf-8 -*- +# © 2017 Creu Blanca +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo.tests.common import TransactionCase + + +class TestInvoiceMandate(TransactionCase): + + def test_post_invoice_and_refund(self): + self.invoice._onchange_partner_id() + self.invoice.action_invoice_open() + self.env['account.invoice.payment.line.multi'].with_context( + active_model='account.invoice', + active_ids=self.invoice.ids + ).create({}).run() + + payment_order = self.env['account.payment.order'].search([]) + self.assertEqual(len(payment_order.ids), 1) + payment_order.draft2open() + payment_order.open2generated() + payment_order.generated2uploaded() + + def test_post_invoice_and_refund(self): + self.invoice._onchange_partner_id() + self.invoice.action_invoice_open() + self.assertEqual(self.invoice.mandate_id, self.mandate) + self.invoice.refund() + + def setUp(self): + res = super(TestInvoiceMandate, self).setUp() + self.partner = self.env.ref('base.res_partner_12') + bank_account = self.env.ref('account_payment_mode.res_partner_12_iban') + self.mandate = self.env['account.banking.mandate'].create({ + 'partner_bank_id': bank_account.id, + 'signature_date': '2015-01-01', + }) + self.mandate.validate() + mode = self.env.ref('account_payment_mode.payment_mode_inbound_ct1') + self.partner.customer_payment_mode_id = mode + mode.payment_method_id.mandate_required = True + invoice_account = self.env['account.account'].search( + [('user_type_id', '=', self.env.ref( + 'account.data_account_type_payable').id)], + limit=1).id + invoice_line_account = self.env['account.account'].search( + [('user_type_id', '=', self.env.ref( + 'account.data_account_type_expenses').id)], + limit=1).id + + self.invoice = self.env['account.invoice'].create({ + 'partner_id': self.partner.id, + 'account_id': invoice_account, + 'type': 'out_invoice' + }) + + self.env['account.invoice.line'].create({ + 'product_id': self.env.ref('product.product_product_4').id, + 'quantity': 1.0, + 'price_unit': 100.0, + 'invoice_id': self.invoice.id, + 'name': 'product that cost 100', + 'account_id': invoice_line_account, + }) + return res diff --git a/account_banking_mandate/tests/test_mandate.py b/account_banking_mandate/tests/test_mandate.py index a59e9c048..db14316ce 100644 --- a/account_banking_mandate/tests/test_mandate.py +++ b/account_banking_mandate/tests/test_mandate.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # © 2016 Akretion (Alexis de Lattre ) -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from odoo.tests.common import TransactionCase @@ -16,6 +16,7 @@ class TestMandate(TransactionCase): self.assertEqual(mandate.state, 'draft') mandate.validate() self.assertEqual(mandate.state, 'valid') + self.assertEqual(bank_account.partner_id.mandate_count, 1) mandate.cancel() self.assertEqual(mandate.state, 'cancel') mandate.back2draft() diff --git a/account_banking_mandate/views/account_banking_mandate_view.xml b/account_banking_mandate/views/account_banking_mandate_view.xml index 71acbe7e5..2e21d4ba4 100644 --- a/account_banking_mandate/views/account_banking_mandate_view.xml +++ b/account_banking_mandate/views/account_banking_mandate_view.xml @@ -1,7 +1,7 @@ @@ -30,6 +30,7 @@ + diff --git a/account_banking_mandate/views/account_move_line.xml b/account_banking_mandate/views/account_move_line.xml index 567fc14e1..59f322d19 100644 --- a/account_banking_mandate/views/account_move_line.xml +++ b/account_banking_mandate/views/account_move_line.xml @@ -1,7 +1,7 @@ diff --git a/account_banking_mandate/views/account_payment_line.xml b/account_banking_mandate/views/account_payment_line.xml index 52288f781..ecce68779 100644 --- a/account_banking_mandate/views/account_payment_line.xml +++ b/account_banking_mandate/views/account_payment_line.xml @@ -1,7 +1,7 @@ diff --git a/account_banking_mandate/views/bank_payment_line_view.xml b/account_banking_mandate/views/bank_payment_line_view.xml index f06e0cb18..983e2b91e 100644 --- a/account_banking_mandate/views/bank_payment_line_view.xml +++ b/account_banking_mandate/views/bank_payment_line_view.xml @@ -1,7 +1,7 @@ diff --git a/account_banking_mandate/views/res_partner.xml b/account_banking_mandate/views/res_partner.xml index e6df2294e..1ff56927a 100644 --- a/account_banking_mandate/views/res_partner.xml +++ b/account_banking_mandate/views/res_partner.xml @@ -1,7 +1,7 @@ diff --git a/account_banking_mandate/views/res_partner_bank_view.xml b/account_banking_mandate/views/res_partner_bank_view.xml index 85c69a550..9793fce1a 100644 --- a/account_banking_mandate/views/res_partner_bank_view.xml +++ b/account_banking_mandate/views/res_partner_bank_view.xml @@ -1,7 +1,7 @@