mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
[MIG] account_asset_management: Migration to v14
TT26410
This commit is contained in:
@@ -4,5 +4,4 @@ from . import account_asset_group
|
||||
from . import account_asset_profile
|
||||
from . import account_asset_line
|
||||
from . import account_asset_recompute_trigger
|
||||
from . import account_fiscal_year
|
||||
from . import account_move
|
||||
|
||||
@@ -45,8 +45,16 @@ class AccountAsset(models.Model):
|
||||
move_line_check = fields.Boolean(
|
||||
compute="_compute_move_line_check", string="Has accounting entries"
|
||||
)
|
||||
name = fields.Char(string="Asset Name", required=True, states=READONLY_STATES,)
|
||||
code = fields.Char(string="Reference", size=32, states=READONLY_STATES,)
|
||||
name = fields.Char(
|
||||
string="Asset Name",
|
||||
required=True,
|
||||
states=READONLY_STATES,
|
||||
)
|
||||
code = fields.Char(
|
||||
string="Reference",
|
||||
size=32,
|
||||
states=READONLY_STATES,
|
||||
)
|
||||
purchase_value = fields.Float(
|
||||
string="Purchase Value",
|
||||
required=True,
|
||||
@@ -133,7 +141,9 @@ class AccountAsset(models.Model):
|
||||
)
|
||||
active = fields.Boolean(default=True)
|
||||
partner_id = fields.Many2one(
|
||||
comodel_name="res.partner", string="Partner", states=READONLY_STATES,
|
||||
comodel_name="res.partner",
|
||||
string="Partner",
|
||||
states=READONLY_STATES,
|
||||
)
|
||||
method = fields.Selection(
|
||||
selection=lambda self: self.env["account.asset.profile"]._selection_method(),
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# Copyright 2009-2018 Noviat
|
||||
# Copyright 2021 Tecnativa - João Marques
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import _, api, fields, models
|
||||
@@ -255,7 +256,7 @@ class AccountAssetLine(models.Model):
|
||||
depreciation_date, exp_acc, "expense", move
|
||||
)
|
||||
self.env["account.move.line"].with_context(ctx).create(aml_e_vals)
|
||||
move.post()
|
||||
move.action_post()
|
||||
line.with_context(allow_asset_line_update=True).write({"move_id": move.id})
|
||||
created_move_ids.append(move.id)
|
||||
asset_ids.add(asset.id)
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
# Copyright 2009-2017 Noviat
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
import logging
|
||||
import time
|
||||
from datetime import datetime
|
||||
|
||||
from dateutil.relativedelta import relativedelta
|
||||
|
||||
from odoo import api, models
|
||||
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class AccountFiscalYear(models.Model):
|
||||
_inherit = "account.fiscal.year"
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
date_from = datetime.strptime(vals.get("date_from"), "%Y-%m-%d")
|
||||
date_to = datetime.strptime(vals.get("date_to"), "%Y-%m-%d")
|
||||
if not date_to == date_from + relativedelta(years=1, days=-1):
|
||||
recompute_vals = {
|
||||
"reason": "creation of fiscalyear %s" % vals.get("name"),
|
||||
"company_id": vals.get("company_id") or self.env.user.company_id.id,
|
||||
"date_trigger": time.strftime(DEFAULT_SERVER_DATETIME_FORMAT),
|
||||
"state": "open",
|
||||
}
|
||||
self.env["account.asset.recompute.trigger"].sudo().create(recompute_vals)
|
||||
return super().create(vals)
|
||||
|
||||
def write(self, vals):
|
||||
if vals.get("date_from") or vals.get("date_to"):
|
||||
for fy in self:
|
||||
recompute_vals = {
|
||||
"reason": "duration change of fiscalyear %s" % fy.name,
|
||||
"company_id": fy.company_id.id,
|
||||
"date_trigger": time.strftime(DEFAULT_SERVER_DATETIME_FORMAT),
|
||||
"state": "open",
|
||||
}
|
||||
self.env["account.asset.recompute.trigger"].sudo().create(
|
||||
recompute_vals
|
||||
)
|
||||
return super().write(vals)
|
||||
@@ -1,4 +1,5 @@
|
||||
# Copyright 2009-2018 Noviat
|
||||
# Copyright 2021 Tecnativa - João Marques
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
import logging
|
||||
@@ -58,11 +59,11 @@ class AccountMove(models.Model):
|
||||
)
|
||||
return super().write(vals)
|
||||
|
||||
def post(self):
|
||||
super().post()
|
||||
def action_post(self):
|
||||
super().action_post()
|
||||
for move in self:
|
||||
for aml in move.line_ids.filtered("asset_profile_id"):
|
||||
depreciation_base = aml.debit or -aml.credit
|
||||
depreciation_base = aml.price_subtotal
|
||||
vals = {
|
||||
"name": aml.name,
|
||||
"code": move.name,
|
||||
|
||||
Reference in New Issue
Block a user