Skip to content

Commit

Permalink
[MIG]account_asset_management: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
RodrigoBM committed Dec 5, 2022
1 parent 68c30cc commit cf7a976
Show file tree
Hide file tree
Showing 17 changed files with 242 additions and 262 deletions.
2 changes: 1 addition & 1 deletion account_asset_management/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

{
"name": "Assets Management",
"version": "15.0.1.0.1",
"version": "16.0.1.0.0",
"license": "AGPL-3",
"depends": ["account", "report_xlsx_helper"],
"excludes": ["account_asset"],
Expand Down
40 changes: 15 additions & 25 deletions account_asset_management/models/account_asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(self, *args, **argv):

class AccountAsset(models.Model):
_name = "account.asset"
_inherit = ["mail.thread", "mail.activity.mixin"]
_inherit = ["mail.thread", "mail.activity.mixin", "analytic.mixin"]
_description = "Asset"
_order = "date_start desc, code, name"
_check_company_auto = True
Expand Down Expand Up @@ -268,20 +268,6 @@ class AccountAsset(models.Model):
store=True,
readonly=True,
)
account_analytic_id = fields.Many2one(
comodel_name="account.analytic.account",
string="Analytic account",
compute="_compute_account_analytic_id",
readonly=False,
store=True,
)
analytic_tag_ids = fields.Many2many(
comodel_name="account.analytic.tag",
string="Analytic tags",
compute="_compute_analytic_tag_ids",
readonly=False,
store=True,
)
carry_forward_missed_depreciations = fields.Boolean(
string="Accumulate missed depreciations",
help="""If create an asset in a fiscal period that is now closed
Expand Down Expand Up @@ -392,9 +378,9 @@ def _compute_account_analytic_id(self):
asset.account_analytic_id = asset.profile_id.account_analytic_id

@api.depends("profile_id")
def _compute_analytic_tag_ids(self):
def _compute_analytic_distribution(self):
for asset in self:
asset.analytic_tag_ids = asset.profile_id.analytic_tag_ids
asset.analytic_distribution = asset.profile_id.analytic_distribution

@api.constrains("method", "method_time")
def _check_method(self):
Expand Down Expand Up @@ -441,14 +427,18 @@ def _onchange_purchase_salvage_value(self):
{"amount": self.depreciation_base, "line_date": self.date_start}
)

@api.model
def create(self, vals):
asset = super().create(vals)
if self.env.context.get("create_asset_from_move_line"):
# Trigger compute of depreciation_base
asset.salvage_value = 0.0
asset._create_first_asset_line()
return asset
@api.model_create_multi
def create(self, vals_list):
asset_ids = super().create(vals_list)
create_asset_from_move_line = self.env.context.get(
"create_asset_from_move_line"
)
for asset_id in asset_ids:
if create_asset_from_move_line:
# Trigger compute of depreciation_base
asset_id.salvage_value = 0.0
asset_id._create_first_asset_line()
return asset_ids

def write(self, vals):
res = super().write(vals)
Expand Down
2 changes: 1 addition & 1 deletion account_asset_management/models/account_asset_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AccountAssetGroup(models.Model):

name = fields.Char(size=64, required=True, index=True)
code = fields.Char(index=True)
parent_path = fields.Char(index=True)
parent_path = fields.Char(index=True, unaccent=False)
company_id = fields.Many2one(
comodel_name="res.company",
string="Company",
Expand Down
9 changes: 3 additions & 6 deletions account_asset_management/models/account_asset_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,16 +229,14 @@ def _setup_move_line_data(self, depreciation_date, account, ml_type, move):
"""Prepare data to be propagated to account.move.line"""
asset = self.asset_id
amount = self.amount
analytic_id = False
analytic_tags = self.env["account.analytic.tag"]
analytic_distribution = False
if ml_type == "depreciation":
debit = amount < 0 and -amount or 0.0
credit = amount > 0 and amount or 0.0
elif ml_type == "expense":
debit = amount > 0 and amount or 0.0
credit = amount < 0 and -amount or 0.0
analytic_id = asset.account_analytic_id.id
analytic_tags = asset.analytic_tag_ids
analytic_distribution = asset.analytic_distribution
move_line_data = {
"name": asset.name,
"ref": self.name,
Expand All @@ -248,8 +246,7 @@ def _setup_move_line_data(self, depreciation_date, account, ml_type, move):
"debit": debit,
"journal_id": asset.profile_id.journal_id.id,
"partner_id": asset.partner_id.id,
"analytic_account_id": analytic_id,
"analytic_tag_ids": [(4, tag.id) for tag in analytic_tags],
"analytic_distribution": analytic_distribution,
"date": depreciation_date,
"asset_id": asset.id,
}
Expand Down
34 changes: 17 additions & 17 deletions account_asset_management/models/account_asset_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,13 @@

class AccountAssetProfile(models.Model):
_name = "account.asset.profile"
_inherit = "analytic.mixin"
_check_company_auto = True
_description = "Asset profile"
_order = "name"

name = fields.Char(size=64, required=True, index=True)
note = fields.Text()
account_analytic_id = fields.Many2one(
comodel_name="account.analytic.account", string="Analytic account"
)
analytic_tag_ids = fields.Many2many(
comodel_name="account.analytic.tag", string="Analytic tags"
)
account_asset_id = fields.Many2one(
comodel_name="account.account",
domain="[('deprecated', '=', False), ('company_id', '=', company_id)]",
Expand Down Expand Up @@ -207,17 +202,22 @@ def _compute_prorrata(self):
if profile.method_time != "year":
profile.prorata = True

@api.model
def create(self, vals):
if vals.get("method_time") != "year" and not vals.get("prorata"):
vals["prorata"] = True
profile = super().create(vals)
acc_id = vals.get("account_asset_id")
if acc_id:
account = self.env["account.account"].browse(acc_id)
if not account.asset_profile_id:
account.write({"asset_profile_id": profile.id})
return profile
@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
if vals.get("method_time") != "year" and not vals.get("prorata"):
vals["prorata"] = True
profile_ids = super().create(vals_list)
account_dict = {}
for profile_id in profile_ids.filtered(
lambda x: not x.account_asset_id.asset_profile_id
):
account_dict.setdefault(profile_id.account_asset_id, []).append(
profile_id.id
)
for account, profile_list in account_dict.items():
account.write({"asset_profile_id": profile_list[-1]})
return profile_ids

def write(self, vals):
if vals.get("method_time"):
Expand Down
5 changes: 1 addition & 4 deletions account_asset_management/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def _prepare_asset_vals(self, aml):
"purchase_value": depreciation_base,
"partner_id": aml.partner_id,
"date_start": self.date,
"account_analytic_id": aml.analytic_account_id,
"analytic_distribution": aml.analytic_distribution,
}

def action_post(self):
Expand All @@ -105,7 +105,6 @@ def action_post(self):
for key, val in vals.items():
setattr(asset_form, key, val)
asset = asset_form.save()
asset.analytic_tag_ids = aml.analytic_tag_ids
aml.with_context(
allow_asset=True, allow_asset_removal=True
).asset_id = asset.id
Expand Down Expand Up @@ -256,7 +255,5 @@ def _expand_asset_line(self):
qty = self.quantity
name = self.name
aml.write({"quantity": 1, "name": "{} {}".format(name, 1)})
aml._onchange_price_subtotal()
for i in range(1, int(qty)):
aml.copy({"name": "{} {}".format(name, i + 1)})
aml.move_id._onchange_invoice_line_ids()
40 changes: 17 additions & 23 deletions account_asset_management/report/account_asset_report_xls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from odoo import _, models
from odoo.exceptions import UserError
from odoo.tools.translate import translate

from odoo.addons.report_xlsx_helper.report.report_xlsx_format import (
FORMATS,
Expand All @@ -23,11 +22,6 @@ class AssetReportXlsx(models.AbstractModel):
_description = "Dynamic XLS asset report generator"
_inherit = "report.report_xlsx.abstract"

def _(self, src):
lang = self.env.context.get("lang", "en_US")
val = translate(self.env.cr, IR_TRANSLATION_NAME, "report", lang, src) or src
return val

def _get_ws_params(self, wb, data, wiz):
self._get_assets(wiz, data)
s1 = self._get_acquisition_ws_params(wb, data, wiz)
Expand All @@ -39,18 +33,18 @@ def _get_asset_template(self):

asset_template = {
"account": {
"header": {"type": "string", "value": self._("Account")},
"header": {"type": "string", "value": _("Account")},
"asset": {
"type": "string",
"value": self._render(
"asset.profile_id.account_asset_id.code or ''"
),
},
"totals": {"type": "string", "value": self._("Totals")},
"totals": {"type": "string", "value": _("Totals")},
"width": 20,
},
"name": {
"header": {"type": "string", "value": self._("Name")},
"header": {"type": "string", "value": _("Name")},
"asset_group": {
"type": "string",
"value": self._render("group.name or ''"),
Expand All @@ -59,7 +53,7 @@ def _get_asset_template(self):
"width": 40,
},
"code": {
"header": {"type": "string", "value": self._("Reference")},
"header": {"type": "string", "value": _("Reference")},
"asset_group": {
"type": "string",
"value": self._render("group.code or ''"),
Expand All @@ -68,15 +62,15 @@ def _get_asset_template(self):
"width": 20,
},
"date_start": {
"header": {"type": "string", "value": self._("Asset Start Date")},
"header": {"type": "string", "value": _("Asset Start Date")},
"asset": {
"value": self._render("asset.date_start or ''"),
"format": FORMATS["format_tcell_date_left"],
},
"width": 20,
},
"date_remove": {
"header": {"type": "string", "value": self._("Asset Removal Date")},
"header": {"type": "string", "value": _("Asset Removal Date")},
"asset": {
"value": self._render("asset.date_remove or ''"),
"format": FORMATS["format_tcell_date_left"],
Expand All @@ -86,7 +80,7 @@ def _get_asset_template(self):
"depreciation_base": {
"header": {
"type": "string",
"value": self._("Depreciation Base"),
"value": _("Depreciation Base"),
"format": FORMATS["format_theader_yellow_right"],
},
"asset_group": {
Expand All @@ -109,7 +103,7 @@ def _get_asset_template(self):
"salvage_value": {
"header": {
"type": "string",
"value": self._("Salvage Value"),
"value": _("Salvage Value"),
"format": FORMATS["format_theader_yellow_right"],
},
"asset_group": {
Expand All @@ -132,7 +126,7 @@ def _get_asset_template(self):
"purchase_value": {
"header": {
"type": "string",
"value": self._("Purchase Value"),
"value": _("Purchase Value"),
"format": FORMATS["format_theader_yellow_right"],
},
"asset_group": {
Expand All @@ -155,7 +149,7 @@ def _get_asset_template(self):
"period_start_value": {
"header": {
"type": "string",
"value": self._("Period Start Value"),
"value": _("Period Start Value"),
"format": FORMATS["format_theader_yellow_right"],
},
"asset_group": {
Expand All @@ -178,7 +172,7 @@ def _get_asset_template(self):
"period_depr": {
"header": {
"type": "string",
"value": self._("Period Depreciation"),
"value": _("Period Depreciation"),
"format": FORMATS["format_theader_yellow_right"],
},
"asset_group": {
Expand All @@ -201,7 +195,7 @@ def _get_asset_template(self):
"period_end_value": {
"header": {
"type": "string",
"value": self._("Period End Value"),
"value": _("Period End Value"),
"format": FORMATS["format_theader_yellow_right"],
},
"asset_group": {
Expand All @@ -224,7 +218,7 @@ def _get_asset_template(self):
"period_end_depr": {
"header": {
"type": "string",
"value": self._("Tot. Depreciation"),
"value": _("Tot. Depreciation"),
"format": FORMATS["format_theader_yellow_right"],
},
"asset_group": {
Expand All @@ -247,7 +241,7 @@ def _get_asset_template(self):
"method": {
"header": {
"type": "string",
"value": self._("Comput. Method"),
"value": _("Comput. Method"),
"format": FORMATS["format_theader_yellow_center"],
},
"asset": {
Expand All @@ -260,7 +254,7 @@ def _get_asset_template(self):
"method_number": {
"header": {
"type": "string",
"value": self._("Number of Years"),
"value": _("Number of Years"),
"format": FORMATS["format_theader_yellow_center"],
},
"asset": {
Expand All @@ -273,7 +267,7 @@ def _get_asset_template(self):
"prorata": {
"header": {
"type": "string",
"value": self._("Prorata Temporis"),
"value": _("Prorata Temporis"),
"format": FORMATS["format_theader_yellow_center"],
},
"asset": {
Expand All @@ -286,7 +280,7 @@ def _get_asset_template(self):
"state": {
"header": {
"type": "string",
"value": self._("Status"),
"value": _("Status"),
"format": FORMATS["format_theader_yellow_center"],
},
"asset": {
Expand Down
Loading

0 comments on commit cf7a976

Please sign in to comment.