From f636a9f18848358ba4bc90d4461288ea86e38490 Mon Sep 17 00:00:00 2001 From: Luis Felipe Mileo Date: Thu, 19 Dec 2019 10:40:21 -0300 Subject: [PATCH] [IMP] black, isort --- l10n_br_account_payment_order/__manifest__.py | 41 +++++---- .../demo/account_payment_order_demo.xml | 2 +- .../models/account_move_line.py | 14 +-- .../models/account_payment_line.py | 63 ++++++++----- .../models/account_payment_mode.py | 19 ++-- .../models/res_partner_bank.py | 18 ++-- .../readme/CONFIGURE.rst | 2 +- .../readme/CONTRIBUTORS.rst | 1 - .../readme/CREDITS.rst | 2 +- .../readme/HISTORY.rst | 2 +- .../tests/test_payment_order.py | 90 ++++++++++--------- 11 files changed, 136 insertions(+), 118 deletions(-) diff --git a/l10n_br_account_payment_order/__manifest__.py b/l10n_br_account_payment_order/__manifest__.py index 64295dad1712..05c677ec66e2 100644 --- a/l10n_br_account_payment_order/__manifest__.py +++ b/l10n_br_account_payment_order/__manifest__.py @@ -3,28 +3,27 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { - 'name': 'Brazilian Payment Order', - 'version': '12.0.1.0.0', - 'license': 'AGPL-3', - 'author': "KMEE, " - "Odoo Community Association (OCA)", - 'website': 'https://github.com/OCA/l10n-brazil', - 'category': 'Banking addons', - 'depends': [ - 'l10n_br_base', - 'account_payment_order', - 'account_due_list', - 'account_cancel', + "name": "Brazilian Payment Order", + "version": "12.0.1.0.0", + "license": "AGPL-3", + "author": "KMEE, " "Odoo Community Association (OCA)", + "website": "https://github.com/OCA/l10n-brazil", + "category": "Banking addons", + "depends": [ + "l10n_br_base", + "account_payment_order", + "account_due_list", + "account_cancel", ], - 'data': [ - 'views/account_payment_order_menu_views.xml', - 'views/account_due_list.xml', - 'views/account_payment_line.xml', - 'views/account_payment_mode.xml', + "data": [ + "views/account_payment_order_menu_views.xml", + "views/account_due_list.xml", + "views/account_payment_line.xml", + "views/account_payment_mode.xml", ], - 'demo': [ - 'demo/account_payment_order_demo.xml', - 'demo/account_payment_mode_demo.xml' + "demo": [ + "demo/account_payment_order_demo.xml", + "demo/account_payment_mode_demo.xml", ], - 'installable': True, + "installable": True, } diff --git a/l10n_br_account_payment_order/demo/account_payment_order_demo.xml b/l10n_br_account_payment_order/demo/account_payment_order_demo.xml index 2c4039de0806..86e7bb2e80dc 100644 --- a/l10n_br_account_payment_order/demo/account_payment_order_demo.xml +++ b/l10n_br_account_payment_order/demo/account_payment_order_demo.xml @@ -30,4 +30,4 @@ - \ No newline at end of file + diff --git a/l10n_br_account_payment_order/models/account_move_line.py b/l10n_br_account_payment_order/models/account_move_line.py index 737c890bb073..143949a6b026 100644 --- a/l10n_br_account_payment_order/models/account_move_line.py +++ b/l10n_br_account_payment_order/models/account_move_line.py @@ -2,15 +2,15 @@ # Luis Felipe Miléo - mileo@kmee.com.br # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import models, fields, api +from odoo import api, fields, models class AccountMoveLine(models.Model): - _inherit = 'account.move.line' + _inherit = "account.move.line" - date_scheduled = fields.Date(string='Data Prevista') + date_scheduled = fields.Date(string="Data Prevista") - @api.depends('move_id') + @api.depends("move_id") def _compute_journal_entry_ref(self): for record in self: if record.name: @@ -20,11 +20,11 @@ def _compute_journal_entry_ref(self): elif record.invoice_id and record.invoice_id.number: record.journal_entry_ref = record.invoice_id.number else: - record.journal_entry_ref = '*' + str(record.move_id.id) + record.journal_entry_ref = "*" + str(record.move_id.id) journal_entry_ref = fields.Char( - compute='_compute_journal_entry_ref', - string='Journal Entry Ref', store=True) + compute="_compute_journal_entry_ref", string="Journal Entry Ref", store=True + ) @api.multi def get_balance(self): diff --git a/l10n_br_account_payment_order/models/account_payment_line.py b/l10n_br_account_payment_order/models/account_payment_line.py index 3dea69205e11..7ed6ca86d9a9 100644 --- a/l10n_br_account_payment_order/models/account_payment_line.py +++ b/l10n_br_account_payment_order/models/account_payment_line.py @@ -2,44 +2,59 @@ # Luis Felipe Miléo - mileo@kmee.com.br # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import models, fields, api +from odoo import api, fields, models from odoo.addons import decimal_precision as dp from odoo.tools.float_utils import float_round as round class PaymentLine(models.Model): - _inherit = 'account.payment.line' + _inherit = "account.payment.line" @api.model def _get_info_partner(self, partner_record): if not partner_record: return False - st = partner_record.street or '' - n = partner_record.street_number or '' - st1 = partner_record.street2 or '' - zip = partner_record.zip or '' - city = partner_record.city_id.name or '' - uf = partner_record.state_id.code or '' - zip_city = city + '-' + uf + '\n' + zip - cntry = partner_record.country_id and \ - partner_record.country_id.name or '' - cnpj = partner_record.cnpj_cpf or '' - return partner_record.legal_name or '' + "\n" + cnpj + "\n" + st \ - + ", " + n + " " + st1 + "\n" + zip_city + "\n" + cntry + st = partner_record.street or "" + n = partner_record.street_number or "" + st1 = partner_record.street2 or "" + zip = partner_record.zip or "" + city = partner_record.city_id.name or "" + uf = partner_record.state_id.code or "" + zip_city = city + "-" + uf + "\n" + zip + cntry = partner_record.country_id and partner_record.country_id.name or "" + cnpj = partner_record.cnpj_cpf or "" + return ( + partner_record.legal_name + or "" + + "\n" + + cnpj + + "\n" + + st + + ", " + + n + + " " + + st1 + + "\n" + + zip_city + + "\n" + + cntry + ) @api.multi - @api.depends('percent_interest', 'amount_currency') + @api.depends("percent_interest", "amount_currency") def _compute_interest(self): for record in self: - precision = record.env[ - 'decimal.precision'].precision_get('Account') + precision = record.env["decimal.precision"].precision_get("Account") record.amount_interest = round( - record.amount_currency * ( - record.percent_interest / 100), precision) + record.amount_currency * (record.percent_interest / 100), precision + ) linha_digitavel = fields.Char(string="Linha Digitável") - percent_interest = fields.Float(string="Percentual de Juros", - digits=dp.get_precision('Account')) - amount_interest = fields.Float(string="Valor Juros", - compute='_compute_interest', - digits=dp.get_precision('Account')) + percent_interest = fields.Float( + string="Percentual de Juros", digits=dp.get_precision("Account") + ) + amount_interest = fields.Float( + string="Valor Juros", + compute="_compute_interest", + digits=dp.get_precision("Account"), + ) diff --git a/l10n_br_account_payment_order/models/account_payment_mode.py b/l10n_br_account_payment_order/models/account_payment_mode.py index 1beccef94ff2..2d55d5727680 100644 --- a/l10n_br_account_payment_order/models/account_payment_mode.py +++ b/l10n_br_account_payment_order/models/account_payment_mode.py @@ -2,19 +2,20 @@ # @author Luis Felipe Miléo - mileo@kmee.com.br # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import models, fields +from odoo import fields, models class AccountPaymentMode(models.Model): - _inherit = 'account.payment.mode' + _inherit = "account.payment.mode" - internal_sequence_id = fields.Many2one('ir.sequence', 'Sequência') - instrucoes = fields.Text('Instruções de cobrança') - invoice_print = fields.Boolean( - 'Gerar relatorio na conclusão da fatura?') + internal_sequence_id = fields.Many2one("ir.sequence", "Sequência") + instrucoes = fields.Text("Instruções de cobrança") + invoice_print = fields.Boolean("Gerar relatorio na conclusão da fatura?") _sql_constraints = [ - ('internal_sequence_id_unique', - 'unique(internal_sequence_id)', - 'Sequência já usada! Crie uma sequência unica para cada modo') + ( + "internal_sequence_id_unique", + "unique(internal_sequence_id)", + "Sequência já usada! Crie uma sequência unica para cada modo", + ) ] diff --git a/l10n_br_account_payment_order/models/res_partner_bank.py b/l10n_br_account_payment_order/models/res_partner_bank.py index 5c275ba410aa..87d7b594726d 100644 --- a/l10n_br_account_payment_order/models/res_partner_bank.py +++ b/l10n_br_account_payment_order/models/res_partner_bank.py @@ -2,20 +2,22 @@ # Magno Costa # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) -from odoo import models, api, _ +from odoo import _, api, models from odoo.exceptions import Warning as UserError class ResPartnerBank(models.Model): - _inherit = 'res.partner.bank' + _inherit = "res.partner.bank" @api.multi - @api.constrains('bra_number') + @api.constrains("bra_number") def check_bra_number(self): for record in self: - if record.bank_id.code_bc == '033': + if record.bank_id.code_bc == "033": if len(record.bra_number) > 4: - raise UserError(_( - u'O cógido da Agencia Bancaria do Santander' - u' deve ter no máximo quatro caracteres.' - )) + raise UserError( + _( + u"O cógido da Agencia Bancaria do Santander" + u" deve ter no máximo quatro caracteres." + ) + ) diff --git a/l10n_br_account_payment_order/readme/CONFIGURE.rst b/l10n_br_account_payment_order/readme/CONFIGURE.rst index 1b48c9c3b603..e7dc235973ab 100644 --- a/l10n_br_account_payment_order/readme/CONFIGURE.rst +++ b/l10n_br_account_payment_order/readme/CONFIGURE.rst @@ -1 +1 @@ -No configuration required. \ No newline at end of file +No configuration required. diff --git a/l10n_br_account_payment_order/readme/CONTRIBUTORS.rst b/l10n_br_account_payment_order/readme/CONTRIBUTORS.rst index 87a88f53e92c..15e157d0dc85 100644 --- a/l10n_br_account_payment_order/readme/CONTRIBUTORS.rst +++ b/l10n_br_account_payment_order/readme/CONTRIBUTORS.rst @@ -2,4 +2,3 @@ * Fernando Marcato * Hendrix Costa * Magno Costa - diff --git a/l10n_br_account_payment_order/readme/CREDITS.rst b/l10n_br_account_payment_order/readme/CREDITS.rst index 186f5e96a375..a9acbd0203b2 100644 --- a/l10n_br_account_payment_order/readme/CREDITS.rst +++ b/l10n_br_account_payment_order/readme/CREDITS.rst @@ -1,4 +1,4 @@ The development of this module has been financially supported by: * KMEE INFORMATICA LTDA - www.kmee.com.br -* AKRETION LTDA - www.akretion.com \ No newline at end of file +* AKRETION LTDA - www.akretion.com diff --git a/l10n_br_account_payment_order/readme/HISTORY.rst b/l10n_br_account_payment_order/readme/HISTORY.rst index f9edf64f0b04..495eb888ddb3 100644 --- a/l10n_br_account_payment_order/readme/HISTORY.rst +++ b/l10n_br_account_payment_order/readme/HISTORY.rst @@ -27,4 +27,4 @@ 12.0.1.0.0 (2019-06-06) ~~~~~~~~~~~~~~~~~~~~~~~ -* [MIG] Migração para a versão 12.0. \ No newline at end of file +* [MIG] Migração para a versão 12.0. diff --git a/l10n_br_account_payment_order/tests/test_payment_order.py b/l10n_br_account_payment_order/tests/test_payment_order.py index 2587c30f7965..231d924a6776 100644 --- a/l10n_br_account_payment_order/tests/test_payment_order.py +++ b/l10n_br_account_payment_order/tests/test_payment_order.py @@ -3,26 +3,25 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) -from openerp.tests.common import TransactionCase from openerp.exceptions import UserError, ValidationError +from openerp.tests.common import TransactionCase class TestPaymentOrder(TransactionCase): - def setUp(self): super(TestPaymentOrder, self).setUp() # Get Invoice for test self.invoice_customer_original = self.env.ref( - 'l10n_br_account_payment_order.demo_invoice_payment_order' + "l10n_br_account_payment_order.demo_invoice_payment_order" ) # Payment Mode self.payment_mode = self.env.ref( - 'account_payment_mode.payment_mode_inbound_ct1' + "account_payment_mode.payment_mode_inbound_ct1" ) - self.env['account.payment.order'].search([]) + self.env["account.payment.order"].search([]) # Configure to be possibile create Payment Order self.payment_mode.payment_order_ok = True @@ -33,79 +32,82 @@ def setUp(self): self.invoice_customer_original.journal_id.update_posted = True # I check that Initially customer invoice is in the "Draft" state - self.assertEquals(self.invoice_customer_original.state, 'draft') + self.assertEquals(self.invoice_customer_original.state, "draft") # I validate invoice by creating on self.invoice_customer_original.action_invoice_open() # I check that the invoice state is "Open" - self.assertEquals(self.invoice_customer_original.state, 'open') + self.assertEquals(self.invoice_customer_original.state, "open") # I check that now there is a move attached to the invoice - assert self.invoice_customer_original.move_id,\ - "Move not created for open invoice" + assert ( + self.invoice_customer_original.move_id + ), "Move not created for open invoice" def test_implemented_fields_payment_order(self): """ Test implemented fields in object account.move.line """ # Check Payment Mode field - assert self.invoice_customer_original.payment_mode_id, \ - "Payment Mode field is not filled." + assert ( + self.invoice_customer_original.payment_mode_id + ), "Payment Mode field is not filled." # Change status of Move to draft just to test self.invoice_customer_original.move_id.button_cancel() for line in self.invoice_customer_original.move_id.line_ids.filtered( - lambda l: l.account_id.id == - self.invoice_customer_original.account_id.id): + lambda l: l.account_id.id == self.invoice_customer_original.account_id.id + ): self.assertEquals( - line.journal_entry_ref, line.invoice_id.name, - "Error with compute field journal_entry_ref") + line.journal_entry_ref, + line.invoice_id.name, + "Error with compute field journal_entry_ref", + ) test_balance_value = line.get_balance() # Return the status of Move to Posted self.invoice_customer_original.move_id.action_post() for line in self.invoice_customer_original.move_id.line_ids.filtered( - lambda l: l.account_id.id == - self.invoice_customer_original.account_id.id): + lambda l: l.account_id.id == self.invoice_customer_original.account_id.id + ): self.assertEquals( - line.journal_entry_ref, line.invoice_id.name, - "Error with compute field journal_entry_ref") + line.journal_entry_ref, + line.invoice_id.name, + "Error with compute field journal_entry_ref", + ) test_balance_value = line.get_balance() - self.assertEquals( - test_balance_value, 300.0, - "Error with method get_balance()") + self.assertEquals(test_balance_value, 300.0, "Error with method get_balance()") def test_cancel_payment_order(self): """ Test create and cancel a Payment Order.""" # Add to payment order self.invoice_customer_original.create_account_payment_line() - payment_order = self.env['account.payment.order'].search([]) - bank_journal = self.env['account.journal'].search( - [('type', '=', 'bank')], limit=1) + payment_order = self.env["account.payment.order"].search([]) + bank_journal = self.env["account.journal"].search( + [("type", "=", "bank")], limit=1 + ) # Set journal to allow cancelling entries bank_journal.update_posted = True - payment_order.write({ - 'journal_id': bank_journal.id - }) + payment_order.write({"journal_id": bank_journal.id}) self.assertEquals(len(payment_order.payment_line_ids), 2) self.assertEquals(len(payment_order.bank_line_ids), 0) for line in payment_order.payment_line_ids: line.percent_interest = 1.5 - self.assertEquals(line._get_info_partner( - self.invoice_customer_original.partner_id), - 'AKRETION LTDA', - "Error with method _get_info_partner" + self.assertEquals( + line._get_info_partner(self.invoice_customer_original.partner_id), + "AKRETION LTDA", + "Error with method _get_info_partner", ) test_amount_interest = line.amount_interest self.assertEquals( - test_amount_interest, 4.5, - "Error with compute field amount_interest.") + test_amount_interest, 4.5, "Error with compute field amount_interest." + ) # Open payment order payment_order.draft2open() @@ -116,7 +118,7 @@ def test_cancel_payment_order(self): payment_order.open2generated() payment_order.generated2uploaded() - self.assertEquals(payment_order.state, 'uploaded') + self.assertEquals(payment_order.state, "uploaded") with self.assertRaises(UserError): payment_order.unlink() @@ -126,20 +128,20 @@ def test_cancel_payment_order(self): bank_line.unlink() payment_order.action_done_cancel() - self.assertEquals(payment_order.state, 'cancel') + self.assertEquals(payment_order.state, "cancel") payment_order.unlink() - self.assertEquals(len(self.env['account.payment.order'].search([])), 0) + self.assertEquals(len(self.env["account.payment.order"].search([])), 0) def test_bra_number_constrains(self): """ Test bra_number constrains. """ - self.banco_bradesco = self.env[ - 'res.bank'].search([('code_bc', '=', '033')]) + self.banco_bradesco = self.env["res.bank"].search([("code_bc", "=", "033")]) with self.assertRaises(ValidationError): - self.env[ - 'res.partner.bank'].create(dict( + self.env["res.partner.bank"].create( + dict( bank_id=self.banco_bradesco.id, - partner_id=self.ref('l10n_br_base.res_partner_akretion'), - bra_number='12345' - )) + partner_id=self.ref("l10n_br_base.res_partner_akretion"), + bra_number="12345", + ) + )