Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][ADD] account_loan_permanent: Introduce permanent loans functionality #1948

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 129 additions & 0 deletions account_loan_permanent/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
=======================
Account Loan Permanents
=======================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:f717e521a32308ca7b21651dede43dac5e8293df7acf72e522eac6410e730bd7
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
:target: https://odoo-community.org/page/development-status
:alt: Alpha
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--financial--tools-lightgray.png?logo=github
:target: https://github.com/OCA/account-financial-tools/tree/16.0/account_loan_permanent
:alt: OCA/account-financial-tools
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/account-financial-tools-16-0/account-financial-tools-16-0-account_loan_permanent
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/account-financial-tools&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module extends the loan functionality to allow permanent loans that
only settle interests.

.. IMPORTANT::
This is an alpha version, the data model and design can change at any time without warning.
Only for development or testing purpose, do not use in production.
`More details on development status <https://odoo-community.org/page/development-status>`_

**Table of contents**

.. contents::
:local:

Usage
=====

To use this module for permanent loans, follow these steps:

1. Navigate to Invoicing / Accounting > Accounting > Loans.
2. Create a new loan or edit an existing one.
3. Configure the loan by setting the following fields:

- Company
- Loan Type: Select "Only interest" for permanent loans
- Amount
- Rate
- Accounts
- Check the "Is Permanent" checkbox

4. Post the loan. This will automatically create an account move with
the expected amounts.

For permanent loans: - The system will automatically generate new loan
lines to maintain the minimum number of future periods. - Only interest
will be settled, and the principal amount remains constant. - The loan
will continue indefinitely until manually closed or modified.

Additional features: - Generate loan entries: The system can
automatically create account moves for unfinished loans up to a
specified date. - Modify rates: You can adjust rates for unposted lines
if needed. - Extend loan duration: The system will automatically add new
periods to maintain the minimum number of future periods.

Note: Permanent loans can only be of type "Only interest". Attempting to
set a loan as permanent with a different type will result in a warning
message.

Changelog
=========



Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-financial-tools/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/account-financial-tools/issues/new?body=module:%20account_loan_permanent%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* Som IT Cooperatiu SCCL

Contributors
------------

- Nicolás Ramos <[email protected]>

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

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.

.. |maintainer-nramosdev| image:: https://github.com/nramosdev.png?size=40px
:target: https://github.com/nramosdev
:alt: nramosdev

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-nramosdev|

