From 0b65e0914915cfd75b8f21022b2d704586f8f0b1 Mon Sep 17 00:00:00 2001 From: Guille Date: Wed, 21 Oct 2020 12:28:28 +0200 Subject: [PATCH] [IMP] contract_mandate: black, isort, prettier --- contract_mandate/__manifest__.py | 28 +++----- contract_mandate/models/contract.py | 40 ++++++----- .../tests/test_contract_mandate.py | 69 ++++++++++--------- contract_mandate/views/contract_view.xml | 21 +++--- 4 files changed, 81 insertions(+), 77 deletions(-) diff --git a/contract_mandate/__manifest__.py b/contract_mandate/__manifest__.py index 39d77757d..cd1467c3f 100644 --- a/contract_mandate/__manifest__.py +++ b/contract_mandate/__manifest__.py @@ -2,21 +2,15 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { - 'name': 'Contract Mandate', - 'summary': 'Mandate in contracts and their invoices', - 'version': '12.0.1.0.2', - 'author': 'Odoo Community Association (OCA), ' - 'Tecnativa', - 'website': 'https://github.com/OCA/contract', - 'depends': [ - 'contract_payment_mode', - 'account_banking_mandate', - ], - 'category': 'Sales Management', - 'license': 'AGPL-3', - 'data': [ - 'views/contract_view.xml', - ], - 'installable': True, - 'auto_install': True, + "name": "Contract Mandate", + "summary": "Mandate in contracts and their invoices", + "version": "12.0.1.0.2", + "author": "Odoo Community Association (OCA), " "Tecnativa", + "website": "https://github.com/OCA/contract", + "depends": ["contract_payment_mode", "account_banking_mandate",], + "category": "Sales Management", + "license": "AGPL-3", + "data": ["views/contract_view.xml",], + "installable": True, + "auto_install": True, } diff --git a/contract_mandate/models/contract.py b/contract_mandate/models/contract.py index 36f4c850e..3790111d3 100644 --- a/contract_mandate/models/contract.py +++ b/contract_mandate/models/contract.py @@ -5,27 +5,27 @@ from odoo import api, fields, models class ContractContract(models.Model): - _inherit = 'contract.contract' + _inherit = "contract.contract" mandate_id = fields.Many2one( - comodel_name='account.banking.mandate', - ondelete='restrict', - string='Direct Debit Mandate', + comodel_name="account.banking.mandate", + ondelete="restrict", + string="Direct Debit Mandate", help="If mandate required in payment method and not set mandate, " - "invoice takes the first valid mandate", + "invoice takes the first valid mandate", index=True, ) mandate_required = fields.Boolean( - related='payment_mode_id.payment_method_id.mandate_required', - readonly=True) + related="payment_mode_id.payment_method_id.mandate_required", readonly=True + ) commercial_partner_id = fields.Many2one( - related='partner_id.commercial_partner_id', + related="partner_id.commercial_partner_id", readonly=True, - string='Commercial Entity', + string="Commercial Entity", ) @api.multi - @api.onchange('payment_mode_id') + @api.onchange("payment_mode_id") def _onchange_payment_mode_id(self): self.ensure_one() if not self.mandate_required: @@ -37,14 +37,17 @@ class ContractContract(models.Model): date_invoice, journal=journal ) if self.mandate_id: - invoice_vals['mandate_id'] = self.mandate_id.id + invoice_vals["mandate_id"] = self.mandate_id.id elif self.payment_mode_id.payment_method_id.mandate_required: - mandate = self.env['account.banking.mandate'].search([ - ('partner_id', '=', self.partner_id.commercial_partner_id.id), - ('state', '=', 'valid'), - ('company_id', '=', self.company_id.id), - ], limit=1) - invoice_vals['mandate_id'] = mandate.id + mandate = self.env["account.banking.mandate"].search( + [ + ("partner_id", "=", self.partner_id.commercial_partner_id.id), + ("state", "=", "valid"), + ("company_id", "=", self.company_id.id), + ], + limit=1, + ) + invoice_vals["mandate_id"] = mandate.id return invoice_vals @api.model @@ -56,8 +59,7 @@ class ContractContract(models.Model): mandates_by_invoice = {} for invoice in invoices: mandates_by_invoice[invoice] = invoice.mandate_id - res = super(ContractContract, self)._finalize_invoice_creation( - invoices) + res = super(ContractContract, self)._finalize_invoice_creation(invoices) for invoice in invoices: invoice.mandate_id = mandates_by_invoice.get(invoice) return res diff --git a/contract_mandate/tests/test_contract_mandate.py b/contract_mandate/tests/test_contract_mandate.py index 1c4e4f7c2..326f7c750 100644 --- a/contract_mandate/tests/test_contract_mandate.py +++ b/contract_mandate/tests/test_contract_mandate.py @@ -8,36 +8,43 @@ class TestContractMandate(TestContractBase): @classmethod def setUpClass(cls): super(TestContractMandate, cls).setUpClass() - cls.payment_method = cls.env['account.payment.method'].create({ - 'name': 'Test SDD', - 'code': 'test_code_sdd', - 'payment_type': 'inbound', - 'mandate_required': True, - }) - cls.payment_mode = cls.env['account.payment.mode'].create({ - 'name': 'Test payment mode', - 'bank_account_link': 'variable', - 'payment_method_id': cls.payment_method.id, - }) - cls.partner = cls.env['res.partner'].create({ - 'customer': True, - 'name': 'Test Customer', - 'customer_payment_mode_id': cls.payment_mode.id, - }) - cls.partner_bank = cls.env['res.partner.bank'].create({ - 'acc_number': '1234', - 'partner_id': cls.partner.id, - }) - cls.mandate = cls.env['account.banking.mandate'].create({ - 'partner_id': cls.partner.id, - 'partner_bank_id': cls.partner_bank.id, - 'signature_date': '2017-01-01', - }) + cls.payment_method = cls.env["account.payment.method"].create( + { + "name": "Test SDD", + "code": "test_code_sdd", + "payment_type": "inbound", + "mandate_required": True, + } + ) + cls.payment_mode = cls.env["account.payment.mode"].create( + { + "name": "Test payment mode", + "bank_account_link": "variable", + "payment_method_id": cls.payment_method.id, + } + ) + cls.partner = cls.env["res.partner"].create( + { + "customer": True, + "name": "Test Customer", + "customer_payment_mode_id": cls.payment_mode.id, + } + ) + cls.partner_bank = cls.env["res.partner.bank"].create( + {"acc_number": "1234", "partner_id": cls.partner.id,} + ) + cls.mandate = cls.env["account.banking.mandate"].create( + { + "partner_id": cls.partner.id, + "partner_bank_id": cls.partner_bank.id, + "signature_date": "2017-01-01", + } + ) cls.contract_with_mandate = cls.contract2.copy( { - 'partner_id': cls.partner.id, - 'payment_mode_id': cls.payment_mode.id, - 'mandate_id': cls.mandate.id, + "partner_id": cls.partner.id, + "payment_mode_id": cls.payment_mode.id, + "mandate_id": cls.mandate.id, } ) @@ -47,11 +54,9 @@ class TestContractMandate(TestContractBase): def test_contract_not_mandate(self): self.contract_with_mandate.mandate_id = False - self.mandate2 = self.mandate.copy( - {'unique_mandate_reference': 'BM0000XX2'} - ) + self.mandate2 = self.mandate.copy({"unique_mandate_reference": "BM0000XX2"}) self.mandate2.validate() - self.mandate.state = 'expired' + self.mandate.state = "expired" new_invoice = self.contract_with_mandate.recurring_create_invoice() self.assertEqual(new_invoice.mandate_id, self.mandate2) diff --git a/contract_mandate/views/contract_view.xml b/contract_mandate/views/contract_view.xml index 3cc9758ce..9d4201c97 100644 --- a/contract_mandate/views/contract_view.xml +++ b/contract_mandate/views/contract_view.xml @@ -1,20 +1,23 @@ - + - contract.contract form view (in contract_mandate) contract.contract - + - - - + + + -