2018-02-26 12:17:24 +01:00
|
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
|
2021-02-23 12:15:36 +01:00
|
|
|
from odoo import fields, models
|
2018-02-26 12:17:24 +01:00
|
|
|
|
|
|
|
|
|
|
|
class AccountLoanGenerateWizard(models.TransientModel):
|
|
|
|
_name = "account.loan.generate.wizard"
|
2021-02-23 11:00:15 +01:00
|
|
|
_description = "Loan generate wizard"
|
2018-02-26 12:17:24 +01:00
|
|
|
|
|
|
|
date = fields.Date(
|
2021-02-23 11:00:15 +01:00
|
|
|
"Account Date",
|
2018-02-26 12:17:24 +01:00
|
|
|
required=True,
|
|
|
|
help="Choose the period for which you want to automatically post the "
|
2021-02-23 11:00:15 +01:00
|
|
|
"depreciation lines of running assets",
|
|
|
|
default=fields.Date.context_today,
|
|
|
|
)
|
|
|
|
loan_type = fields.Selection(
|
2021-02-23 12:15:36 +01:00
|
|
|
[("leasing", "Leasings"), ("loan", "Loans")], required=True, default="loan"
|
2021-02-23 11:00:15 +01:00
|
|
|
)
|
2018-02-26 12:17:24 +01:00
|
|
|
|
|
|
|
def run_leasing(self):
|
2021-02-23 11:00:15 +01:00
|
|
|
created_ids = self.env["account.loan"].generate_leasing_entries(self.date)
|
2023-02-07 15:03:13 +01:00
|
|
|
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
|
2021-02-23 11:00:15 +01:00
|
|
|
result["domain"] = [("id", "in", created_ids), ("type", "=", "in_invoice")]
|
2018-02-26 12:17:24 +01:00
|
|
|
return result
|
|
|
|
|
|
|
|
def run_loan(self):
|
2021-02-23 11:00:15 +01:00
|
|
|
created_ids = self.env["account.loan"].generate_loan_entries(self.date)
|
2023-02-07 15:03:13 +01:00
|
|
|
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
|
2021-02-23 11:00:15 +01:00
|
|
|
result["domain"] = [("id", "in", created_ids)]
|
2018-02-26 12:17:24 +01:00
|
|
|
return result
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
self.ensure_one()
|
2021-02-23 11:00:15 +01:00
|
|
|
if self.loan_type == "leasing":
|
2018-02-26 12:17:24 +01:00
|
|
|
return self.run_leasing()
|
|
|
|
return self.run_loan()
|