2
0

[MIG]account_asset_management: Migration to 15.0

This commit is contained in:
manu 2022-04-13 12:18:36 +02:00 committed by Rodrigo
parent 9d5714cd94
commit 6fc511524d
17 changed files with 338 additions and 325 deletions

View File

@ -5,7 +5,7 @@
{
"name": "Assets Management",
"version": "14.0.2.7.0",
"version": "15.0.1.0.0",
"license": "AGPL-3",
"depends": ["account", "report_xlsx_helper"],
"excludes": ["account_asset"],

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<data noupdate="1">
<odoo noupdate="1">
<record forcecreate="True" id="ir_cron_assets_generator" model="ir.cron">
<field name="name">Asset Management: Generate assets</field>
<field name="model_id" ref="model_account_asset_compute" />
@ -13,5 +12,4 @@
<field name="active" eval="False" />
<field name="doall" eval="False" />
</record>
</data>
</odoo>

View File

@ -59,7 +59,6 @@ class AccountAsset(models.Model):
states=READONLY_STATES,
)
purchase_value = fields.Float(
string="Purchase Value",
required=True,
states=READONLY_STATES,
help="This amount represent the initial value of the asset."
@ -67,7 +66,6 @@ class AccountAsset(models.Model):
"\nPurchase Value - Salvage Value.",
)
salvage_value = fields.Float(
string="Salvage Value",
digits="Account",
states=READONLY_STATES,
help="The estimated value that an asset will realize upon "
@ -77,7 +75,6 @@ class AccountAsset(models.Model):
depreciation_base = fields.Float(
compute="_compute_depreciation_base",
digits="Account",
string="Depreciation Base",
store=True,
help="This amount represent the depreciation base "
"of the asset (Purchase Value - Salvage Value).",
@ -94,7 +91,7 @@ class AccountAsset(models.Model):
string="Depreciated Value",
store=True,
)
note = fields.Text("Note")
note = fields.Text()
profile_id = fields.Many2one(
comodel_name="account.asset.profile",
string="Asset Profile",
@ -227,7 +224,6 @@ class AccountAsset(models.Model):
help="Use number of days to calculate depreciation amount",
)
use_leap_years = fields.Boolean(
string="Use leap years",
compute="_compute_use_leap_years",
readonly=False,
store=True,
@ -1241,13 +1237,11 @@ class AccountAsset(models.Model):
asset_ref = depreciation.asset_id.name
if depreciation.asset_id.code:
asset_ref = "[{}] {}".format(depreciation.asset_id.code, asset_ref)
error_log += _("\nError while processing asset '%s': %s") % (
asset_ref,
str(e),
)
error_msg = _("Error while processing asset '%s': \n\n%s") % (
asset_ref,
tb,
error_log += _(
"\nError while processing asset '{ref}': {exception}"
).format(ref=asset_ref, exception=str(e))
error_msg = _("Error while processing asset '{ref}': \n\n{tb}").format(
ref=asset_ref, tb=tb
)
_logger.error("%s, %s", self._name, error_msg)

View File

@ -14,7 +14,7 @@ class AccountAssetGroup(models.Model):
_parent_store = True
_check_company_auto = True
name = fields.Char(string="Name", size=64, required=True, index=True)
name = fields.Char(size=64, required=True, index=True)
code = fields.Char(index=True)
parent_path = fields.Char(index=True)
company_id = fields.Many2one(

View File

@ -31,7 +31,7 @@ class AccountAssetLine(models.Model):
depreciation_base = fields.Float(
related="asset_id.depreciation_base", string="Depreciation Base", readonly=True
)
amount = fields.Float(string="Amount", digits="Account", required=True)
amount = fields.Float(digits="Account", required=True)
remaining_value = fields.Float(
compute="_compute_values",
digits="Account",
@ -263,17 +263,17 @@ class AccountAssetLine(models.Model):
asset = line.asset_id
depreciation_date = line.line_date
am_vals = line._setup_move_data(depreciation_date)
move = self.env["account.move"].with_context(ctx).create(am_vals)
move = self.env["account.move"].with_context(**ctx).create(am_vals)
depr_acc = asset.profile_id.account_depreciation_id
exp_acc = asset.profile_id.account_expense_depreciation_id
aml_d_vals = line._setup_move_line_data(
depreciation_date, depr_acc, "depreciation", move
)
self.env["account.move.line"].with_context(ctx).create(aml_d_vals)
self.env["account.move.line"].with_context(**ctx).create(aml_d_vals)
aml_e_vals = line._setup_move_line_data(
depreciation_date, exp_acc, "expense", move
)
self.env["account.move.line"].with_context(ctx).create(aml_e_vals)
self.env["account.move.line"].with_context(**ctx).create(aml_e_vals)
move.action_post()
line.with_context(allow_asset_line_update=True).write({"move_id": move.id})
created_move_ids.append(move.id)

View File

@ -11,7 +11,7 @@ class AccountAssetProfile(models.Model):
_description = "Asset profile"
_order = "name"
name = fields.Char(string="Name", size=64, required=True, index=True)
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"
@ -129,7 +129,6 @@ class AccountAssetProfile(models.Model):
help="Use number of days to calculate depreciation amount",
)
use_leap_years = fields.Boolean(
string="Use leap years",
default=False,
help="If not set, the system will distribute evenly the amount to "
"amortize across the years, based on the number of years. "

View File

@ -8,7 +8,7 @@ class AccountAssetRecomputeTrigger(models.Model):
_name = "account.asset.recompute.trigger"
_description = "Asset table recompute triggers"
reason = fields.Char(string="Reason", required=True)
reason = fields.Char(required=True)
company_id = fields.Many2one("res.company", string="Company", required=True)
date_trigger = fields.Datetime(
"Trigger Date",
@ -18,7 +18,6 @@ class AccountAssetRecomputeTrigger(models.Model):
date_completed = fields.Datetime("Completion Date", readonly=True)
state = fields.Selection(
selection=[("open", "Open"), ("done", "Done")],
string="State",
default="open",
readonly=True,
)

View File

@ -85,7 +85,7 @@ class AccountMove(models.Model):
}
def action_post(self):
super().action_post()
ret_val = super().action_post()
for move in self:
for aml in move.line_ids.filtered(
lambda line: line.asset_profile_id and not line.tax_line_id
@ -119,12 +119,13 @@ class AccountMove(models.Model):
if refs:
message = _("This invoice created the asset(s): %s") % ", ".join(refs)
move.message_post(body=message)
return ret_val
def button_draft(self):
invoices = self.filtered(lambda r: r.is_purchase_document())
if invoices:
invoices.line_ids.asset_id.unlink()
super().button_draft()
return super().button_draft()
def _reverse_move_vals(self, default_values, cancel=True):
move_vals = super()._reverse_move_vals(default_values, cancel)

View File

@ -20,3 +20,7 @@
* Jordi Ballester <jordi.ballester@forgeflow.com>
* Miquel Raïch <miquel.raich@forgeflow.com>
* `Sygel <https://www.sygel.es>`_:
* Manuel Regidor <manuel.regidor@sygel.es>

View File

@ -308,8 +308,8 @@ class AssetReportXlsx(models.AbstractModel):
self.env["account.asset"]._xls_acquisition_template()
)
wl_acq = self.env["account.asset"]._xls_acquisition_fields()
title = self._get_title(wiz, "acquisition", format="normal")
title_short = self._get_title(wiz, "acquisition", format="short")
title = self._get_title(wiz, "acquisition", frmt="normal")
title_short = self._get_title(wiz, "acquisition", frmt="short")
sheet_name = title_short[:31].replace("/", "-")
return {
@ -326,8 +326,8 @@ class AssetReportXlsx(models.AbstractModel):
active_template = self._get_asset_template()
active_template.update(self.env["account.asset"]._xls_active_template())
wl_act = self.env["account.asset"]._xls_active_fields()
title = self._get_title(wiz, "active", format="normal")
title_short = self._get_title(wiz, "active", format="short")
title = self._get_title(wiz, "active", frmt="normal")
title_short = self._get_title(wiz, "active", frmt="short")
sheet_name = title_short[:31].replace("/", "-")
return {
@ -344,8 +344,8 @@ class AssetReportXlsx(models.AbstractModel):
removal_template = self._get_asset_template()
removal_template.update(self.env["account.asset"]._xls_removal_template())
wl_dsp = self.env["account.asset"]._xls_removal_fields()
title = self._get_title(wiz, "removal", format="normal")
title_short = self._get_title(wiz, "removal", format="short")
title = self._get_title(wiz, "removal", frmt="normal")
title_short = self._get_title(wiz, "removal", frmt="short")
sheet_name = title_short[:31].replace("/", "-")
return {
@ -357,21 +357,21 @@ class AssetReportXlsx(models.AbstractModel):
"report_type": "removal",
}
def _get_title(self, wiz, report, format="normal"):
def _get_title(self, wiz, report, frmt="normal"):
prefix = "{} - {}".format(wiz.date_from, wiz.date_to)
if report == "acquisition":
if format == "normal":
if frmt == "normal":
title = prefix + " : " + _("New Acquisitions")
else:
title = "ACQ"
elif report == "active":
if format == "normal":
if frmt == "normal":
title = prefix + " : " + _("Active Assets")
else:
title = "ACT"
else:
if format == "normal":
if frmt == "normal":
title = prefix + " : " + _("Removed Assets")
else:
title = "DSP"
@ -412,9 +412,8 @@ class AssetReportXlsx(models.AbstractModel):
raise UserError(
_(
"Inconsistent reporting structure."
"\nPlease correct Asset Group '%s' (id %s)"
)
% (child.name, child.id)
"\nPlease correct Asset Group '{group}' (id {id})"
).format(group=child.name, id=child.id)
)
groups.extend(_child_get(child))
return groups
@ -468,8 +467,8 @@ class AssetReportXlsx(models.AbstractModel):
report = ws_params["report_type"]
def asset_filter(asset):
filter = getattr(self, "{}_filter".format(report))
return filter(wiz, asset)
filt = getattr(self, "{}_filter".format(report))
return filt(wiz, asset)
def _has_assets(group, group_val):
assets = group_val.get("assets")
@ -567,8 +566,8 @@ class AssetReportXlsx(models.AbstractModel):
row_pos = self._report_title(ws, row_pos, ws_params, data, wiz)
def asset_filter(asset):
filter = getattr(self, "{}_filter".format(report))
return filter(wiz, asset)
filt = getattr(self, "{}_filter".format(report))
return filt(wiz, asset)
assets = data["assets"].filtered(asset_filter)

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<data noupdate="1">
<odoo noupdate="1">
<record id="account_asset_profile_multi_company_rule" model="ir.rule">
<field name="name">Account Asset Profile multi-company</field>
<field ref="model_account_asset_profile" name="model_id" />
@ -25,5 +24,4 @@
name="domain_force"
>['|', ('company_id', '=', False), ('company_id', 'in', company_ids)]</field>
</record>
</data>
</odoo>

View File

@ -7,7 +7,7 @@ import calendar
import time
from datetime import date, datetime
from odoo import fields
from odoo import Command, fields
from odoo.tests.common import Form
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
@ -27,37 +27,58 @@ class TestAssetManagement(AccountTestInvoicingCommon):
cls.product = cls.env["product.product"].create(
{"name": "Test", "standard_price": 500.0}
)
move_form = Form(
cls.env["account.move"].with_context(
default_move_type="in_invoice", check_move_validity=False
cls.invoice = (
cls.env["account.move"]
.with_context(check_move_validity=False)
.create(
{
"move_type": "in_invoice",
"invoice_date": fields.Date.context_today(cls.env.user),
"partner_id": cls.partner.id,
"invoice_line_ids": [
Command.create(
{
"name": "test",
"product_id": cls.product.id,
"price_unit": 2000.00,
"quantity": 1,
}
),
],
}
)
)
move_form.invoice_date = fields.Date.context_today(cls.env.user)
move_form.partner_id = cls.partner
with move_form.invoice_line_ids.new() as line_form:
line_form.name = "test"
line_form.product_id = cls.product
line_form.price_unit = 2000.00
line_form.quantity = 1
cls.invoice = move_form.save()
move_form = Form(
cls.env["account.move"].with_context(
default_move_type="in_invoice", check_move_validity=False
cls.invoice_2 = (
cls.env["account.move"]
.with_context(check_move_validity=False)
.create(
{
"move_type": "in_invoice",
"invoice_date": fields.Date.context_today(cls.env.user),
"partner_id": cls.partner.id,
"invoice_line_ids": [
Command.create(
{
"name": "test 2",
"product_id": cls.product.id,
"price_unit": 10000.00,
"quantity": 1,
}
),
Command.create(
{
"name": "test 3",
"product_id": cls.product.id,
"price_unit": 20000.00,
"quantity": 1,
}
),
],
}
)
)
move_form.invoice_date = fields.Date.context_today(cls.env.user)
move_form.partner_id = cls.partner
with move_form.invoice_line_ids.new() as line_form:
line_form.name = "test 2"
line_form.product_id = cls.product
line_form.price_unit = 10000.00
line_form.quantity = 1
with move_form.invoice_line_ids.new() as line_form:
line_form.name = "test 3"
line_form.product_id = cls.product
line_form.price_unit = 20000.00
line_form.quantity = 1
cls.invoice_2 = move_form.save()
# analytic configuration
cls.env.user.write(
@ -121,20 +142,28 @@ class TestAssetManagement(AccountTestInvoicingCommon):
"amount": 15.0,
}
)
move_form = Form(
self.env["account.move"].with_context(
default_move_type="in_invoice", check_move_validity=False
invoice = (
self.env["account.move"]
.with_context(check_move_validity=False)
.create(
{
"move_type": "in_invoice",
"invoice_date": fields.Date.context_today(self.env.user),
"partner_id": self.partner.id,
"invoice_line_ids": [
Command.create(
{
"name": "Line 1",
"price_unit": 200.0,
"quantity": 1,
"tax_ids": [tax.id],
}
),
],
}
)
)
move_form.invoice_date = fields.Date.context_today(self.env.user)
move_form.partner_id = self.partner
with move_form.invoice_line_ids.new() as line_form:
line_form.name = "Line 1"
line_form.price_unit = 200.0
line_form.quantity = 1
line_form.tax_ids.clear()
line_form.tax_ids.add(tax)
invoice = move_form.save()
self.assertEqual(invoice.partner_id, self.partner)
def test_00_fiscalyear_lock_date_month(self):
@ -510,7 +539,7 @@ class TestAssetManagement(AccountTestInvoicingCommon):
asset.compute_depreciation_board()
asset.validate()
wiz_ctx = {"active_id": asset.id, "early_removal": True}
wiz = self.remove_model.with_context(wiz_ctx).create(
wiz = self.remove_model.with_context(**wiz_ctx).create(
{
"date_remove": "2019-01-31",
"sale_value": 0.0,
@ -535,11 +564,10 @@ class TestAssetManagement(AccountTestInvoicingCommon):
self.assertTrue(len(invoice.invoice_line_ids) > 0)
line = invoice.invoice_line_ids[0]
self.assertTrue(line.price_unit > 0.0)
move_form = Form(invoice)
with move_form.invoice_line_ids.edit(0) as line_form:
line_form.quantity = 2
line_form.asset_profile_id = asset_profile
invoice = move_form.save()
invoice.invoice_line_ids[0].write(
{"quantity": 2, "asset_profile_id": asset_profile.id}
)
invoice._onchange_invoice_line_ids()
invoice.action_post()
# get all asset after invoice validation
current_asset = self.env["account.asset"].search([])
@ -577,8 +605,7 @@ class TestAssetManagement(AccountTestInvoicingCommon):
def test_11_assets_from_invoice(self):
all_assets = self.env["account.asset"].search([])
ctx = dict(self.invoice_2._context)
del ctx["default_move_type"]
invoice = self.invoice_2.with_context(ctx)
invoice = self.invoice_2.with_context(**ctx)
asset_profile = self.car5y
asset_profile.asset_product_item = True
# Compute depreciation lines on invoice validation
@ -837,7 +864,7 @@ class TestAssetManagement(AccountTestInvoicingCommon):
)
wiz = Form(
self.env["wiz.asset.move.reverse"].with_context(
{
**{
"active_model": depreciation_line._name,
"active_id": depreciation_line.id,
"active_ids": [depreciation_line.id],
@ -845,6 +872,7 @@ class TestAssetManagement(AccountTestInvoicingCommon):
)
)
reverse_wizard = wiz.save()
reverse_wizard.write({"journal_id": depreciation_line.move_id.journal_id.id})
reverse_wizard.reverse_move()
ict0.refresh()
self.assertEqual(ict0.value_depreciated, 0)

View File

@ -174,7 +174,6 @@
options="{'reload_on_button': true}"
>
<tree
string="Asset Lines"
decoration-info="(move_check == False) and (init_entry == False)"
create="false"
>
@ -252,7 +251,7 @@
</page>
<page string="History">
<field name="account_move_line_ids" readonly="1">
<tree string="Journal Items">
<tree>
<field name="date" />
<field name="move_id" />
<field name="journal_id" optional="show" />
@ -290,7 +289,7 @@
<field name="name">account.asset.tree</field>
<field name="model">account.asset</field>
<field name="arch" type="xml">
<tree string="Assets">
<tree>
<field name="name" />
<field name="code" optional="show" />
<field name="depreciation_base" optional="show" />

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<data>
<record id="account_asset_group_view_form" model="ir.ui.view">
<field name="name">account.asset.group.form</field>
<field name="model">account.asset.group</field>
@ -25,7 +24,7 @@
<field name="name">account.asset.group.tree</field>
<field name="model">account.asset.group</field>
<field name="arch" type="xml">
<tree string="Asset Group" editable="bottom">
<tree editable="bottom">
<field name="name" />
<field name="code" optional="show" />
<field name="parent_id" />
@ -49,5 +48,4 @@
<field name="res_model">account.asset.group</field>
<field name="view_mode">tree,form</field>
</record>
</data>
</odoo>

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<data>
<record id="account_asset_profile_view_form" model="ir.ui.view">
<field name="name">account.asset.profile.form</field>
<field name="model">account.asset.profile</field>
@ -87,7 +86,7 @@
<field name="name">account.asset.profile.tree</field>
<field name="model">account.asset.profile</field>
<field name="arch" type="xml">
<tree string="Asset profile">
<tree>
<field name="name" />
<field name="method_number" optional="hide" />
<field name="method_period" optional="hide" />
@ -141,5 +140,4 @@
<field name="res_model">account.asset.profile</field>
<field name="view_mode">tree,form</field>
</record>
</data>
</odoo>

View File

@ -32,9 +32,7 @@ class AccountAssetRemove(models.TransientModel):
"in case of early removal",
)
force_date = fields.Date(string="Force accounting date")
sale_value = fields.Float(
string="Sale Value", default=lambda self: self._default_sale_value()
)
sale_value = fields.Float(default=lambda self: self._default_sale_value())
account_sale_id = fields.Many2one(
comodel_name="account.account",
string="Asset Sale Account",

View File

@ -18,7 +18,7 @@ class WizAssetMoveReverse(models.TransientModel):
required=True,
default=fields.Date.context_today,
)
reason = fields.Char(string="Reason")
reason = fields.Char()
journal_id = fields.Many2one(
"account.journal",
string="Use Specific Journal",