Browse Source

[IMP] fix and improve move lines code still in WIP

pull/134/head
houssine 4 years ago
parent
commit
d22f5219c5
  1. 3
      easy_my_coop_loan/models/interest_line.py
  2. 26
      easy_my_coop_loan_account/models/company.py
  3. 116
      easy_my_coop_loan_account/models/interest_line.py
  4. 10
      easy_my_coop_loan_account/models/loan_issue_line.py

3
easy_my_coop_loan/models/interest_line.py

@ -96,8 +96,9 @@ class LoanInterestLine(models.Model):
state = fields.Selection(
[
("draft", "Draft"),
("due_fy", "Due in the year"),
("due", "Due"),
("requested", "Payment requested"),
("scheduled", "Payment scheduled"),
("donation", "Donation"),
("paid", "Paid"),
],

26
easy_my_coop_loan_account/models/company.py

@ -30,14 +30,6 @@ class ResCompany(models.Model):
" 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,
@ -49,11 +41,25 @@ class ResCompany(models.Model):
debt_long_term_fy_account = fields.Many2one(
"account.account",
company_dependent=True,
string="Short Term Debt Account",
string="Long Term Debt Due In The Year 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",
)
debt_long_term_due_account = fields.Many2one(
"account.account",
company_dependent=True,
string="Long Term Debt Due Account",
help="This account is used to register the loan debt due",
required=True,
)
expense_account = fields.Many2one(
"account.account",
company_dependent=True,
string="Expense Account",
help="This account is used to register the prorata temporis interest"
" amount at the end of the fiscal year",
required=True,
)
interest_account = fields.Many2one(
"account.account",

116
easy_my_coop_loan_account/models/interest_line.py

@ -1,6 +1,7 @@
# Copyright 2020 Coop IT Easy SCRL fs
# Houssine BAKKALI <houssine@coopiteasy.be>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from dateutil.relativedelta import relativedelta
from odoo import api, fields, models
@ -12,13 +13,13 @@ class LoanInterestLine(models.Model):
comodel_name="account.move",
string="Loan due this fiscal year account move"
)
loan_reimbursment_move = fields.Many2one(
loan_due_move = fields.Many2one(
comodel_name="account.move",
string="Loan reimbursement account move"
string="Loan due this fiscal year account move"
)
interest_payment_move = fields.Many2one(
loan_reimbursment_move = fields.Many2one(
comodel_name="account.move",
string="Interest payment account move"
string="Loan reimbursement account move"
)
@api.multi
@ -48,54 +49,90 @@ class LoanInterestLine(models.Model):
})
@api.multi
def generate_interest_payement_move_lines(self):
self.ensure_one()
move_line_obj = self.env["account.move.line"]
def generate_payment_move_lines(self):
for line in self:
if not self.loan_reimbursment_move:
company = line.company_id
move = line.create_move()
debit_vals = line.get_move_line(line.partner_id)
loaner_vals = line.get_move_line(line.partner_id)
move = self.create_move()
debit_vals = self.get_move_line(self.partner_id)
loaner_vals = self.get_move_line(self.partner_id)
debit_vals["debit"] = line.interest
debit_vals["account_id"] = company.interest_account.id
debit_vals["debit"] = self.interest
debit_vals["account_id"] = self.company_id.interest_account.id
if line.due_loan_amount > 0 and line.net_interest > 0:
loaner_vals["credit"] = line.due_amount
elif line.due_loan_amount > 0:
loaner_vals["credit"] = line.due_loan_amount
elif line.net_interest > 0:
loaner_vals["credit"] = line.net_interest
loaner_vals["account_id"] = company.loaner_account
loaner_vals["credit"] = self.due_amount
loaner_vals["account_id"] = self.company_id.loaner_account
vals_list = [debit_vals, loaner_vals]
if self.taxes_amount > 0:
tax_vals = self.get_move_line()
tax_vals["credit"] = self.taxes_amount
tax_vals["account_id"] = self.company_id.tax_account.id
vals_list.append(tax_vals)
vals_list = [debit_vals, loaner_vals]
move_line_obj.create(vals_list)
if line.taxes_amount > 0:
tax_vals = self.get_move_line()
tax_vals["credit"] = line.taxes_amount
tax_vals["account_id"] = company.tax_account.id
vals_list.append(tax_vals)
self.interest_payment_mpve = move
self.env["account.move.line"].create(vals_list)
line.write({"loan_reimbursment_move": move.id,
"state": "scheduled"})
@api.multi
def generate_loan_due_fy(self):
self.ensure_one()
def generate_loan_due_fy(self, date):
move_line_obj = self.env["account.move.line"]
for line in self:
if not self.loan_due_fy_move:
company = line.line.company_id
move = line.create_move(date)
move = self.create_move(fields.Date.today())
debit_vals = line.get_move_line(line.partner_id)
credit_vals = line.get_move_line(line.partner_id)
debit_vals = self.get_move_line(self.partner_id)
credit_vals = self.get_move_line(self.partner_id)
debit_vals["debit"] = line.due_loan_amount
debit_vals["date"] = date
debit_vals["account_id"] = company.debt_long_term_account.id
debit_vals["debit"] = self.due_amount
debit_vals["account_id"] = self.company_id.debt_long_term_account.id
credit_vals["credit"] = line.due_loan_amount
credit_vals["credit"] = date
credit_vals["account_id"] = company.debt_long_term_fy_account.id
credit_vals["credit"] = self.due_amount
credit_vals["account_id"] = self.company_id.debt_long_term_fy_account
self.env["account.move.line"].create([debit_vals, credit_vals])
move_line_obj.create([debit_vals, credit_vals])
line.write({"loan_due_fy_move": move.id,
"state": "due_fy"})
self.loan_due_fy_move = move
@api.multi
def generate_loan_due_now(self):
for line in self:
if line.loan_due_move:
company = line.company_id
move = line.create_move(fields.Date.today())
debit_vals = line.get_move_line(line)
credit_vals = line.get_move_line(line.partner_id)
debit_vals["debit"] = line.due_loan_amount
debit_vals["account_id"] = company.debt_long_term_fy_account.id
credit_vals["credit"] = line.due_loan_amount
credit_vals["account_id"] = company.debt_long_term_due_account
self.env["account.move.line"].create([debit_vals, credit_vals])
line.write({"loan_due_move": move.id,
"state": "due"})
@api.model
def _generate_move_line_debt_end_fy(self):
fy = self.env["account.fiscal.year"].get_next_fiscal_year()
date = fy.date_from - relativedelta(days=1)
if fy:
interest_lines = self.search([
('due_date', '>=', fy.date_from),
@ -103,21 +140,18 @@ class LoanInterestLine(models.Model):
('due_loan_amount', '>', 0),
])
for line in interest_lines:
if (not line.loan_reimbursment_move
and not line.loan_due_fy_move):
self.generate_loan_due_fy()
interest_lines.generate_loan_due_fy(date)
@api.model
def _generate_payment_move(self):
# TODO configure how many days before you want generate the move lines
fy = self.env["account.fiscal.year"].get_next_fiscal_year()
interest_lines = self.search([
('due_date', '>=', fy.date_from),
('due_date', '<=', fy.date_to),
('due_amount', '>', 0),
])
for line in interest_lines:
if line.interest > 0 and not line.loan_reimbursment_move:
line.generate_interest_payement_move_lines()
interest_lines.generate_payment_move_lines()
return True

10
easy_my_coop_loan_account/models/loan_issue_line.py

@ -12,7 +12,7 @@ class LoanIssueLine(models.Model):
_inherit = "loan.issue.line"
awaiting_move_id = fields.Many2one(
"account.move",
comodel_name="account.move",
string="Awaiting payment account move"
)
@ -56,14 +56,6 @@ class LoanIssueLine(models.Model):
move_line_obj.create([loan_vals, loaner_vals])
line.awaiting_move_id = move
@api.multi
def create_interest_payment_move(self):
print()
@api.multi
def create_loan_reimbursement_move(self):
print()
@api.multi
def action_request_payment(self):
self.create_waiting_payment_move()

Loading…
Cancel
Save