[FIX] account_asset_management: create asset using Form
This way, the computes are computed as expected.
This commit is contained in:
parent
b1b0952153
commit
c964dccf2c
@ -7,6 +7,7 @@ import logging
|
|||||||
|
|
||||||
from odoo import _, api, fields, models
|
from odoo import _, api, fields, models
|
||||||
from odoo.exceptions import UserError
|
from odoo.exceptions import UserError
|
||||||
|
from odoo.tests.common import Form
|
||||||
|
|
||||||
_logger = logging.getLogger(__name__)
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -72,20 +73,25 @@ class AccountMove(models.Model):
|
|||||||
vals = {
|
vals = {
|
||||||
"name": aml.name,
|
"name": aml.name,
|
||||||
"code": move.name,
|
"code": move.name,
|
||||||
"profile_id": aml.asset_profile_id.id,
|
"profile_id": aml.asset_profile_id,
|
||||||
"purchase_value": depreciation_base,
|
"purchase_value": depreciation_base,
|
||||||
"partner_id": aml.partner_id.id,
|
"partner_id": aml.partner_id,
|
||||||
"date_start": move.date,
|
"date_start": move.date,
|
||||||
"account_analytic_id": aml.analytic_account_id.id,
|
"account_analytic_id": aml.analytic_account_id,
|
||||||
"analytic_tag_ids": aml.analytic_tag_ids.id,
|
|
||||||
}
|
}
|
||||||
if self.env.context.get("company_id"):
|
if self.env.context.get("company_id"):
|
||||||
vals["company_id"] = self.env.context["company_id"]
|
vals["company_id"] = self.env["res.company"].browse(
|
||||||
asset = (
|
self.env.context["company_id"]
|
||||||
self.env["account.asset"]
|
)
|
||||||
.with_context(create_asset_from_move_line=True, move_id=move.id)
|
asset_form = Form(
|
||||||
.create(vals)
|
self.env["account.asset"].with_context(
|
||||||
|
create_asset_from_move_line=True, move_id=move.id
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
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).asset_id = asset.id
|
aml.with_context(allow_asset=True).asset_id = asset.id
|
||||||
refs = [
|
refs = [
|
||||||
"<a href=# data-oe-model=account.asset data-oe-id=%s>%s</a>"
|
"<a href=# data-oe-model=account.asset data-oe-id=%s>%s</a>"
|
||||||
|
Loading…
Reference in New Issue
Block a user