2
0
account-financial-tools/account_loan/wizards/account_loan_generate_entries.py

46 lines
1.5 KiB
Python
Raw Normal View History

2018-02-26 12:17:24 +01:00
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models
2018-02-26 12:17:24 +01:00
class AccountLoanGenerateWizard(models.TransientModel):
_name = "account.loan.generate.wizard"
_description = "Loan generate wizard"
2018-02-26 12:17:24 +01:00
date = fields.Date(
"Account Date",
2018-02-26 12:17:24 +01:00
required=True,
help="Choose the period for which you want to automatically post the "
"depreciation lines of running assets",
default=fields.Date.context_today,
)
loan_type = fields.Selection(
[("leasing", "Leasings"), ("loan", "Loans")], required=True, default="loan"
)
2018-02-26 12:17:24 +01:00
2023-09-15 10:04:47 +02:00
def _run_leasing(self):
created_ids = self.env["account.loan"]._generate_leasing_entries(self.date)
result = self.env["ir.actions.act_window"]._for_xml_id(
"account.action_move_out_invoice_type"
)
2018-02-26 12:17:24 +01:00
if len(created_ids) == 0:
return
2023-09-15 10:04:47 +02:00
result["domain"] = [("id", "in", created_ids)]
2018-02-26 12:17:24 +01:00
return result
2023-09-15 10:04:47 +02:00
def _run_loan(self):
created_ids = self.env["account.loan"]._generate_loan_entries(self.date)
result = self.env["ir.actions.act_window"]._for_xml_id(
"account.action_move_line_form"
)
2018-02-26 12:17:24 +01:00
if len(created_ids) == 0:
return
result["domain"] = [("id", "in", created_ids)]
2018-02-26 12:17:24 +01:00
return result
def run(self):
self.ensure_one()
if self.loan_type == "leasing":
2023-09-15 10:04:47 +02:00
return self._run_leasing()
return self._run_loan()