[IMP] account_loan: Allow to increase the amount of the loan

[UPD] Update account_loan.pot

[BOT] post-merge updates
This commit is contained in:
Enric Tobella
2023-09-15 12:28:54 +02:00
committed by Víctor Martínez
parent ab4999daaa
commit c3b98b1492
12 changed files with 491 additions and 105 deletions

View File

@@ -7,7 +7,7 @@ Account Loan management
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:c9f87eb07ebda20ab00e0446ae5e5908b6a64086fd868f2bfc58e4e9f7dc68b0
!! source digest: sha256:95234840632690af02753b03c14b05c13899c8ee92ebd9e394694d91f0212461
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
@@ -51,7 +51,7 @@ Usage
To use this module, you need to:
#. Go to `Invoicing / Accounting > Adviser > Loans`
#. Go to `Invoicing / Accounting > Accounting > Loans`
#. Configure a loan selecting the company, loan type, amount, rate and accounts
#. Post the loan, it will automatically create an account move with the
expected amounts

View File

@@ -9,6 +9,7 @@
"category": "Accounting",
"depends": ["account"],
"data": [
"wizards/account_loan_increase_amount.xml",
"data/ir_sequence_data.xml",
"security/ir.model.access.csv",
"security/account_loan_security.xml",

View File

@@ -4,7 +4,7 @@
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0\n"
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
@@ -14,6 +14,26 @@ msgstr ""
"Plural-Forms: \n"
#. module: account_loan
#: model_terms:ir.ui.view,arch_db:account_loan.account_loan_form
msgid ""
"<span class=\"o_stat_text\">Deduct</span>\n"
" <span class=\"o_stat_text\">Debt</span>"
msgstr ""
#. module: account_loan
#: model_terms:ir.ui.view,arch_db:account_loan.account_loan_form
msgid ""
"<span class=\"o_stat_text\">Increase</span>\n"
" <span class=\"o_stat_text\">Debt</span>"
msgstr ""
#. module: account_loan
#: model_terms:ir.ui.view,arch_db:account_loan.res_partner_form_view
msgid "<span class=\"o_stat_text\">Loans</span>"
msgstr ""
#. module: account_loan
#: model:ir.model.fields,field_description:account_loan.field_account_loan_increase_amount__account_id
#: model:ir.model.fields,field_description:account_loan.field_account_loan_post__account_id
msgid "Account"
msgstr ""
@@ -70,19 +90,23 @@ msgid "Activity Type Icon"
msgstr ""
#. module: account_loan
#: code:addons/account_loan/wizard/account_loan_pay_amount.py:0
#. odoo-python
#: code:addons/account_loan/wizards/account_loan_pay_amount.py:0
#, python-format
msgid "Amount cannot be bigger than debt"
msgstr ""
#. module: account_loan
#: code:addons/account_loan/wizard/account_loan_pay_amount.py:0
#. odoo-python
#: code:addons/account_loan/wizards/account_loan_increase_amount.py:0
#: code:addons/account_loan/wizards/account_loan_pay_amount.py:0
#, python-format
msgid "Amount cannot be less than zero"
msgstr ""
#. module: account_loan
#: code:addons/account_loan/model/account_loan_line.py:0
#. odoo-python
#: code:addons/account_loan/models/account_loan_line.py:0
#, python-format
msgid "Amount cannot be recomputed if moves or invoices exists already"
msgstr ""
@@ -103,6 +127,7 @@ msgid "Amount that will reduce the pending loan amount on long term"
msgstr ""
#. module: account_loan
#: model:ir.model.fields,field_description:account_loan.field_account_loan_increase_amount__amount
#: model:ir.model.fields,field_description:account_loan.field_account_loan_pay_amount__amount
msgid "Amount to reduce from Principal"
msgstr ""
@@ -124,6 +149,7 @@ msgstr ""
#. module: account_loan
#: model_terms:ir.ui.view,arch_db:account_loan.account_loan_generate_wizard_form
#: model_terms:ir.ui.view,arch_db:account_loan.account_loan_increase_amount_form_view
#: model_terms:ir.ui.view,arch_db:account_loan.account_loan_pay_amount_form
#: model_terms:ir.ui.view,arch_db:account_loan.account_loan_post_form
msgid "Cancel"
@@ -166,9 +192,15 @@ msgstr ""
msgid "Compute items"
msgstr ""
#. module: account_loan
#: model:ir.model,name:account_loan.model_res_partner
msgid "Contact"
msgstr ""
#. module: account_loan
#: model:ir.model.fields,field_description:account_loan.field_account_loan__create_uid
#: model:ir.model.fields,field_description:account_loan.field_account_loan_generate_wizard__create_uid
#: model:ir.model.fields,field_description:account_loan.field_account_loan_increase_amount__create_uid
#: model:ir.model.fields,field_description:account_loan.field_account_loan_line__create_uid
#: model:ir.model.fields,field_description:account_loan.field_account_loan_pay_amount__create_uid
#: model:ir.model.fields,field_description:account_loan.field_account_loan_post__create_uid
@@ -178,6 +210,7 @@ msgstr ""
#. module: account_loan
#: model:ir.model.fields,field_description:account_loan.field_account_loan__create_date
#: model:ir.model.fields,field_description:account_loan.field_account_loan_generate_wizard__create_date
#: model:ir.model.fields,field_description:account_loan.field_account_loan_increase_amount__create_date
#: model:ir.model.fields,field_description:account_loan.field_account_loan_line__create_date
#: model:ir.model.fields,field_description:account_loan.field_account_loan_pay_amount__create_date
#: model:ir.model.fields,field_description:account_loan.field_account_loan_post__create_date
@@ -186,6 +219,7 @@ msgstr ""
#. module: account_loan
#: model:ir.model.fields,field_description:account_loan.field_account_loan__currency_id
#: model:ir.model.fields,field_description:account_loan.field_account_loan_increase_amount__currency_id
#: model:ir.model.fields,field_description:account_loan.field_account_loan_line__currency_id
#: model:ir.model.fields,field_description:account_loan.field_account_loan_pay_amount__currency_id
msgid "Currency"
@@ -197,6 +231,7 @@ msgid "Currently applied rate"
msgstr ""
#. module: account_loan
#: model:ir.model.fields,field_description:account_loan.field_account_loan_increase_amount__date
#: model:ir.model.fields,field_description:account_loan.field_account_loan_line__date
#: model:ir.model.fields,field_description:account_loan.field_account_loan_pay_amount__date
msgid "Date"
@@ -210,10 +245,10 @@ msgstr ""
#. module: account_loan
#: model:ir.model.fields,field_description:account_loan.field_account_loan__display_name
#: model:ir.model.fields,field_description:account_loan.field_account_loan_generate_wizard__display_name
#: model:ir.model.fields,field_description:account_loan.field_account_loan_increase_amount__display_name
#: model:ir.model.fields,field_description:account_loan.field_account_loan_line__display_name
#: model:ir.model.fields,field_description:account_loan.field_account_loan_pay_amount__display_name
#: model:ir.model.fields,field_description:account_loan.field_account_loan_post__display_name
#: model:ir.model.fields,field_description:account_loan.field_account_move__display_name
msgid "Display Name"
msgstr ""
@@ -267,11 +302,6 @@ msgstr ""
msgid "Followers"
msgstr ""
#. module: account_loan
#: model:ir.model.fields,field_description:account_loan.field_account_loan__message_channel_ids
msgid "Followers (Channels)"
msgstr ""
#. module: account_loan
#: model:ir.model.fields,field_description:account_loan.field_account_loan__message_partner_ids
msgid "Followers (Partners)"
@@ -298,18 +328,29 @@ msgstr ""
msgid "Has Invoices"
msgstr ""
#. module: account_loan
#: model:ir.model.fields,field_description:account_loan.field_account_loan__has_message
msgid "Has Message"
msgstr ""
#. module: account_loan
#: model:ir.model.fields,field_description:account_loan.field_account_loan_line__has_moves
msgid "Has Moves"
msgstr ""
#. module: account_loan
#: model:ir.model.fields,help:account_loan.field_res_partner__lended_loan_count
#: model:ir.model.fields,help:account_loan.field_res_users__lended_loan_count
msgid "How many Loans this partner lended to us ?"
msgstr ""
#. module: account_loan
#: model:ir.model.fields,field_description:account_loan.field_account_loan__id
#: model:ir.model.fields,field_description:account_loan.field_account_loan_generate_wizard__id
#: model:ir.model.fields,field_description:account_loan.field_account_loan_increase_amount__id
#: model:ir.model.fields,field_description:account_loan.field_account_loan_line__id
#: model:ir.model.fields,field_description:account_loan.field_account_loan_pay_amount__id
#: model:ir.model.fields,field_description:account_loan.field_account_loan_post__id
#: model:ir.model.fields,field_description:account_loan.field_account_move__id
msgid "ID"
msgstr ""
@@ -325,7 +366,6 @@ msgstr ""
#. module: account_loan
#: model:ir.model.fields,help:account_loan.field_account_loan__message_needaction
#: model:ir.model.fields,help:account_loan.field_account_loan__message_unread
msgid "If checked, new messages require your attention."
msgstr ""
@@ -335,6 +375,16 @@ msgstr ""
msgid "If checked, some messages have a delivery error."
msgstr ""
#. module: account_loan
#: model:ir.actions.act_window,name:account_loan.account_loan_increase_amount_act_window
msgid "Increase Amount"
msgstr ""
#. module: account_loan
#: model:ir.model,name:account_loan.model_account_loan_increase_amount
msgid "Increase the debt of a loan"
msgstr ""
#. module: account_loan
#: model:ir.model.fields,field_description:account_loan.field_account_loan__interests_product_id
msgid "Interest product"
@@ -378,6 +428,7 @@ msgstr ""
#. module: account_loan
#: model:ir.model.fields,field_description:account_loan.field_account_loan__journal_id
#: model:ir.model.fields,field_description:account_loan.field_account_loan_increase_amount__journal_id
#: model:ir.model.fields,field_description:account_loan.field_account_loan_post__journal_id
msgid "Journal"
msgstr ""
@@ -395,16 +446,17 @@ msgstr ""
#. module: account_loan
#: model:ir.model.fields,field_description:account_loan.field_account_loan____last_update
#: model:ir.model.fields,field_description:account_loan.field_account_loan_generate_wizard____last_update
#: model:ir.model.fields,field_description:account_loan.field_account_loan_increase_amount____last_update
#: model:ir.model.fields,field_description:account_loan.field_account_loan_line____last_update
#: model:ir.model.fields,field_description:account_loan.field_account_loan_pay_amount____last_update
#: model:ir.model.fields,field_description:account_loan.field_account_loan_post____last_update
#: model:ir.model.fields,field_description:account_loan.field_account_move____last_update
msgid "Last Modified on"
msgstr ""
#. module: account_loan
#: model:ir.model.fields,field_description:account_loan.field_account_loan__write_uid
#: model:ir.model.fields,field_description:account_loan.field_account_loan_generate_wizard__write_uid
#: model:ir.model.fields,field_description:account_loan.field_account_loan_increase_amount__write_uid
#: model:ir.model.fields,field_description:account_loan.field_account_loan_line__write_uid
#: model:ir.model.fields,field_description:account_loan.field_account_loan_pay_amount__write_uid
#: model:ir.model.fields,field_description:account_loan.field_account_loan_post__write_uid
@@ -414,6 +466,7 @@ msgstr ""
#. module: account_loan
#: model:ir.model.fields,field_description:account_loan.field_account_loan__write_date
#: model:ir.model.fields,field_description:account_loan.field_account_loan_generate_wizard__write_date
#: model:ir.model.fields,field_description:account_loan.field_account_loan_increase_amount__write_date
#: model:ir.model.fields,field_description:account_loan.field_account_loan_line__write_date
#: model:ir.model.fields,field_description:account_loan.field_account_loan_pay_amount__write_date
#: model:ir.model.fields,field_description:account_loan.field_account_loan_post__write_date
@@ -435,6 +488,18 @@ msgstr ""
msgid "Leasings"
msgstr ""
#. module: account_loan
#: model:ir.model.fields,field_description:account_loan.field_res_partner__lended_loan_ids
#: model:ir.model.fields,field_description:account_loan.field_res_users__lended_loan_ids
msgid "Lended Loan"
msgstr ""
#. module: account_loan
#: model:ir.model.fields,field_description:account_loan.field_res_partner__lended_loan_count
#: model:ir.model.fields,field_description:account_loan.field_res_users__lended_loan_count
msgid "Lended Loan Count"
msgstr ""
#. module: account_loan
#: model:ir.model.fields,field_description:account_loan.field_account_loan__partner_id
msgid "Lender"
@@ -448,12 +513,12 @@ msgstr ""
#. module: account_loan
#: model:ir.model,name:account_loan.model_account_loan
#: model:ir.model.fields,field_description:account_loan.field_account_bank_statement_line__loan_id
#: model:ir.model.fields,field_description:account_loan.field_account_loan_increase_amount__loan_id
#: model:ir.model.fields,field_description:account_loan.field_account_loan_line__loan_id
#: model:ir.model.fields,field_description:account_loan.field_account_loan_pay_amount__loan_id
#: model:ir.model.fields,field_description:account_loan.field_account_loan_post__loan_id
#: model:ir.model.fields,field_description:account_loan.field_account_move__loan_id
#: model:ir.model.fields,field_description:account_loan.field_account_payment__loan_id
#: model_terms:ir.ui.view,arch_db:account_loan.account_loan_form
msgid "Loan"
msgstr ""
@@ -481,11 +546,6 @@ msgstr ""
msgid "Loan generate wizard"
msgstr ""
#. module: account_loan
#: model_terms:ir.ui.view,arch_db:account_loan.account_loan_line_tree
msgid "Loan items"
msgstr ""
#. module: account_loan
#: model:ir.model.constraint,message:account_loan.constraint_account_loan_name_uniq
msgid "Loan name must be unique"
@@ -510,7 +570,6 @@ msgstr ""
#: model:ir.actions.act_window,name:account_loan.account_loan_action
#: model:ir.model.fields.selection,name:account_loan.selection__account_loan_generate_wizard__loan_type__loan
#: model:ir.ui.menu,name:account_loan.account_loan_menu
#: model_terms:ir.ui.view,arch_db:account_loan.account_loan_tree
msgid "Loans"
msgstr ""
@@ -610,7 +669,7 @@ msgstr ""
#. module: account_loan
#: model:ir.model.fields,help:account_loan.field_account_loan__message_needaction_counter
msgid "Number of messages which requires an action"
msgid "Number of messages requiring action"
msgstr ""
#. module: account_loan
@@ -623,25 +682,20 @@ msgstr ""
msgid "Number of periods that the loan will last"
msgstr ""
#. module: account_loan
#: model:ir.model.fields,help:account_loan.field_account_loan__message_unread_counter
msgid "Number of unread messages"
msgstr ""
#. module: account_loan
#: model:ir.model.fields.selection,name:account_loan.selection__account_loan__loan_type__interest
msgid "Only interest"
msgstr ""
#. module: account_loan
#: code:addons/account_loan/wizard/account_loan_post.py:0
#. odoo-python
#: code:addons/account_loan/wizards/account_loan_post.py:0
#, python-format
msgid "Only loans in draft state can be posted"
msgstr ""
#. module: account_loan
#: model:ir.actions.act_window,name:account_loan.account_loan_pay_amount_action
#: model_terms:ir.ui.view,arch_db:account_loan.account_loan_form
#: model_terms:ir.ui.view,arch_db:account_loan.account_loan_pay_amount_form
#: model_terms:ir.ui.view,arch_db:account_loan.account_loan_post_form
msgid "Pay amount"
@@ -784,6 +838,7 @@ msgstr ""
#. module: account_loan
#: model_terms:ir.ui.view,arch_db:account_loan.account_loan_generate_wizard_form
#: model_terms:ir.ui.view,arch_db:account_loan.account_loan_increase_amount_form_view
#: model_terms:ir.ui.view,arch_db:account_loan.account_loan_pay_amount_form
#: model_terms:ir.ui.view,arch_db:account_loan.account_loan_post_form
msgid "Run"
@@ -810,37 +865,47 @@ msgid "Short term account"
msgstr ""
#. module: account_loan
#: code:addons/account_loan/wizard/account_loan_pay_amount.py:0
#. odoo-python
#: code:addons/account_loan/wizards/account_loan_increase_amount.py:0
#: code:addons/account_loan/wizards/account_loan_pay_amount.py:0
#, python-format
msgid "Some future invoices already exists"
msgstr ""
#. module: account_loan
#: code:addons/account_loan/wizard/account_loan_pay_amount.py:0
#. odoo-python
#: code:addons/account_loan/wizards/account_loan_increase_amount.py:0
#: code:addons/account_loan/wizards/account_loan_pay_amount.py:0
#, python-format
msgid "Some future moves already exists"
msgstr ""
#. module: account_loan
#: code:addons/account_loan/wizard/account_loan_pay_amount.py:0
#. odoo-python
#: code:addons/account_loan/wizards/account_loan_increase_amount.py:0
#: code:addons/account_loan/wizards/account_loan_pay_amount.py:0
#, python-format
msgid "Some invoices are not created"
msgstr ""
#. module: account_loan
#: code:addons/account_loan/model/account_loan_line.py:0
#. odoo-python
#: code:addons/account_loan/models/account_loan_line.py:0
#, python-format
msgid "Some invoices must be created first"
msgstr ""
#. module: account_loan
#: code:addons/account_loan/wizard/account_loan_pay_amount.py:0
#. odoo-python
#: code:addons/account_loan/wizards/account_loan_increase_amount.py:0
#: code:addons/account_loan/wizards/account_loan_pay_amount.py:0
#, python-format
msgid "Some moves are not created"
msgstr ""
#. module: account_loan
#: code:addons/account_loan/model/account_loan_line.py:0
#. odoo-python
#: code:addons/account_loan/models/account_loan_line.py:0
#, python-format
msgid "Some moves must be created first"
msgstr ""
@@ -905,16 +970,6 @@ msgstr ""
msgid "Type of the exception activity on record."
msgstr ""
#. module: account_loan
#: model:ir.model.fields,field_description:account_loan.field_account_loan__message_unread
msgid "Unread Messages"
msgstr ""
#. module: account_loan
#: model:ir.model.fields,field_description:account_loan.field_account_loan__message_unread_counter
msgid "Unread Messages Counter"
msgstr ""
#. module: account_loan
#: model_terms:ir.ui.view,arch_db:account_loan.account_loan_line_tree
msgid "Values"
@@ -944,6 +999,7 @@ msgstr ""
#. module: account_loan
#: model_terms:ir.ui.view,arch_db:account_loan.account_loan_generate_wizard_form
#: model_terms:ir.ui.view,arch_db:account_loan.account_loan_increase_amount_form_view
#: model_terms:ir.ui.view,arch_db:account_loan.account_loan_pay_amount_form
#: model_terms:ir.ui.view,arch_db:account_loan.account_loan_post_form
msgid "or"

View File

@@ -238,34 +238,38 @@ class AccountLoanLine(models.Model):
+ self.interests_amount
)
def _move_vals(self):
def _move_vals(self, journal=False, account=False):
return {
"loan_line_id": self.id,
"loan_id": self.loan_id.id,
"date": self.date,
"ref": self.name,
"journal_id": self.loan_id.journal_id.id,
"line_ids": [Command.create(vals) for vals in self._move_line_vals()],
"journal_id": (journal and journal.id) or self.loan_id.journal_id.id,
"line_ids": [
Command.create(vals) for vals in self._move_line_vals(account=account)
],
}
def _move_line_vals(self):
def _move_line_vals(self, account=False):
vals = []
partner = self.loan_id.partner_id.with_company(self.loan_id.company_id)
vals.append(
{
"account_id": partner.property_account_payable_id.id,
"account_id": (account and account.id)
or partner.property_account_payable_id.id,
"partner_id": partner.id,
"credit": self.payment_amount,
"debit": 0,
}
)
vals.append(
{
"account_id": self.loan_id.interest_expenses_account_id.id,
"credit": 0,
"debit": self.interests_amount,
}
)
if self.interests_amount:
vals.append(
{
"account_id": self.loan_id.interest_expenses_account_id.id,
"credit": 0,
"debit": self.interests_amount,
}
)
vals.append(
{
"account_id": self.loan_id.short_term_loan_account_id.id,
@@ -326,7 +330,7 @@ class AccountLoanLine(models.Model):
)
return vals
def _generate_move(self):
def _generate_move(self, journal=False, account=False):
"""
Computes and post the moves of loans
:return: list of account.move generated
@@ -338,7 +342,9 @@ class AccountLoanLine(models.Model):
lambda r: r.date < record.date and not r.move_ids
):
raise UserError(_("Some moves must be created first"))
move = self.env["account.move"].create(record._move_vals())
move = self.env["account.move"].create(
record._move_vals(journal=journal, account=account)
)
move.action_post()
res.append(move.id)
return res
@@ -372,6 +378,9 @@ class AccountLoanLine(models.Model):
for line in invoice.invoice_line_ids:
line.tax_ids = line._get_computed_taxes()
invoice.flush_recordset()
invoice.filtered(
lambda m: m.currency_id.round(m.amount_total) < 0
).action_switch_invoice_into_refund_credit_note()
if record.loan_id.post_invoice:
invoice.action_post()
if (

View File

@@ -5,4 +5,5 @@ access_account_loan_line,account.loan.line,model_account_loan_line,account.group
access_account_loan_line_manager,account.loan.line,model_account_loan_line,account.group_account_manager,1,1,1,1
access_account_loan_generate_wizard,access_account_loan_generate_wizard,model_account_loan_generate_wizard,account.group_account_manager,1,1,1,1
access_account_loan_pay_amount,access_account_loan_pay_amount,model_account_loan_pay_amount,account.group_account_manager,1,1,1,1
access_account_loan_increase_amount,access_account_loan_increase_amount,model_account_loan_increase_amount,account.group_account_manager,1,1,1,1
access_account_loan_post,access_account_loan_post,model_account_loan_post,account.group_account_manager,1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
5 access_account_loan_line_manager account.loan.line model_account_loan_line account.group_account_manager 1 1 1 1
6 access_account_loan_generate_wizard access_account_loan_generate_wizard model_account_loan_generate_wizard account.group_account_manager 1 1 1 1
7 access_account_loan_pay_amount access_account_loan_pay_amount model_account_loan_pay_amount account.group_account_manager 1 1 1 1
8 access_account_loan_increase_amount access_account_loan_increase_amount model_account_loan_increase_amount account.group_account_manager 1 1 1 1
9 access_account_loan_post access_account_loan_post model_account_loan_post account.group_account_manager 1 1 1 1

View File

@@ -1,20 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
<title>Account Loan management</title>
<style type="text/css">
/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
*/
@@ -367,9 +367,9 @@ ul.auto-toc {
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:c9f87eb07ebda20ab00e0446ae5e5908b6a64086fd868f2bfc58e4e9f7dc68b0
!! source digest: sha256:95234840632690af02753b03c14b05c13899c8ee92ebd9e394694d91f0212461
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/account-financial-tools/tree/16.0/account_loan"><img alt="OCA/account-financial-tools" src="https://img.shields.io/badge/github-OCA%2Faccount--financial--tools-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/account-financial-tools-16-0/account-financial-tools-16-0-account_loan"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runboat.odoo-community.org/builds?repo=OCA/account-financial-tools&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/account-financial-tools/tree/16.0/account_loan"><img alt="OCA/account-financial-tools" src="https://img.shields.io/badge/github-OCA%2Faccount--financial--tools-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/account-financial-tools-16-0/account-financial-tools-16-0-account_loan"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/account-financial-tools&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module extends the functionality of accounting to support loans.
It will create automatically moves or invoices for loans.
Moreover, you can check the pending amount to be paid and reduce the debt.</p>
@@ -388,25 +388,25 @@ Moreover, you can check the pending amount to be paid and reduce the debt.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#usage" id="id2">Usage</a></li>
<li><a class="reference internal" href="#changelog" id="id3">Changelog</a><ul>
<li><a class="reference internal" href="#id1" id="id4">16.0.1.0.0</a></li>
<li><a class="reference internal" href="#usage" id="toc-entry-1">Usage</a></li>
<li><a class="reference internal" href="#changelog" id="toc-entry-2">Changelog</a><ul>
<li><a class="reference internal" href="#section-1" id="toc-entry-3">16.0.1.0.0</a></li>
</ul>
</li>
<li><a class="reference internal" href="#bug-tracker" id="id5">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="id6">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="id7">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="id8">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="id9">Maintainers</a></li>
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-4">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-5">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-6">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-7">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-8">Maintainers</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#id2">Usage</a></h1>
<h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
<p>To use this module, you need to:</p>
<ol class="arabic simple">
<li>Go to <cite>Invoicing / Accounting &gt; Adviser &gt; Loans</cite></li>
<li>Go to <cite>Invoicing / Accounting &gt; Accounting &gt; Loans</cite></li>
<li>Configure a loan selecting the company, loan type, amount, rate and accounts</li>
<li>Post the loan, it will automatically create an account move with the
expected amounts</li>
@@ -422,14 +422,14 @@ leases before a selected date</li>
<a class="reference external image-reference" href="https://runbot.odoo-community.org/runbot/92/12.0"><img alt="Try me on Runbot" src="https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas" /></a>
</div>
<div class="section" id="changelog">
<h1><a class="toc-backref" href="#id3">Changelog</a></h1>
<div class="section" id="id1">
<h2><a class="toc-backref" href="#id4">16.0.1.0.0</a></h2>
<h1><a class="toc-backref" href="#toc-entry-2">Changelog</a></h1>
<div class="section" id="section-1">
<h2><a class="toc-backref" href="#toc-entry-3">16.0.1.0.0</a></h2>
<p>Due to the changes on 16, we will generate two moves on leasings, one for the invoice, and another one for the change from long to short term.</p>
</div>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#id5">Bug Tracker</a></h1>
<h1><a class="toc-backref" href="#toc-entry-4">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/account-financial-tools/issues">GitHub Issues</a>.
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
@@ -437,15 +437,15 @@ If you spotted it first, help us to smash it by providing a detailed and welcome
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h1><a class="toc-backref" href="#id6">Credits</a></h1>
<h1><a class="toc-backref" href="#toc-entry-5">Credits</a></h1>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#id7">Authors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-6">Authors</a></h2>
<ul class="simple">
<li>Creu Blanca</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#id8">Contributors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-7">Contributors</a></h2>
<ul class="simple">
<li>Enric Tobella &lt;<a class="reference external" href="mailto:etobella&#64;creublanca.es">etobella&#64;creublanca.es</a>&gt;</li>
<li>Bhavesh Odedra &lt;<a class="reference external" href="mailto:bodedra&#64;opensourceintegrators.com">bodedra&#64;opensourceintegrators.com</a>&gt;</li>
@@ -453,14 +453,14 @@ If you spotted it first, help us to smash it by providing a detailed and welcome
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#id9">Maintainers</a></h2>
<h2><a class="toc-backref" href="#toc-entry-8">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<p>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.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
<p><a class="reference external" href="https://github.com/etobella"><img alt="etobella" src="https://github.com/etobella.png?size=40px" /></a></p>
<p><a class="reference external image-reference" href="https://github.com/etobella"><img alt="etobella" src="https://github.com/etobella.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/account-financial-tools/tree/16.0/account_loan">OCA/account-financial-tools</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>

View File

@@ -103,6 +103,52 @@ class TestLoan(TransactionCase):
self.assertEqual(line_1.principal_amount, 0)
self.assertEqual(line_end.principal_amount, 500000)
def test_increase_amount_validation(self):
amount = 10000
periods = 24
loan = self.create_loan("fixed-annuity", amount, 1, periods)
self.assertTrue(loan.line_ids)
self.assertEqual(len(loan.line_ids), periods)
line = loan.line_ids.filtered(lambda r: r.sequence == 1)
self.assertAlmostEqual(
-numpy_financial.pmt(1 / 100 / 12, 24, 10000), line.payment_amount, 2
)
self.assertEqual(line.long_term_principal_amount, 0)
loan.long_term_loan_account_id = self.lt_loan_account
loan.compute_lines()
line = loan.line_ids.filtered(lambda r: r.sequence == 1)
self.assertGreater(line.long_term_principal_amount, 0)
self.post(loan)
self.assertTrue(loan.start_date)
line = loan.line_ids.filtered(lambda r: r.sequence == 1)
self.assertTrue(line)
self.assertFalse(line.move_ids)
wzd = self.env["account.loan.generate.wizard"].create({})
action = wzd.run()
self.assertTrue(action)
self.assertFalse(wzd.run())
self.assertTrue(line.move_ids)
self.assertIn(line.move_ids.id, action["domain"][0][2])
self.assertTrue(line.move_ids)
self.assertEqual(line.move_ids.state, "posted")
with self.assertRaises(UserError):
self.env["account.loan.increase.amount"].with_context(
default_loan_id=loan.id
).create(
{
"amount": (amount - amount / periods) / 2,
"date": line.date + relativedelta(months=-1),
}
).run()
with self.assertRaises(UserError):
self.env["account.loan.increase.amount"].with_context(
default_loan_id=loan.id
).create({"amount": 0, "date": line.date}).run()
with self.assertRaises(UserError):
self.env["account.loan.increase.amount"].with_context(
default_loan_id=loan.id
).create({"amount": -100, "date": line.date}).run()
def test_pay_amount_validation(self):
amount = 10000
periods = 24
@@ -132,26 +178,125 @@ class TestLoan(TransactionCase):
self.assertTrue(line.move_ids)
self.assertEqual(line.move_ids.state, "posted")
with self.assertRaises(UserError):
self.env["account.loan.pay.amount"].create(
self.env["account.loan.pay.amount"].with_context(
default_loan_id=loan.id
).create(
{
"loan_id": loan.id,
"amount": (amount - amount / periods) / 2,
"fees": 100,
"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": line.date}
).run()
self.env["account.loan.pay.amount"].with_context(
default_loan_id=loan.id
).create({"amount": amount, "fees": 100, "date": line.date}).run()
with self.assertRaises(UserError):
self.env["account.loan.pay.amount"].create(
{"loan_id": loan.id, "amount": 0, "fees": 100, "date": line.date}
).run()
self.env["account.loan.pay.amount"].with_context(
default_loan_id=loan.id
).create({"amount": 0, "fees": 100, "date": line.date}).run()
with self.assertRaises(UserError):
self.env["account.loan.pay.amount"].create(
{"loan_id": loan.id, "amount": -100, "fees": 100, "date": line.date}
).run()
self.env["account.loan.pay.amount"].with_context(
default_loan_id=loan.id
).create({"amount": -100, "fees": 100, "date": line.date}).run()
def test_increase_amount_loan(self):
amount = 10000
periods = 24
loan = self.create_loan("fixed-annuity", amount, 1, periods)
self.assertTrue(loan.line_ids)
self.assertEqual(len(loan.line_ids), periods)
line = loan.line_ids.filtered(lambda r: r.sequence == 1)
self.assertAlmostEqual(
-numpy_financial.pmt(1 / 100 / 12, 24, 10000), line.payment_amount, 2
)
self.assertEqual(line.long_term_principal_amount, 0)
loan.long_term_loan_account_id = self.lt_loan_account
loan.compute_lines()
line = loan.line_ids.filtered(lambda r: r.sequence == 1)
self.assertGreater(line.long_term_principal_amount, 0)
self.post(loan)
self.assertTrue(loan.start_date)
line = loan.line_ids.filtered(lambda r: r.sequence == 1)
self.assertTrue(line)
self.assertFalse(line.move_ids)
wzd = self.env["account.loan.generate.wizard"].create({})
action = wzd.run()
self.assertTrue(action)
self.assertFalse(wzd.run())
self.assertTrue(line.move_ids)
self.assertIn(line.move_ids.id, action["domain"][0][2])
self.assertTrue(line.move_ids)
self.assertEqual(line.move_ids.state, "posted")
pending_principal_amount = loan.pending_principal_amount
action = (
self.env["account.loan.increase.amount"]
.with_context(default_loan_id=loan.id)
.create(
{
"amount": 1000,
"date": line.date,
}
)
.run()
)
new_move = self.env[action["res_model"]].search(action["domain"])
new_move.ensure_one()
self.assertFalse(new_move.is_invoice())
self.assertEqual(loan, new_move.loan_id)
self.assertEqual(loan.pending_principal_amount, pending_principal_amount + 1000)
def test_increase_amount_leasing(self):
amount = 10000
periods = 24
loan = self.create_loan("fixed-annuity", amount, 1, periods)
self.assertTrue(loan.line_ids)
self.assertEqual(len(loan.line_ids), periods)
line = loan.line_ids.filtered(lambda r: r.sequence == 1)
self.assertAlmostEqual(
-numpy_financial.pmt(1 / 100 / 12, 24, 10000), line.payment_amount, 2
)
self.assertEqual(line.long_term_principal_amount, 0)
loan.is_leasing = True
loan.long_term_loan_account_id = self.lt_loan_account
loan.compute_lines()
line = loan.line_ids.filtered(lambda r: r.sequence == 1)
self.assertGreater(line.long_term_principal_amount, 0)
self.post(loan)
self.assertTrue(loan.start_date)
line = loan.line_ids.filtered(lambda r: r.sequence == 1)
self.assertTrue(line)
self.assertFalse(line.move_ids)
wzd = self.env["account.loan.generate.wizard"].create(
{
"date": fields.date.today() + relativedelta(days=1),
"loan_type": "leasing",
}
)
action = wzd.run()
self.assertTrue(action)
self.assertFalse(wzd.run())
self.assertTrue(line.move_ids)
self.assertIn(line.move_ids.id, action["domain"][0][2])
self.assertTrue(line.move_ids)
self.assertEqual(line.move_ids.state, "posted")
pending_principal_amount = loan.pending_principal_amount
action = (
self.env["account.loan.increase.amount"]
.with_context(default_loan_id=loan.id)
.create(
{
"amount": 1000,
"date": line.date,
}
)
.run()
)
new_move = self.env[action["res_model"]].search(action["domain"])
new_move.ensure_one()
self.assertFalse(new_move.is_invoice())
self.assertEqual(loan, new_move.loan_id)
self.assertEqual(loan.pending_principal_amount, pending_principal_amount + 1000)
def test_fixed_annuity_begin_loan(self):
amount = 10000

View File

@@ -66,12 +66,29 @@
<button
name="%(account_loan_pay_amount_action)d"
class="oe_stat_button"
icon="fa-usd"
icon="fa-arrow-down"
attrs="{'invisible': [('state', '!=', 'posted')]}"
type="action"
string="Pay amount"
groups="account.group_account_manager"
/>
>
<div class="o_field_widget o_stat_info">
<span class="o_stat_text">Deduct</span>
<span class="o_stat_text">Debt</span>
</div>
</button>
<button
name="%(account_loan_increase_amount_act_window)d"
class="oe_stat_button"
icon="fa-arrow-up"
attrs="{'invisible': [('state', '!=', 'posted')]}"
type="action"
groups="account.group_account_manager"
>
<div class="o_field_widget o_stat_info">
<span class="o_stat_text">Increase</span>
<span class="o_stat_text">Debt</span>
</div>
</button>
</div>
<h1>
<field name="name" />

View File

@@ -3,3 +3,4 @@
from . import account_loan_generate_entries
from . import account_loan_pay_amount
from . import account_loan_post
from . import account_loan_increase_amount

View File

@@ -0,0 +1,113 @@
# Copyright 2023 Dixmit
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import _, api, fields, models
from odoo.exceptions import UserError
class AccountLoanIncreaseAmount(models.TransientModel):
_name = "account.loan.increase.amount"
_description = "Increase the debt of a loan"
@api.model
def _default_journal_id(self):
loan_id = self.env.context.get("default_loan_id")
if loan_id:
return self.env["account.loan"].browse(loan_id).journal_id.id
@api.model
def _default_account_id(self):
loan_id = self.env.context.get("default_loan_id")
if loan_id:
loan = self.env["account.loan"].browse(loan_id)
if loan.is_leasing:
return loan.leased_asset_account_id.id
else:
return loan.partner_id.with_company(
loan.company_id
).property_account_receivable_id.id
journal_id = fields.Many2one(
"account.journal", required=True, default=lambda r: r._default_journal_id()
)
account_id = fields.Many2one(
"account.account", required=True, default=lambda r: r._default_account_id()
)
loan_id = fields.Many2one(
"account.loan",
required=True,
readonly=True,
)
currency_id = fields.Many2one(
"res.currency", related="loan_id.currency_id", readonly=True
)
date = fields.Date(required=True, default=fields.Date.today())
amount = fields.Monetary(
currency_field="currency_id",
string="Amount to reduce from Principal",
)
def new_line_vals(self, sequence):
return {
"loan_id": self.loan_id.id,
"sequence": sequence,
"payment_amount": -self.amount,
"rate": 0,
"interests_amount": 0,
"date": self.date,
}
def run(self):
self.ensure_one()
if self.loan_id.is_leasing:
if self.loan_id.line_ids.filtered(
lambda r: r.date <= self.date and not r.move_ids
):
raise UserError(_("Some invoices are not created"))
if self.loan_id.line_ids.filtered(
lambda r: r.date > self.date and r.move_ids
):
raise UserError(_("Some future invoices already exists"))
else:
if self.loan_id.line_ids.filtered(
lambda r: r.date < self.date and not r.move_ids
):
raise UserError(_("Some moves are not created"))
if self.loan_id.line_ids.filtered(
lambda r: r.date > self.date and r.move_ids
):
raise UserError(_("Some future moves already exists"))
lines = self.loan_id.line_ids.filtered(lambda r: r.date > self.date).sorted(
"sequence", reverse=True
)
sequence = min(lines.mapped("sequence"))
for line in lines:
line.sequence += 1
line.flush_recordset()
old_line = lines.filtered(lambda r: r.sequence == sequence + 1)
pending = old_line.pending_principal_amount
if self.loan_id.currency_id.compare_amounts(self.amount, 0) <= 0:
raise UserError(_("Amount cannot be less than zero"))
self.loan_id.periods += 1
self.loan_id.fixed_periods = self.loan_id.periods - sequence
self.loan_id.fixed_loan_amount = pending - self.amount
new_line = self.env["account.loan.line"].create(self.new_line_vals(sequence))
new_line.long_term_pending_principal_amount = (
old_line.long_term_pending_principal_amount
)
amount = self.loan_id.loan_amount
for line in self.loan_id.line_ids.sorted("sequence"):
if line.move_ids:
amount = line.final_pending_principal_amount
else:
line.pending_principal_amount = amount
if line.sequence != sequence:
line.rate = self.loan_id.rate_period
line._check_amount()
amount -= line.payment_amount - line.interests_amount
if self.loan_id.long_term_loan_account_id:
self.loan_id._check_long_term_principal_amount()
if self.loan_id.currency_id.compare_amounts(pending, self.amount) == 0:
self.loan_id.write({"state": "cancelled"})
new_line._generate_move(journal=self.journal_id, account=self.account_id)
return new_line.view_account_values()

View File

@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2023 Dixmit
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>
<record model="ir.ui.view" id="account_loan_increase_amount_form_view">
<field name="name">account.loan.increase.amount.form (in account_loan)</field>
<field name="model">account.loan.increase.amount</field>
<field name="arch" type="xml">
<form>
<group>
<field name="loan_id" readonly="True" />
<field name="date" />
<field name="amount" />
<field name="currency_id" />
</group>
<footer>
<button
name="run"
string="Run"
type="object"
class="oe_highlight"
/>
or
<button string="Cancel" class="oe_link" special="cancel" />
</footer>
</form>
</field>
</record>
<record model="ir.actions.act_window" id="account_loan_increase_amount_act_window">
<field name="name">Increase Amount</field>
<field name="res_model">account.loan.increase.amount</field>
<field name="view_mode">form</field>
<field name="context">{'default_loan_id': active_id}</field>
<field name="target">new</field>
</record>
</odoo>

View File

@@ -57,12 +57,15 @@ class AccountLoan(models.TransientModel):
lambda r: r.date > self.date and r.move_ids
):
raise UserError(_("Some future invoices already exists"))
if self.loan_id.line_ids.filtered(
lambda r: r.date < self.date and not r.move_ids
):
raise UserError(_("Some moves are not created"))
if self.loan_id.line_ids.filtered(lambda r: r.date > self.date and r.move_ids):
raise UserError(_("Some future moves already exists"))
else:
if self.loan_id.line_ids.filtered(
lambda r: r.date < self.date and not r.move_ids
):
raise UserError(_("Some moves are not created"))
if self.loan_id.line_ids.filtered(
lambda r: r.date > self.date and r.move_ids
):
raise UserError(_("Some future moves already exists"))
lines = self.loan_id.line_ids.filtered(lambda r: r.date > self.date).sorted(
"sequence", reverse=True
)