Browse Source

[IMP] add account move line

pull/134/head
houssine 4 years ago
parent
commit
de8c526077
  1. 2
      easy_my_coop_loan_account/models/account_move.py
  2. 4
      easy_my_coop_loan_account/models/company.py
  3. 121
      easy_my_coop_loan_account/models/interest_line.py
  4. 16
      easy_my_coop_loan_account/models/loan_issue_line.py
  5. 2
      easy_my_coop_loan_account/views/res_company_view.xml

2
easy_my_coop_loan_account/models/account_move.py

@ -1,4 +1,4 @@
# Copyright 2019 Coop IT Easy SCRL fs
# 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).

4
easy_my_coop_loan_account/models/company.py

@ -1,4 +1,4 @@
# Copyright 2019 Coop IT Easy SCRL fs
# 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).
@ -46,7 +46,7 @@ class ResCompany(models.Model):
" than one year",
required=True,
)
debt_short_term_account = fields.Many2one(
debt_long_term_fy_account = fields.Many2one(
"account.account",
company_dependent=True,
string="Short Term Debt Account",

121
easy_my_coop_loan_account/models/interest_line.py

@ -1,18 +1,123 @@
# Copyright 2019 Coop IT Easy SCRL fs
# 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 odoo import api, models
from odoo import api, fields, models
class LoanInterestLine(models.Model):
_inherit = "loan.interest.line"
loan_due_fy_move = fields.Many2one(
comodel_name="account.move",
string="Loan due this fiscal year account move"
)
loan_reimbursment_move = fields.Many2one(
comodel_name="account.move",
string="Loan reimbursement account move"
)
interest_payment_move = fields.Many2one(
comodel_name="account.move",
string="Interest payment account move"
)
@api.multi
def get_move_line(self, move_id, partner=None):
self.ensure_one()
move_line = {
"date_maturity": self.due_date,
"date": self.due_date,
"move_id": move_id,
}
if partner:
move_line["partner_id"] = partner.id
return move_line
@api.multi
def create_move(self, date=None):
self.ensure_one()
if date:
due_date = date
else:
due_date = self.due_date
return self.env["account.move"].create({
"ref": self.loan_issue_id.reference,
"date": due_date,
"journal_id": self.company_id.loan_journal.id,
})
@api.multi
def generate_interest_payement_move_lines(self):
self.ensure_one()
move_line_obj = self.env["account.move.line"]
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"] = self.interest
debit_vals["account_id"] = self.company_id.interest_account.id
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)
move_line_obj.create(vals_list)
self.interest_payment_mpve = move
@api.multi
def generate_loan_due_fy(self):
self.ensure_one()
move_line_obj = self.env["account.move.line"]
move = self.create_move(fields.Date.today())
debit_vals = self.get_move_line(self.partner_id)
credit_vals = self.get_move_line(self.partner_id)
debit_vals["debit"] = self.due_amount
debit_vals["account_id"] = self.company_id.debt_long_term_account.id
credit_vals["credit"] = self.due_amount
credit_vals["account_id"] = self.company_id.debt_long_term_fy_account
move_line_obj.create([debit_vals, credit_vals])
self.loan_due_fy_move = move
@api.model
def _generate_loan_reimbursement_fy(self):
#TODO get fiscal year begin and end dates
interest_lines = self.search([('due_date', '<=', ''),
('due_date', '<=', )
])
def _generate_move_line_debt_end_fy(self):
fy = self.env["account.fiscal.year"].get_next_fiscal_year()
if fy:
interest_lines = self.search([
('due_date', '>=', fy.date_from),
('due_date', '<=', fy.date_to),
('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()
@api.model
def _generate_payment_move(self):
# TODO configure how many days before you want generate the move lines
interest_lines = self.search([
('due_date', '>=', fy.date_from),
('due_date', '<=', fy.date_to),
('due_amount', '>', 0),
])
for line in interest_lines:
print()
if line.interest > 0 and not line.loan_reimbursment_move:
line.generate_interest_payement_move_lines()
return True

16
easy_my_coop_loan_account/models/loan_issue_line.py

@ -1,4 +1,4 @@
# Copyright 2019 Coop IT Easy SCRL fs
# 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).
@ -31,7 +31,7 @@ class LoanIssueLine(models.Model):
return self.env["account.move"].create({
"ref": line.reference,
"date": date.today(),
"journal_id": journal.id,
"journal_id": journal,
})
@api.multi
@ -56,18 +56,6 @@ class LoanIssueLine(models.Model):
move_line_obj.create([loan_vals, loaner_vals])
line.awaiting_move_id = move
@api.multi
def create_loan_fy_move(self):
# this function generate the move for the loan
# to reimburse for the current fiscal year
for line in self:
company = line.company_id
move = self.create_move(
line,
line,
company.awaiting_loan_payment_journal.id,
)
@api.multi
def create_interest_payment_move(self):
print()

2
easy_my_coop_loan_account/views/res_company_view.xml

@ -12,7 +12,7 @@
<field name="loaner_account"/>
<field name="expense_account"/>
<field name="debt_long_term_account"/>
<field name="debt_short_term_account"/>
<field name="debt_long_term_fy_account"/>
<field name="interest_account"/>
<field name="tax_account"/>
<field name="awaiting_loan_payment_journal"/>

Loading…
Cancel
Save