2018-08-05 20:33:56 +02:00
|
|
|
# Copyright 2009-2018 Noviat
|
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
|
|
|
|
2020-01-29 18:37:08 +01:00
|
|
|
from odoo import _, fields, models
|
2018-08-05 20:33:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
class AccountAssetCompute(models.TransientModel):
|
2020-01-29 18:34:31 +01:00
|
|
|
_name = "account.asset.compute"
|
2018-08-05 20:33:56 +02:00
|
|
|
_description = "Compute Assets"
|
|
|
|
|
|
|
|
date_end = fields.Date(
|
2020-01-29 18:34:31 +01:00
|
|
|
string="Date",
|
|
|
|
required=True,
|
2018-08-05 20:33:56 +02:00
|
|
|
default=fields.Date.today,
|
|
|
|
help="All depreciation lines prior to this date will be automatically"
|
2020-01-29 18:34:31 +01:00
|
|
|
" posted",
|
|
|
|
)
|
2018-08-05 20:33:56 +02:00
|
|
|
note = fields.Text()
|
|
|
|
|
|
|
|
def asset_compute(self):
|
2020-01-29 18:34:31 +01:00
|
|
|
assets = self.env["account.asset"].search([("state", "=", "open")])
|
2018-08-05 20:33:56 +02:00
|
|
|
created_move_ids, error_log = assets._compute_entries(
|
2020-01-29 18:34:31 +01:00
|
|
|
self.date_end, check_triggers=True
|
|
|
|
)
|
2018-08-05 20:33:56 +02:00
|
|
|
|
|
|
|
if error_log:
|
2020-01-29 18:34:31 +01:00
|
|
|
module = __name__.split("addons.")[1].split(".")[0]
|
2020-01-29 18:37:08 +01:00
|
|
|
result_view = self.env.ref(
|
|
|
|
"{}.{}_view_form_result".format(module, self._table)
|
|
|
|
)
|
2020-01-29 18:34:31 +01:00
|
|
|
self.note = _("Compute Assets errors") + ":\n" + error_log
|
2018-08-05 20:33:56 +02:00
|
|
|
return {
|
2020-01-29 18:34:31 +01:00
|
|
|
"name": _("Compute Assets result"),
|
|
|
|
"res_id": self.id,
|
|
|
|
"view_mode": "form",
|
|
|
|
"res_model": "account.asset.compute",
|
|
|
|
"view_id": result_view.id,
|
|
|
|
"target": "new",
|
|
|
|
"type": "ir.actions.act_window",
|
|
|
|
"context": {"asset_move_ids": created_move_ids},
|
2018-08-05 20:33:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
2020-01-29 18:34:31 +01:00
|
|
|
"name": _("Created Asset Moves"),
|
|
|
|
"view_mode": "tree,form",
|
|
|
|
"res_model": "account.move",
|
|
|
|
"view_id": False,
|
|
|
|
"domain": [("id", "in", created_move_ids)],
|
|
|
|
"type": "ir.actions.act_window",
|
2018-08-05 20:33:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
def view_asset_moves(self):
|
|
|
|
self.ensure_one()
|
2020-01-29 18:34:31 +01:00
|
|
|
domain = [("id", "in", self.env.context.get("asset_move_ids", []))]
|
2018-08-05 20:33:56 +02:00
|
|
|
return {
|
2020-01-29 18:34:31 +01:00
|
|
|
"name": _("Created Asset Moves"),
|
|
|
|
"view_mode": "tree,form",
|
|
|
|
"res_model": "account.move",
|
|
|
|
"view_id": False,
|
|
|
|
"domain": domain,
|
|
|
|
"type": "ir.actions.act_window",
|
2018-08-05 20:33:56 +02:00
|
|
|
}
|