From ead9ba290ac1ca1866564decbde83186fc7f4a67 Mon Sep 17 00:00:00 2001 From: amcor Date: Tue, 28 May 2019 14:28:15 +0200 Subject: [PATCH] [FIX] test date migrations and lint, flake8 and minor changes --- account_loan/model/account_loan.py | 11 +++---- account_loan/model/account_move.py | 4 +-- account_loan/readme/CONTRIBUTORS.rst | 2 +- account_loan/readme/USAGE.rst | 2 +- account_loan/tests/test_loan.py | 32 ++++++------------- .../wizard/account_loan_generate_entries.py | 7 ++-- .../wizard/account_loan_pay_amount.py | 1 - account_loan/wizard/account_loan_post.py | 1 - 8 files changed, 20 insertions(+), 40 deletions(-) diff --git a/account_loan/model/account_loan.py b/account_loan/model/account_loan.py index 70f2b6b1c..2018a194f 100644 --- a/account_loan/model/account_loan.py +++ b/account_loan/model/account_loan.py @@ -2,7 +2,6 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from odoo import api, fields, models -from odoo.tools import DEFAULT_SERVER_DATE_FORMAT as DF from datetime import datetime from dateutil.relativedelta import relativedelta @@ -336,9 +335,8 @@ class AccountLoan(models.Model): @api.onchange('company_id') def _onchange_company(self): self._onchange_is_leasing() - self.interest_expenses_account_id = False - self.short_term_loan_account_id = False - self.long_term_loan_account_id = False + self.interest_expenses_account_id = self.short_term_loan_account_id = \ + self.long_term_loan_account_id = False def get_default_name(self, vals): return self.env['ir.sequence'].next_by_code('account.loan') or '/' @@ -394,12 +392,11 @@ class AccountLoan(models.Model): return final_sequence = min(lines.mapped('sequence')) for line in lines.sorted('sequence', reverse=True): - date = datetime.strptime( - line.date, DF).date() + relativedelta(months=12) + date = line.date + relativedelta(months=12) if self.state == 'draft' or line.sequence != final_sequence: line.long_term_pending_principal_amount = sum( self.line_ids.filtered( - lambda r: datetime.strptime(r.date, DF).date() >= date + lambda r: r.date >= date ).mapped('principal_amount')) line.long_term_principal_amount = ( line.long_term_pending_principal_amount - amount) diff --git a/account_loan/model/account_move.py b/account_loan/model/account_move.py index bd4e298be..3e83fc3e8 100644 --- a/account_loan/model/account_move.py +++ b/account_loan/model/account_move.py @@ -20,8 +20,8 @@ class AccountMove(models.Model): ) @api.multi - def post(self): - res = super().post() + def post(self, invoice=False): + res = super().post(invoice=invoice) for record in self: if record.loan_line_id: record.loan_id = record.loan_line_id.loan_id diff --git a/account_loan/readme/CONTRIBUTORS.rst b/account_loan/readme/CONTRIBUTORS.rst index 014726dc6..42054ecf5 100644 --- a/account_loan/readme/CONTRIBUTORS.rst +++ b/account_loan/readme/CONTRIBUTORS.rst @@ -1,3 +1,3 @@ * Enric Tobella * Bhavesh Odedra -* Alberto Martín Cortada \ No newline at end of file +* Alberto Martín Cortada diff --git a/account_loan/readme/USAGE.rst b/account_loan/readme/USAGE.rst index d5c3bde3f..b19313b48 100644 --- a/account_loan/readme/USAGE.rst +++ b/account_loan/readme/USAGE.rst @@ -15,4 +15,4 @@ On a posted loan you can: .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/92/11.0 \ No newline at end of file + :target: https://runbot.odoo-community.org/runbot/92/11.0 diff --git a/account_loan/tests/test_loan.py b/account_loan/tests/test_loan.py index dba800944..d018e991e 100644 --- a/account_loan/tests/test_loan.py +++ b/account_loan/tests/test_loan.py @@ -4,9 +4,7 @@ from odoo import fields from odoo.exceptions import UserError from odoo.tests import TransactionCase -from odoo.tools import DEFAULT_SERVER_DATE_FORMAT as DF -from datetime import datetime from dateutil.relativedelta import relativedelta import logging @@ -142,36 +140,28 @@ class TestLoan(TransactionCase): 'loan_id': loan.id, 'amount': (amount - amount / periods) / 2, 'fees': 100, - 'date': datetime.strptime( - line.date, DF - ).date() + relativedelta(months=-1) + 'date': line.date + relativedelta(months=-1) }).run() with self.assertRaises(UserError): self.env['account.loan.pay.amount'].create({ 'loan_id': loan.id, 'amount': amount, 'fees': 100, - 'date': datetime.strptime( - line.date, DF - ).date() + 'date': line.date, }).run() with self.assertRaises(UserError): self.env['account.loan.pay.amount'].create({ 'loan_id': loan.id, 'amount': 0, 'fees': 100, - 'date': datetime.strptime( - line.date, DF - ).date() + 'date': line.date, }).run() with self.assertRaises(UserError): self.env['account.loan.pay.amount'].create({ 'loan_id': loan.id, 'amount': -100, 'fees': 100, - 'date': datetime.strptime( - line.date, DF - ).date() + 'date': line.date, }).run() def test_fixed_annuity_loan(self): @@ -258,9 +248,9 @@ class TestLoan(TransactionCase): 'loan_id': loan.id, 'amount': (amount - amount / periods) / 2, 'fees': 100, - 'date': datetime.strptime( - loan.line_ids.filtered(lambda r: r.sequence == 1).date, DF - ).date() + relativedelta(months=-1) + 'date': loan.line_ids.filtered( + lambda r: r.sequence == 1 + ).date + relativedelta(months=-1) }).run() line.invoice_ids.action_invoice_open() self.assertTrue(line.has_moves) @@ -345,9 +335,7 @@ class TestLoan(TransactionCase): self.assertEqual(loan.interests_amount, 0) self.assertEqual(loan.pending_principal_amount, amount) self.assertFalse(loan.line_ids.filtered( - lambda r: ( - datetime.strptime(r.date, DF).date() <= - datetime.strptime(loan.start_date, DF).date()))) + lambda r: r.date <= loan.start_date)) for line in loan.line_ids: self.assertEqual(loan.state, 'posted') line.view_process_values() @@ -396,11 +384,11 @@ class TestLoan(TransactionCase): 'reconcile': True, }) - def create_loan(self, type, amount, rate, periods): + def create_loan(self, type_loan, amount, rate, periods): loan = self.env['account.loan'].create({ 'journal_id': self.journal.id, 'rate_type': 'napr', - 'loan_type': type, + 'loan_type': type_loan, 'loan_amount': amount, 'payment_on_first_period': True, 'rate': rate, diff --git a/account_loan/wizard/account_loan_generate_entries.py b/account_loan/wizard/account_loan_generate_entries.py index ce5e8bc86..c4ec41da7 100644 --- a/account_loan/wizard/account_loan_generate_entries.py +++ b/account_loan/wizard/account_loan_generate_entries.py @@ -1,10 +1,6 @@ -# -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. from odoo import api, fields, models -from odoo.tools import DEFAULT_SERVER_DATE_FORMAT as DF - -from datetime import datetime class AccountLoanGenerateWizard(models.TransientModel): @@ -23,7 +19,8 @@ class AccountLoanGenerateWizard(models.TransientModel): def run_leasing(self): created_ids = self.env['account.loan'].generate_leasing_entries( - datetime.strptime(self.date, DF).date()) + self.date + ) action = self.env.ref('account.action_invoice_tree2') result = action.read()[0] if len(created_ids) == 0: diff --git a/account_loan/wizard/account_loan_pay_amount.py b/account_loan/wizard/account_loan_pay_amount.py index 7c0d9fea1..6dd2164a1 100644 --- a/account_loan/wizard/account_loan_pay_amount.py +++ b/account_loan/wizard/account_loan_pay_amount.py @@ -1,4 +1,3 @@ -# Copyright 2018 Creu Blanca # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from odoo import api, fields, models, _ diff --git a/account_loan/wizard/account_loan_post.py b/account_loan/wizard/account_loan_post.py index ae7a6027b..bde773626 100644 --- a/account_loan/wizard/account_loan_post.py +++ b/account_loan/wizard/account_loan_post.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. from odoo import api, fields, models, _