mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
[FIX] test date migrations and lint, flake8 and minor changes
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
* Enric Tobella <etobella@creublanca.es>
|
||||
* Bhavesh Odedra <bodedra@opensourceintegrators.com>
|
||||
* Alberto Martín Cortada <alberto.martin@guadaltech.es>
|
||||
* Alberto Martín Cortada <alberto.martin@guadaltech.es>
|
||||
|
||||
@@ -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
|
||||
:target: https://runbot.odoo-community.org/runbot/92/11.0
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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, _
|
||||
|
||||
@@ -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, _
|
||||
|
||||
Reference in New Issue
Block a user