This module is part of the `OCA/account-financial-tools <https://github.com/OCA/account-financial-tools/tree/16.0/account_loan_permanent>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions account_loan_permanent/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
20 changes: 20 additions & 0 deletions account_loan_permanent/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2024 Som IT Cooperatiu SCCL - Nicolás Ramos <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Account Loan Permanents",
"version": "16.0.1.0.0",
"author": "Som IT Cooperatiu SCCL, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-financial-tools",
"license": "AGPL-3",
"summary": "Extension for permanent loans",
"category": "Accounting",
"depends": [
"account_loan",
],
"data": [
"views/account_loan_views.xml",
],
"installable": True,
"maintainers": ["nramosdev"],
"development_status": "Alpha",
}
66 changes: 66 additions & 0 deletions account_loan_permanent/i18n/account_loan_permanents.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * account_loan_permanent
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-10-08 09:28+0000\n"
"PO-Revision-Date: 2024-10-08 09:28+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: account_loan_permanent
#: model:ir.model,name:account_loan_permanent.model_account_loan_line
msgid "Annuity"
msgstr ""

#. module: account_loan_permanent
#: model:ir.model.fields,help:account_loan_permanent.field_account_loan__is_permanent
msgid ""
"If checked, this loan will be treated as a permanent loan. Permanent loans "
"are only allowed for 'Only interest' type loans and will continue generating"
" new periods indefinitely."
msgstr ""

#. module: account_loan_permanent
#. odoo-python
#: code:addons/account_loan_permanent/models/account_loan.py:0
#, python-format
msgid "Invalid Loan Type"
msgstr ""

#. module: account_loan_permanent
#: model:ir.model.fields,field_description:account_loan_permanent.field_account_loan__is_permanent
msgid "Is Permanent"
msgstr ""

#. module: account_loan_permanent
#: model:ir.model,name:account_loan_permanent.model_account_loan
msgid "Loan"
msgstr ""

#. module: account_loan_permanent
#: model:ir.model.fields,field_description:account_loan_permanent.field_account_loan__min_periods
msgid "Minimum Periods"
msgstr ""

#. module: account_loan_permanent
#. odoo-python
#: code:addons/account_loan_permanent/models/account_loan.py:0
#, python-format
msgid "Permanent loans can only be of type 'Only interest'"
msgstr ""

#. module: account_loan_permanent
#: model:ir.model.fields,help:account_loan_permanent.field_account_loan__min_periods
msgid ""
"The minimum number of periods for a permanent loan. This ensures that the "
"loan will have at least this many periods before potentially generating new "
"ones."
msgstr ""
74 changes: 74 additions & 0 deletions account_loan_permanent/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * account_loan_permanent
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-10-08 09:28+0000\n"
"PO-Revision-Date: 2024-10-08 11:32+0200\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 3.4.4\n"

#. module: account_loan_permanent
#: model:ir.model,name:account_loan_permanent.model_account_loan_line
msgid "Annuity"
msgstr "Anualidad"

#. module: account_loan_permanent
#: model:ir.model.fields,help:account_loan_permanent.field_account_loan__is_permanent
msgid ""
"If checked, this loan will be treated as a permanent loan. Permanent loans "
"are only allowed for 'Only interest' type loans and will continue generating "
"new periods indefinitely."
msgstr ""
"Si se comprueba, este préstamo se tratará como un préstamo permanente. Los "
"préstamos permanentes solo están permitidos para préstamos de tipo “solo "
"interés” y continuarán generando nuevos períodos indefinidamente."

#. module: account_loan_permanent
#. odoo-python
#: code:addons/account_loan_permanent/models/account_loan.py:0
#, python-format
msgid "Invalid Loan Type"
msgstr "Tipo De Préstamo No Válido"

#. module: account_loan_permanent
#: model:ir.model.fields,field_description:account_loan_permanent.field_account_loan__is_permanent
msgid "Is Permanent"
msgstr "Es permanente"

#. module: account_loan_permanent
#: model:ir.model,name:account_loan_permanent.model_account_loan
msgid "Loan"
msgstr "Préstamo"

#. module: account_loan_permanent
#: model:ir.model.fields,field_description:account_loan_permanent.field_account_loan__min_periods
msgid "Minimum Periods"
msgstr "Períodos Mínimos"

#. module: account_loan_permanent
#. odoo-python
#: code:addons/account_loan_permanent/models/account_loan.py:0
#, python-format
msgid "Permanent loans can only be of type 'Only interest'"
msgstr "Los préstamos permanentes solo pueden ser del tipo “Solo intereses”"

#. module: account_loan_permanent
#: model:ir.model.fields,help:account_loan_permanent.field_account_loan__min_periods
msgid ""
"The minimum number of periods for a permanent loan. This ensures that the "
"loan will have at least this many periods before potentially generating new "
"ones."
msgstr ""
"El número mínimo de períodos para un préstamo permanente. Esto asegura que "
"el préstamo tenga al menos estos períodos antes de generar potencialmente "
"otros nuevos."
2 changes: 2 additions & 0 deletions account_loan_permanent/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import account_loan
from . import account_loan_line
67 changes: 67 additions & 0 deletions account_loan_permanent/models/account_loan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Copyright 2024 Som IT Cooperatiu SCCL - Nicolás Ramos <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import _, api, fields, models


class AccountLoan(models.Model):
"""Extend account.loan model to add permanent loan functionality."""

_inherit = "account.loan"

is_permanent = fields.Boolean(
default=False,
help="If checked, this loan will be treated as a permanent loan. "
"Permanent loans are only allowed for 'Only interest' type loans "
"and will continue generating new periods indefinitely.",
)
min_periods = fields.Integer(
string="Minimum Periods",
default=60,
help="The minimum number of periods for a permanent loan. "
"This ensures that the loan will have at least this many periods "
"before potentially generating new ones.",
)

@api.onchange("is_permanent", "loan_type")
def _onchange_is_permanent(self):
"""Handle changes in is_permanent and loan_type fields."""
if self.is_permanent and self.loan_type != "interest":
self.is_permanent = False
return {
"warning": {
"title": _("Invalid Loan Type"),
"message": _("Permanent loans can only be of type 'Only interest'"),
}
}
if self.is_permanent:
self.residual_amount = 0
self.periods = max(self.periods, self.min_periods)

def _create(self, data_list):
res = super()._create(data_list)
for loan in res.filtered(lambda l: l.is_permanent):
loan.periods = loan.min_periods
return res

@api.model
def _generate_loan_entries(self, date):
"""
Generate the moves of unfinished loans before date
:param date:
:return:
"""
res = super()._generate_loan_entries(date)
for loan in self.filtered(lambda l: l.is_permanent):
lines = loan.line_ids.filtered(lambda l: l.date <= date and not l.move_ids)
if lines:
res += lines._generate_move()
loan.periods += len(lines)

Check warning on line 59 in account_loan_permanent/models/account_loan.py

View check run for this annotation

Codecov / codecov/patch

account_loan_permanent/models/account_loan.py#L58-L59

Added lines #L58 - L59 were not covered by tests
last_line = loan.line_ids.sorted(key=lambda r: r.sequence)[-1]
while last_line.date <= date:
new_line = self.env["account.loan.line"]._create_next_line(

Check warning on line 62 in account_loan_permanent/models/account_loan.py

View check run for this annotation

Codecov / codecov/patch

account_loan_permanent/models/account_loan.py#L62

Added line #L62 was not covered by tests
last_line
)
last_line = new_line
loan.periods += 1

Check warning on line 66 in account_loan_permanent/models/account_loan.py

View check run for this annotation

Codecov / codecov/patch

account_loan_permanent/models/account_loan.py#L65-L66

Added lines #L65 - L66 were not covered by tests
return res
Loading
Loading