From 6e8ed7df07ca8c48339071369e37ed7ffe6f4d50 Mon Sep 17 00:00:00 2001 From: houssine Date: Fri, 13 Nov 2020 16:12:05 +0100 Subject: [PATCH] [ADD] add module emc_loan_account still in wip --- easy_my_coop_loan_account/__init__.py | 1 + easy_my_coop_loan_account/__manifest__.py | 27 ++++++ .../data/emc_loan_account_data.xml | 31 +++++++ easy_my_coop_loan_account/models/__init__.py | 3 + .../models/account_move.py | 39 +++++++++ easy_my_coop_loan_account/models/company.py | 86 +++++++++++++++++++ .../models/loan_issue_line.py | 65 ++++++++++++++ .../views/loan_issue_line_view.xml | 22 +++++ .../views/res_company_view.xml | 24 ++++++ 9 files changed, 298 insertions(+) create mode 100644 easy_my_coop_loan_account/__init__.py create mode 100644 easy_my_coop_loan_account/__manifest__.py create mode 100644 easy_my_coop_loan_account/data/emc_loan_account_data.xml create mode 100644 easy_my_coop_loan_account/models/__init__.py create mode 100644 easy_my_coop_loan_account/models/account_move.py create mode 100644 easy_my_coop_loan_account/models/company.py create mode 100644 easy_my_coop_loan_account/models/loan_issue_line.py create mode 100644 easy_my_coop_loan_account/views/loan_issue_line_view.xml create mode 100644 easy_my_coop_loan_account/views/res_company_view.xml diff --git a/easy_my_coop_loan_account/__init__.py b/easy_my_coop_loan_account/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/easy_my_coop_loan_account/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/easy_my_coop_loan_account/__manifest__.py b/easy_my_coop_loan_account/__manifest__.py new file mode 100644 index 0000000..fa78aa8 --- /dev/null +++ b/easy_my_coop_loan_account/__manifest__.py @@ -0,0 +1,27 @@ +# Copyright 2020 - ongoing Coop IT Easy SCRLfs () +# - Houssine BAKKALI - +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +{ + "name": "Easy My Coop Loan Account", + "version": "12.0.1.0.0", + "depends": [ + "account", + "easy_my_coop_loan", + ], + "author": "Coop IT Easy SCRLfs", + "category": "Cooperative management", + "website": "https://www.coopiteasy.be", + "license": "AGPL-3", + "summary": """ + This module brings the accounting part of the loan issue. + It has for purpose to generate all the accounting entries to the covered + use cases. + """, + "data": [ + "data/emc_loan_account_data.xml", + "views/res_company_view.xml", + "views/loan_issue_line_view.xml", + ], + "installable": True, +} diff --git a/easy_my_coop_loan_account/data/emc_loan_account_data.xml b/easy_my_coop_loan_account/data/emc_loan_account_data.xml new file mode 100644 index 0000000..7361612 --- /dev/null +++ b/easy_my_coop_loan_account/data/emc_loan_account_data.xml @@ -0,0 +1,31 @@ + + + + Awaiting Loan Payment Journal + + ALPJ/%(year)s/ + True + + + + Awaiting Loan Payment Journal + ALPJ + general + + + + + Loan Journal + + LOANJ/%(year)s/ + True + + + + Loan Journal + LOANJ + general + + + + \ No newline at end of file diff --git a/easy_my_coop_loan_account/models/__init__.py b/easy_my_coop_loan_account/models/__init__.py new file mode 100644 index 0000000..fa9a212 --- /dev/null +++ b/easy_my_coop_loan_account/models/__init__.py @@ -0,0 +1,3 @@ +from . import company +from . import loan_issue_line +from . import account_move diff --git a/easy_my_coop_loan_account/models/account_move.py b/easy_my_coop_loan_account/models/account_move.py new file mode 100644 index 0000000..de62360 --- /dev/null +++ b/easy_my_coop_loan_account/models/account_move.py @@ -0,0 +1,39 @@ +# Copyright 2019 Coop IT Easy SCRL fs +# Houssine BAKKALI +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import api, fields, models + + +class AccountMove(models.Model): + _inherit = "account.move" + + loan_issue_line = fields.One2many( + "loan.issue.line", + "awaiting_move_id", + string="Loan issue line", + readonly=True, + ) + + +class AccountMoveLine(models.Model): + _inherit = "account.move.line" + + loan_issue_line = fields.One2many( + "loan.issue.line", + related="move_id.loan_issue_line", + ) + + @api.multi + def check_full_reconcile(self): + super(AccountMoveLine, self).check_full_reconcile() + full_reconcile_id = self.mapped("full_reconcile_id") + loan_issue_line = self.mapped("loan_issue_line") + if full_reconcile_id and loan_issue_line: + for move_line in self: + if move_line.statement_id: + loan_issue_line.payment_date = move_line.date + loan_issue_line.with_context( + {"paid_by_bank_statement": True} + ).action_paid() + print(full_reconcile_id) diff --git a/easy_my_coop_loan_account/models/company.py b/easy_my_coop_loan_account/models/company.py new file mode 100644 index 0000000..a019017 --- /dev/null +++ b/easy_my_coop_loan_account/models/company.py @@ -0,0 +1,86 @@ +# Copyright 2019 Coop IT Easy SCRL fs +# Houssine Bakkali +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + + +from odoo import fields, models + + +class ResCompany(models.Model): + _inherit = "res.company" + + awaiting_loan_payment_account = fields.Many2one( + "account.account", + company_dependent=True, + string="Awaiting Loan Payment Account", + domain=[ + ("internal_type", "=", "receivable"), + ("deprecated", "=", False), + ], + help="This account serve to track awaiting payment." + " It only serve a bank reconciliation purpose to register the awaiting" + " loan payment as received/paid", + required=True, + ) + loaner_account = fields.Many2one( + "account.account", + company_dependent=True, + string="Loaner Account", + help="This account will be the default one as the" + " receivable account for the cooperators", + required=True, + ) + expense_account = fields.Many2one( + "account.account", + company_dependent=True, + string="Expense Account", + help="This account is used to register the loan debt due for more" + " than one year", + required=True, + ) + debt_long_term_account = fields.Many2one( + "account.account", + company_dependent=True, + string="Long Term Debt Account", + help="This account is used to register the loan debt due for more" + " than one year", + required=True, + ) + debt_short_term_account = fields.Many2one( + "account.account", + company_dependent=True, + string="Short Term Debt Account", + help="This account is used to register the loan debt due for the" + " current fiscal year", + required=True, + old_name="debt_short_term_account", + ) + interest_account = fields.Many2one( + "account.account", + company_dependent=True, + string="Interest Account", + help="This account is used to register the due loan interest", + required=True, + ) + tax_account = fields.Many2one( + "account.account", + company_dependent=True, + string="Tax Account", + help="This account is used to register the tax to pay" + " to the tax administration", + required=True, + ) + awaiting_loan_payment_journal = fields.Many2one( + "account.journal", + string="Awaiting loan payment journal", + help="This journal will be the default one as the" + " to track the payment from the loaners", + required=True, + ) + loan_journal = fields.Many2one( + "account.journal", + string="Loan journal", + help="This journal will be the one used to register all" + " the loan account move lines", + required=True, + ) diff --git a/easy_my_coop_loan_account/models/loan_issue_line.py b/easy_my_coop_loan_account/models/loan_issue_line.py new file mode 100644 index 0000000..ed29d70 --- /dev/null +++ b/easy_my_coop_loan_account/models/loan_issue_line.py @@ -0,0 +1,65 @@ +# Copyright 2019 Coop IT Easy SCRL fs +# Houssine BAKKALI +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from datetime import date + +from odoo import api, fields, models, _ +from odoo.exceptions import UserError + + +class LoanIssueLine(models.Model): + _inherit = "loan.issue.line" + + awaiting_move_id = fields.Many2one( + "account.move", + string="Awaiting payment account move" + ) + + @api.multi + def get_loan_move_line(self, move_id): + self.ensure_one() + move_line = { + "partner_id": self.partner_id.id, + "date_maturity": date.today(), + "move_id": move_id, + } + return move_line + + @api.multi + def create_waiting_payment_moves(self): + move_obj = self.env["account.move"] + move_line_obj = self.env["account.move.line"] + for line in self: + company = line.company_id + move_vals = { + "ref": line.reference, + "date": date.today(), + "journal_id": company.awaiting_loan_payment_journal.id, + } + move = move_obj.create(move_vals) + loan_vals = line.get_loan_move_line(move.id) + loaner_vals = line.get_loan_move_line(move.id) + + loan_vals["account_id"] = company.debt_long_term_account.id + loan_vals["credit"] = line.amount + + loaner_vals["account_id"] = company.awaiting_loan_payment_account.id + loaner_vals["debit"] = line.amount + + move_line_obj.create([loan_vals, loaner_vals]) + line.awaiting_move_id = move + + @api.multi + def action_request_payment(self): + self.create_waiting_payment_moves() + super(LoanIssueLine, self).action_request_payment() + + @api.multi + def action_paid(self): + paid_by = self.env.context.get("paid_by_bank_statement") + if paid_by: + super(LoanIssueLine, self).action_paid() + else: + raise UserError(_("The payment must be registered" + " by bank statement")) \ No newline at end of file diff --git a/easy_my_coop_loan_account/views/loan_issue_line_view.xml b/easy_my_coop_loan_account/views/loan_issue_line_view.xml new file mode 100644 index 0000000..30c2121 --- /dev/null +++ b/easy_my_coop_loan_account/views/loan_issue_line_view.xml @@ -0,0 +1,22 @@ + + + + loan.issue.line.form + loan.issue.line + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/easy_my_coop_loan_account/views/res_company_view.xml b/easy_my_coop_loan_account/views/res_company_view.xml new file mode 100644 index 0000000..73912b6 --- /dev/null +++ b/easy_my_coop_loan_account/views/res_company_view.xml @@ -0,0 +1,24 @@ + + + + res.company.form.easymy.coop + + res.company + + + + + + + + + + + + + + + + +