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 Oct 17, 2022
1 parent 695bb69 commit c2ec97d
Show file tree
Hide file tree
Showing 17 changed files with 163 additions and 211 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
18 changes: 3 additions & 15 deletions account_asset_management/models/account_asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,6 @@ class AccountAsset(models.Model):
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 @@ -391,11 +384,6 @@ def _compute_account_analytic_id(self):
for asset in self:
asset.account_analytic_id = asset.profile_id.account_analytic_id

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

@api.constrains("method", "method_time")
def _check_method(self):
if self.filtered(
Expand Down Expand Up @@ -441,9 +429,9 @@ 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)
@api.model_create_multi
def create(self, vals_list):
asset = super().create(vals_list)
if self.env.context.get("create_asset_from_move_line"):
# Trigger compute of depreciation_base
asset.salvage_value = 0.0
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
7 changes: 3 additions & 4 deletions account_asset_management/models/account_asset_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,13 @@ def _setup_move_line_data(self, depreciation_date, account, ml_type, move):
asset = self.asset_id
amount = self.amount
analytic_id = False
analytic_tags = self.env["account.analytic.tag"]
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
move_line_data = {
"name": asset.name,
"ref": self.name,
Expand All @@ -248,11 +246,12 @@ 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": {},
"date": depreciation_date,
"asset_id": asset.id,
}
if analytic_id:
move_line_data["analytic_distribution"][analytic_id] = 100
return move_line_data

def create_move(self):
Expand Down
14 changes: 6 additions & 8 deletions account_asset_management/models/account_asset_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ class AccountAssetProfile(models.Model):
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,11 +204,12 @@ 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)
@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 = super().create(vals_list)
acc_id = vals.get("account_asset_id")
if acc_id:
account = self.env["account.account"].browse(acc_id)
Expand Down
4 changes: 0 additions & 4 deletions account_asset_management/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ 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,
}

def action_post(self):
Expand All @@ -105,7 +104,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 +254,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 c2ec97d

Please sign in to comment.