2
0

[MIG] account_asset_management: Migration to v14

TT26410
This commit is contained in:
João Marques 2021-01-14 07:53:25 +00:00 committed by Rodrigo
parent 2aa11d4e40
commit dd7e4e08df
17 changed files with 203 additions and 319 deletions

View File

@ -14,13 +14,13 @@ Assets Management
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--financial--tools-lightgray.png?logo=github
:target: https://github.com/OCA/account-financial-tools/tree/13.0/account_asset_management
:target: https://github.com/OCA/account-financial-tools/tree/14.0/account_asset_management
:alt: OCA/account-financial-tools
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/account-financial-tools-13-0/account-financial-tools-13-0-account_asset_management
:target: https://translation.odoo-community.org/projects/account-financial-tools-14-0/account-financial-tools-14-0-account_asset_management
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/92/13.0
:target: https://runbot.odoo-community.org/runbot/92/14.0
:alt: Try me on Runbot
|badge1| |badge2| |badge3| |badge4| |badge5|
@ -60,6 +60,11 @@ The module in NOT compatible with the standard account_asset module.
Changelog
=========
14.0.1.0.0 (2021-01-08)
~~~~~~~~~~~~~~~~~~~~~~~
* [BREAKING] Removed all functionality associated with `account.fiscal.year`
13.0.1.0.0 (2019-10-21)
~~~~~~~~~~~~~~~~~~~~~~~
@ -94,7 +99,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-financial-tools/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/account-financial-tools/issues/new?body=module:%20account_asset_management%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/account-financial-tools/issues/new?body=module:%20account_asset_management%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Do not contact contributors directly about support or help with technical issues.
@ -124,6 +129,7 @@ Contributors
* Ernesto Tejeda
* Pedro M. Baeza
* João Marques
Maintainers
~~~~~~~~~~~
@ -138,6 +144,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
This module is part of the `OCA/account-financial-tools <https://github.com/OCA/account-financial-tools/tree/13.0/account_asset_management>`_ project on GitHub.
This module is part of the `OCA/account-financial-tools <https://github.com/OCA/account-financial-tools/tree/14.0/account_asset_management>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@ -1,10 +1,11 @@
# Copyright 2009-2018 Noviat
# Copyright 2019 Tecnativa - Pedro M. Baeza
# Copyright 2021 Tecnativa - João Marques
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Assets Management",
"version": "13.0.1.3.2",
"version": "14.0.1.0.0",
"license": "AGPL-3",
"depends": ["account"],
"excludes": ["account_asset"],

View File

@ -1,27 +0,0 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import SUPERUSER_ID, api
def migrate(cr, version):
with api.Environment.manage():
env = api.Environment(cr, SUPERUSER_ID, {})
domain = "['|',('company_id','=',False),('company_id','in',company_ids)]"
rule = env.ref(
"account_asset_management.account_asset_profile_multi_company_rule",
raise_if_not_found=False,
)
if rule:
rule.write({"domain_force": domain})
rule = env.ref(
"account_asset_management.account_asset_multi_company_rule",
raise_if_not_found=False,
)
if rule:
rule.write({"domain_force": domain})
rule = env.ref(
"account_asset_management.account_asset_group_multi_company_rule",
raise_if_not_found=False,
)
if rule:
rule.write({"domain_force": domain})

View File

@ -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

View File

@ -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(),

View File

@ -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)

View File

@ -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)

View File

@ -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,

View File

@ -13,3 +13,4 @@
* Ernesto Tejeda
* Pedro M. Baeza
* João Marques

View File

@ -1,3 +1,8 @@
14.0.1.0.0 (2021-01-08)
~~~~~~~~~~~~~~~~~~~~~~~
* [BREAKING] Removed all functionality associated with `account.fiscal.year`
13.0.1.0.0 (2019-10-21)
~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -13,3 +13,5 @@ access_account_asset_recompute_trigger_manager,account.asset.recompute.trigger,m
access_account_asset_group_invoice,account.asset.group,model_account_asset_group,account.group_account_invoice,1,0,0,0
access_account_asset_group_user,account.asset.group,model_account_asset_group,account.group_account_user,1,0,0,0
access_account_asset_group_manager,account.asset.group,model_account_asset_group,account.group_account_manager,1,1,1,1
access_account_asset_remove_user,account.asset.remove,model_account_asset_remove,account.group_account_user,1,1,1,1
access_account_asset_compute_user,account.asset.compute,model_account_asset_compute,account.group_account_user,1,1,1,1

1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
13 access_account_asset_group_invoice account.asset.group model_account_asset_group account.group_account_invoice 1 0 0 0
14 access_account_asset_group_user account.asset.group model_account_asset_group account.group_account_user 1 0 0 0
15 access_account_asset_group_manager account.asset.group model_account_asset_group account.group_account_manager 1 1 1 1
16 access_account_asset_remove_user account.asset.remove model_account_asset_remove account.group_account_user 1 1 1 1
17 access_account_asset_compute_user account.asset.compute model_account_asset_compute account.group_account_user 1 1 1 1

View File

@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
<title>Assets Management</title>
<style type="text/css">
@ -367,7 +367,7 @@ ul.auto-toc {
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/account-financial-tools/tree/13.0/account_asset_management"><img alt="OCA/account-financial-tools" src="https://img.shields.io/badge/github-OCA%2Faccount--financial--tools-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/account-financial-tools-13-0/account-financial-tools-13-0-account_asset_management"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/92/13.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/account-financial-tools/tree/14.0/account_asset_management"><img alt="OCA/account-financial-tools" src="https://img.shields.io/badge/github-OCA%2Faccount--financial--tools-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/account-financial-tools-14-0/account-financial-tools-14-0-account_asset_management"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/92/14.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This Module manages the assets owned by a company. It will keep
track of depreciations occurred on those assets. And it allows to create
accounting entries from the depreciation lines.</p>
@ -387,30 +387,39 @@ the standard account_asset module from Odoo.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#usage" id="id4">Usage</a></li>
<li><a class="reference internal" href="#changelog" id="id5">Changelog</a><ul>
<li><a class="reference internal" href="#id1" id="id6">13.0.1.0.0 (2019-10-21)</a></li>
<li><a class="reference internal" href="#id2" id="id7">12.0.2.1.0 (2019-10-21)</a></li>
<li><a class="reference internal" href="#id3" id="id8">12.0.1.0.0 (2019-01-13)</a></li>
<li><a class="reference internal" href="#usage" id="id5">Usage</a></li>
<li><a class="reference internal" href="#changelog" id="id6">Changelog</a><ul>
<li><a class="reference internal" href="#id1" id="id7">14.0.1.0.0 (2021-01-08)</a></li>
<li><a class="reference internal" href="#id2" id="id8">13.0.1.0.0 (2019-10-21)</a></li>
<li><a class="reference internal" href="#id3" id="id9">12.0.2.1.0 (2019-10-21)</a></li>
<li><a class="reference internal" href="#id4" id="id10">12.0.1.0.0 (2019-01-13)</a></li>
</ul>
</li>
<li><a class="reference internal" href="#bug-tracker" id="id9">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="id10">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="id11">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="id12">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="id13">Maintainers</a></li>
<li><a class="reference internal" href="#bug-tracker" id="id11">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="id12">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="id13">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="id14">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="id15">Maintainers</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#id4">Usage</a></h1>
<h1><a class="toc-backref" href="#id5">Usage</a></h1>
<p>The module in NOT compatible with the standard account_asset module.</p>
</div>
<div class="section" id="changelog">
<h1><a class="toc-backref" href="#id5">Changelog</a></h1>
<h1><a class="toc-backref" href="#id6">Changelog</a></h1>
<div class="section" id="id1">
<h2><a class="toc-backref" href="#id6">13.0.1.0.0 (2019-10-21)</a></h2>
<h2><a class="toc-backref" href="#id7">14.0.1.0.0 (2021-01-08)</a></h2>
<blockquote>
<ul class="simple">
<li>[BREAKING] Removed all functionality associated with <cite>account.fiscal.year</cite></li>
</ul>
</blockquote>
</div>
<div class="section" id="id2">
<h2><a class="toc-backref" href="#id8">13.0.1.0.0 (2019-10-21)</a></h2>
<ul class="simple">
<li>Python code and views were adapted to be compatible with v13.</li>
<li>When assets are created through accounting journal items,
@ -427,14 +436,14 @@ allow the module to be uninstalled by unchecking that configuration option.</li>
<li>Tests were adapted.</li>
</ul>
</div>
<div class="section" id="id2">
<h2><a class="toc-backref" href="#id7">12.0.2.1.0 (2019-10-21)</a></h2>
<div class="section" id="id3">
<h2><a class="toc-backref" href="#id9">12.0.2.1.0 (2019-10-21)</a></h2>
<ul class="simple">
<li>[IMP] Add option to calculate depreciation table by days</li>
</ul>
</div>
<div class="section" id="id3">
<h2><a class="toc-backref" href="#id8">12.0.1.0.0 (2019-01-13)</a></h2>
<div class="section" id="id4">
<h2><a class="toc-backref" href="#id10">12.0.1.0.0 (2019-01-13)</a></h2>
<ul class="simple">
<li>[BREAKING] account.asset: parent_path has replaced parent_left &amp; parent_right (TODO: migration script)</li>
<li>[BREAKING] account.asset.recompute.trigger: depends on date_range.py (TODO: re-implement in account_fiscal_year.py)</li>
@ -442,23 +451,23 @@ allow the module to be uninstalled by unchecking that configuration option.</li>
</div>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#id9">Bug Tracker</a></h1>
<h1><a class="toc-backref" href="#id11">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/account-financial-tools/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/account-financial-tools/issues/new?body=module:%20account_asset_management%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/account-financial-tools/issues/new?body=module:%20account_asset_management%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h1><a class="toc-backref" href="#id10">Credits</a></h1>
<h1><a class="toc-backref" href="#id12">Credits</a></h1>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#id11">Authors</a></h2>
<h2><a class="toc-backref" href="#id13">Authors</a></h2>
<ul class="simple">
<li>Noviat</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#id12">Contributors</a></h2>
<h2><a class="toc-backref" href="#id14">Contributors</a></h2>
<ul class="simple">
<li>OpenERP SA</li>
<li>Luc De Meyer (Noviat)</li>
@ -474,18 +483,19 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<li><a class="reference external" href="https://www.tecnativa.com">Tecnativa</a>:<ul>
<li>Ernesto Tejeda</li>
<li>Pedro M. Baeza</li>
<li>João Marques</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#id13">Maintainers</a></h2>
<h2><a class="toc-backref" href="#id15">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/account-financial-tools/tree/13.0/account_asset_management">OCA/account-financial-tools</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/account-financial-tools/tree/14.0/account_asset_management">OCA/account-financial-tools</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>

View File

@ -1,67 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<data noupdate="1">
<record id="account_fiscal_year_current" model="account.fiscal.year">
<field name="name">FY_assets</field>
<field name="date_from" eval="time.strftime('%Y-01-01')" />
<field name="date_to" eval="time.strftime('%Y-12-31')" />
<field name="company_id" ref="base.main_company" />
</record>
<record id="account_fiscal_year_previous" model="account.fiscal.year">
<field name="name">FY_assets previous</field>
<field
name="date_from"
eval="(datetime.now() - relativedelta(years=1, month=1, day=1)).strftime('%Y-%m-%d')"
/>
<field
name="date_to"
eval="(datetime.now() - relativedelta(years=1, month=12, day=31)).strftime('%Y-%m-%d')"
/>
<field name="company_id" ref="base.main_company" />
</record>
<!-- Asset profiles -->
<record id="account_asset_profile_ict_3Y" model="account.asset.profile">
<field name="account_expense_depreciation_id" ref="account.a_expense" />
<field name="account_asset_id" ref="account.xfa" />
<field name="account_depreciation_id" ref="account.xfa" />
<field name="journal_id" ref="account.expenses_journal" />
<field name="name">Hardware - 3 Years</field>
<field name="method_time">year</field>
<field name="method_number" eval="3" />
<field name="method_period">year</field>
</record>
<record id="account_asset_profile_car_5Y" model="account.asset.profile">
<field name="account_expense_depreciation_id" ref="account.a_expense" />
<field name="account_asset_id" ref="account.xfa" />
<field name="account_depreciation_id" ref="account.xfa" />
<field name="journal_id" ref="account.expenses_journal" />
<field name="name">Cars - 5 Years</field>
<field name="method_time">year</field>
<field name="method_number" eval="5" />
<field name="method_period">year</field>
</record>
<!-- Assets -->
<record id="account_asset_asset_ict0" model="account.asset">
<field name="state">draft</field>
<field name="method_time">year</field>
<field name="method_number" eval="3" />
<field name="method_period">year</field>
<field name="date_start" eval="time.strftime('%Y-01-01')" />
<field name="name">Laptop</field>
<field name="code">PI00101</field>
<field name="purchase_value" eval="1500.0" />
<field name="profile_id" ref="account_asset_profile_ict_3Y" />
</record>
<record id="account_asset_asset_vehicle0" model="account.asset">
<field name="state">draft</field>
<field name="method_time">year</field>
<field name="method_number" eval="5" />
<field name="method_period">year</field>
<field name="date_start" eval="time.strftime('%Y-01-01')" />
<field name="name">CEO's Car</field>
<field name="purchase_value" eval="12000.0" />
<field name="salvage_value" eval="2000.0" />
<field name="profile_id" ref="account_asset_profile_car_5Y" />
</record>
</data>
</odoo>

View File

@ -1,82 +1,49 @@
# Copyright (c) 2014 ACSONE SA/NV (acsone.eu).
# Copyright 2009-2018 Noviat
# Copyright 2021 Tecnativa - João Marques
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import calendar
import time
from datetime import date, datetime
from odoo import tools
from odoo.modules.module import get_resource_path
from odoo.tests.common import Form, SavepointCase
from odoo.tests.common import Form
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
class TestAssetManagement(SavepointCase):
@classmethod
def _load(cls, module, *args):
tools.convert_file(
cls.cr,
module,
get_resource_path(module, *args),
{},
"init",
False,
"test",
cls.registry._assertion_report,
)
class TestAssetManagement(AccountTestInvoicingCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls._load("account", "test", "account_minimal_test.xml")
cls._load("account_asset_management", "tests", "account_asset_test_data.xml")
# ENVIRONEMENTS
cls.asset_model = cls.env["account.asset"]
cls.asset_profile_model = cls.env["account.asset.profile"]
cls.dl_model = cls.env["account.asset.line"]
cls.remove_model = cls.env["account.asset.remove"]
cls.account_invoice = cls.env["account.move"]
cls.account_move_line = cls.env["account.move.line"]
cls.account_account = cls.env["account.account"]
cls.account_journal = cls.env["account.journal"]
cls.account_invoice_line = cls.env["account.move.line"]
# INSTANCES
# Instance: company
cls.company = cls.env.ref("base.main_company")
# Instance: partner
cls.partner = cls.env.ref("base.res_partner_2")
# Instance: journal
cls.journal = cls.account_journal.search([("type", "=", "purchase")])[0]
# Instance: product
cls.product = cls.env.ref("product.product_product_4")
cls.partner = cls.env["res.partner"].create({"name": "Test Partner"})
cls.product = cls.env["product.product"].create(
{"name": "Test", "standard_price": 500.0}
)
move_form = Form(
cls.env["account.move"].with_context(
default_type="in_invoice", check_move_validity=False
default_move_type="in_invoice", check_move_validity=False
)
)
move_form.partner_id = cls.partner
move_form.journal_id = cls.journal
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_type="in_invoice", check_move_validity=False
default_move_type="in_invoice", check_move_validity=False
)
)
move_form.partner_id = cls.partner
move_form.journal_id = cls.journal
with move_form.invoice_line_ids.new() as line_form:
line_form.name = "test 2"
line_form.product_id = cls.product
@ -88,30 +55,85 @@ class TestAssetManagement(SavepointCase):
line_form.price_unit = 20000.00
line_form.quantity = 1
cls.invoice_2 = move_form.save()
# Asset Profile 1
cls.ict3Y = cls.asset_profile_model.create(
{
"account_expense_depreciation_id": cls.company_data[
"default_account_expense"
].id,
"account_asset_id": cls.company_data["default_account_assets"].id,
"account_depreciation_id": cls.company_data[
"default_account_assets"
].id,
"journal_id": cls.company_data["default_journal_purchase"].id,
"name": "Hardware - 3 Years",
"method_time": "year",
"method_number": 3,
"method_period": "year",
}
)
# Asset Profile 2
cls.car5y = cls.asset_profile_model.create(
{
"account_expense_depreciation_id": cls.company_data[
"default_account_expense"
].id,
"account_asset_id": cls.company_data["default_account_assets"].id,
"account_depreciation_id": cls.company_data[
"default_account_assets"
].id,
"journal_id": cls.company_data["default_journal_purchase"].id,
"name": "Cars - 5 Years",
"method_time": "year",
"method_number": 5,
"method_period": "year",
}
)
def test_01_nonprorata_basic(self):
"""Basic tests of depreciation board computations and postings."""
#
# first load demo assets and do some sanity checks
#
ict0 = self.browse_ref("account_asset_management." "account_asset_asset_ict0")
# First create demo assets and do some sanity checks
# Asset Model 1
ict0 = self.asset_model.create(
{
"state": "draft",
"method_time": "year",
"method_number": 3,
"method_period": "year",
"name": "Laptop",
"code": "PI00101",
"purchase_value": 1500.0,
"profile_id": self.ict3Y.id,
"date_start": time.strftime("%Y-01-01"),
}
)
# Sanity checks
self.assertEqual(ict0.state, "draft")
self.assertEqual(ict0.purchase_value, 1500)
self.assertEqual(ict0.salvage_value, 0)
self.assertEqual(ict0.depreciation_base, 1500)
self.assertEqual(len(ict0.depreciation_line_ids), 1)
vehicle0 = self.browse_ref(
"account_asset_management." "account_asset_asset_vehicle0"
# Asset Model 2
vehicle0 = self.asset_model.create(
{
"state": "draft",
"method_time": "year",
"method_number": 5,
"method_period": "year",
"name": "CEO's Car",
"purchase_value": 12000.0,
"salvage_value": 2000.0,
"profile_id": self.car5y.id,
"date_start": time.strftime("%Y-01-01"),
}
)
# Sanity checks
self.assertEqual(vehicle0.state, "draft")
self.assertEqual(vehicle0.purchase_value, 12000)
self.assertEqual(vehicle0.salvage_value, 2000)
self.assertEqual(vehicle0.depreciation_base, 10000)
self.assertEqual(len(vehicle0.depreciation_line_ids), 1)
#
# I compute the depreciation boards
#
# Compute the depreciation boards
ict0.compute_depreciation_board()
ict0.refresh()
self.assertEqual(len(ict0.depreciation_line_ids), 4)
@ -120,10 +142,7 @@ class TestAssetManagement(SavepointCase):
vehicle0.refresh()
self.assertEqual(len(vehicle0.depreciation_line_ids), 6)
self.assertEqual(vehicle0.depreciation_line_ids[1].amount, 2000)
#
# I post the first depreciation line
#
# Post the first depreciation line
ict0.validate()
ict0.depreciation_line_ids[1].create_move()
ict0.refresh()
@ -142,9 +161,7 @@ class TestAssetManagement(SavepointCase):
asset = self.asset_model.create(
{
"name": "test asset",
"profile_id": self.ref(
"account_asset_management." "account_asset_profile_car_5Y"
),
"profile_id": self.car5y.id,
"purchase_value": 3333,
"salvage_value": 0,
"date_start": time.strftime("%Y-07-07"),
@ -180,13 +197,11 @@ class TestAssetManagement(SavepointCase):
def test_03_proprata_init_prev_year(self):
"""Prorata temporis depreciation with init value in prev year."""
# I create an asset in current year
# Create an asset in current year
asset = self.asset_model.create(
{
"name": "test asset",
"profile_id": self.ref(
"account_asset_management." "account_asset_profile_car_5Y"
),
"profile_id": self.car5y.id,
"purchase_value": 3333,
"salvage_value": 0,
"date_start": "%d-07-07" % (datetime.now().year - 1,),
@ -196,7 +211,7 @@ class TestAssetManagement(SavepointCase):
"prorata": True,
}
)
# I create a initial depreciation line in previous year
# Create a initial depreciation line in previous year
self.dl_model.create(
{
"asset_id": asset.id,
@ -209,9 +224,9 @@ class TestAssetManagement(SavepointCase):
self.assertEqual(len(asset.depreciation_line_ids), 2)
asset.compute_depreciation_board()
asset.refresh()
# I check the depreciated value is the initial value
# check the depreciated value is the initial value
self.assertAlmostEqual(asset.value_depreciated, 325.08, places=2)
# I check computed values in the depreciation board
# check computed values in the depreciation board
self.assertAlmostEqual(asset.depreciation_line_ids[3].amount, 55.55, places=2)
if calendar.isleap(date.today().year - 1):
# for leap years the first year depreciation amount of 325.08
@ -239,9 +254,7 @@ class TestAssetManagement(SavepointCase):
asset = self.asset_model.create(
{
"name": "test asset",
"profile_id": self.ref(
"account_asset_management." "account_asset_profile_car_5Y"
),
"profile_id": self.car5y.id,
"purchase_value": 3333,
"salvage_value": 0,
"date_start": time.strftime("%Y-07-07"),
@ -263,9 +276,9 @@ class TestAssetManagement(SavepointCase):
self.assertEqual(len(asset.depreciation_line_ids), 2)
asset.compute_depreciation_board()
asset.refresh()
# I check the depreciated value is the initial value
# check the depreciated value is the initial value
self.assertAlmostEqual(asset.value_depreciated, 279.44, places=2)
# I check computed values in the depreciation board
# check computed values in the depreciation board
if calendar.isleap(date.today().year):
self.assertAlmostEqual(
asset.depreciation_line_ids[2].amount, 44.75, places=2
@ -286,14 +299,11 @@ class TestAssetManagement(SavepointCase):
def test_05_degressive_linear(self):
"""Degressive-Linear with annual and quarterly depreciation."""
# annual depreciation
asset = self.asset_model.create(
{
"name": "test asset",
"profile_id": self.ref(
"account_asset_management." "account_asset_profile_car_5Y"
),
"profile_id": self.car5y.id,
"purchase_value": 1000,
"salvage_value": 0,
"date_start": time.strftime("%Y-07-07"),
@ -307,21 +317,17 @@ class TestAssetManagement(SavepointCase):
)
asset.compute_depreciation_board()
asset.refresh()
# check values in the depreciation board
self.assertEqual(len(asset.depreciation_line_ids), 5)
self.assertAlmostEqual(asset.depreciation_line_ids[1].amount, 400.00, places=2)
self.assertAlmostEqual(asset.depreciation_line_ids[2].amount, 240.00, places=2)
self.assertAlmostEqual(asset.depreciation_line_ids[3].amount, 200.00, places=2)
self.assertAlmostEqual(asset.depreciation_line_ids[4].amount, 160.00, places=2)
# quarterly depreciation
asset = self.asset_model.create(
{
"name": "test asset",
"profile_id": self.ref(
"account_asset_management." "account_asset_profile_car_5Y"
),
"profile_id": self.car5y.id,
"purchase_value": 1000,
"salvage_value": 0,
"date_start": time.strftime("%Y-07-07"),
@ -335,7 +341,6 @@ class TestAssetManagement(SavepointCase):
)
asset.compute_depreciation_board()
asset.refresh()
# check values in the depreciation board
self.assertEqual(len(asset.depreciation_line_ids), 15)
# lines prior to asset start period are grouped in the first entry
@ -349,9 +354,7 @@ class TestAssetManagement(SavepointCase):
asset = self.asset_model.create(
{
"name": "test asset",
"profile_id": self.ref(
"account_asset_management." "account_asset_profile_car_5Y"
),
"profile_id": self.car5y.id,
"purchase_value": 1000,
"salvage_value": 100,
"date_start": time.strftime("%Y-07-07"),
@ -365,7 +368,6 @@ class TestAssetManagement(SavepointCase):
)
asset.compute_depreciation_board()
asset.refresh()
# check values in the depreciation board
self.assertEqual(len(asset.depreciation_line_ids), 6)
self.assertAlmostEqual(asset.depreciation_line_ids[1].amount, 400.00, places=2)
@ -379,9 +381,7 @@ class TestAssetManagement(SavepointCase):
asset = self.asset_model.create(
{
"name": "test asset",
"profile_id": self.ref(
"account_asset_management." "account_asset_profile_car_5Y"
),
"profile_id": self.car5y.id,
"purchase_value": 1000,
"salvage_value": 100,
"date_start": time.strftime("%Y-07-07"),
@ -394,7 +394,6 @@ class TestAssetManagement(SavepointCase):
)
asset.compute_depreciation_board()
asset.refresh()
# check values in the depreciation board
self.assertEqual(len(asset.depreciation_line_ids), 6)
self.assertAlmostEqual(asset.depreciation_line_ids[1].amount, 200.00, places=2)
@ -405,9 +404,7 @@ class TestAssetManagement(SavepointCase):
asset = self.asset_model.create(
{
"name": "test asset removal",
"profile_id": self.ref(
"account_asset_management." "account_asset_profile_car_5Y"
),
"profile_id": self.car5y.id,
"purchase_value": 5000,
"salvage_value": 0,
"date_start": "2019-01-01",
@ -425,8 +422,10 @@ class TestAssetManagement(SavepointCase):
"date_remove": "2019-01-31",
"sale_value": 0.0,
"posting_regime": "gain_loss_on_sale",
"account_plus_value_id": self.ref("account.a_sale"),
"account_min_value_id": self.ref("account.a_expense"),
"account_plus_value_id": self.company_data[
"default_account_revenue"
].id,
"account_min_value_id": self.company_data["default_account_expense"].id,
}
)
wiz.remove()
@ -438,9 +437,7 @@ class TestAssetManagement(SavepointCase):
def test_09_asset_from_invoice(self):
all_asset = self.env["account.asset"].search([])
invoice = self.invoice
asset_profile = self.env.ref(
"account_asset_management.account_asset_profile_car_5Y"
)
asset_profile = self.car5y
asset_profile.asset_product_item = False
self.assertTrue(len(invoice.invoice_line_ids) > 0)
line = invoice.invoice_line_ids[0]
@ -450,14 +447,14 @@ class TestAssetManagement(SavepointCase):
line_form.quantity = 2
line_form.asset_profile_id = asset_profile
invoice = move_form.save()
invoice.post()
# I get all asset after invoice validation
invoice.action_post()
# get all asset after invoice validation
current_asset = self.env["account.asset"].search([])
# I get the new asset
# get the new asset
new_asset = current_asset - all_asset
# I check that a new asset is created
# check that a new asset is created
self.assertEqual(len(new_asset), 1)
# I check that the new asset has the correct purchase value
# check that the new asset has the correct purchase value
self.assertAlmostEqual(
new_asset.purchase_value, line.price_unit * line.quantity, places=2
)
@ -465,9 +462,7 @@ class TestAssetManagement(SavepointCase):
def test_10_asset_from_invoice_product_item(self):
all_asset = self.env["account.asset"].search([])
invoice = self.invoice
asset_profile = self.env.ref(
"account_asset_management.account_asset_profile_car_5Y"
)
asset_profile = self.car5y
asset_profile.asset_product_item = True
self.assertTrue(len(invoice.invoice_line_ids) > 0)
line = invoice.invoice_line_ids[0]
@ -475,40 +470,36 @@ class TestAssetManagement(SavepointCase):
line.quantity = 2
line.asset_profile_id = asset_profile
self.assertEqual(len(invoice.invoice_line_ids), 2)
invoice.post()
# I get all asset after invoice validation
invoice.action_post()
# get all asset after invoice validation
current_asset = self.env["account.asset"].search([])
# I get the new asset
# get the new asset
new_asset = current_asset - all_asset
# I check that a new asset is created
# check that a new asset is created
self.assertEqual(len(new_asset), 2)
for asset in new_asset:
# I check that the new asset has the correct purchase value
# check that the new asset has the correct purchase value
self.assertAlmostEqual(asset.purchase_value, line.price_unit, places=2)
def test_11_assets_from_invoice(self):
all_assets = self.env["account.asset"].search([])
ctx = dict(self.invoice_2._context)
del ctx["default_type"]
del ctx["default_move_type"]
invoice = self.invoice_2.with_context(ctx)
asset_profile = self.env.ref(
"account_asset_management.account_asset_profile_car_5Y"
)
asset_profile = self.car5y
asset_profile.asset_product_item = True
# Compute depreciation lines on invoice validation
asset_profile.open_asset = True
self.assertTrue(len(invoice.invoice_line_ids) == 2)
invoice.invoice_line_ids.write(
{"quantity": 1, "asset_profile_id": asset_profile.id}
)
invoice.post()
invoice.action_post()
# Retrieve all assets after invoice validation
current_assets = self.env["account.asset"].search([])
# What are the new assets?
new_assets = current_assets - all_assets
self.assertEqual(len(new_assets), 2)
for asset in new_assets:
dlines = asset.depreciation_line_ids.filtered(
lambda l: l.type == "depreciate"
@ -522,9 +513,7 @@ class TestAssetManagement(SavepointCase):
asset = self.asset_model.create(
{
"name": "test asset",
"profile_id": self.ref(
"account_asset_management." "account_asset_profile_car_5Y"
),
"profile_id": self.car5y.id,
"purchase_value": 3333,
"salvage_value": 0,
"date_start": "2019-07-07",
@ -556,9 +545,7 @@ class TestAssetManagement(SavepointCase):
asset = self.asset_model.create(
{
"name": "test asset",
"profile_id": self.ref(
"account_asset_management." "account_asset_profile_car_5Y"
),
"profile_id": self.car5y.id,
"purchase_value": 10000,
"salvage_value": 0,
"date_start": time.strftime("2019-01-01"),
@ -587,9 +574,7 @@ class TestAssetManagement(SavepointCase):
asset = self.asset_model.create(
{
"name": "test asset",
"profile_id": self.ref(
"account_asset_management." "account_asset_profile_car_5Y"
),
"profile_id": self.car5y.id,
"purchase_value": 10000,
"salvage_value": 0,
"date_start": time.strftime("2019-01-01"),

View File

@ -374,12 +374,13 @@
<field name="view_id" ref="account_asset_view_tree" />
<field name="search_view_id" ref="account_asset_view_search" />
</record>
<act_window
id="act_entries_open"
name="Journal Items"
binding_model="account.asset"
binding_views="form"
res_model="account.move.line"
domain="['|',('asset_id','in',context.get('active_ids')),('asset_id','=','active_id')]"
/>
<record id="act_entries_open" model="ir.actions.act_window">
<field name="name">Journal Items</field>
<field name="binding_model_id" ref="model_account_asset" />
<field name="binding_view_types">form</field>
<field name="res_model">account.move.line</field>
<field
name="domain"
>['|',('asset_id','in',context.get('active_ids')),('asset_id','=','active_id')]</field>
</record>
</odoo>

View File

@ -11,11 +11,11 @@
>
<field
name="asset_profile_id"
attrs="{'invisible': [('parent.type', 'not in', ('in_invoice', 'in_refund'))]}"
attrs="{'invisible': [('parent.move_type', 'not in', ('in_invoice', 'in_refund'))]}"
/>
<field
name="asset_id"
attrs="{'invisible': [('parent.type', 'not in', ('out_invoice', 'out_refund'))]}"
attrs="{'invisible': [('parent.move_type', 'not in', ('out_invoice', 'out_refund'))]}"
groups="account.group_account_manager"
/>
</xpath>

View File

@ -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
@ -83,7 +84,7 @@ class AccountAssetRemove(models.TransientModel):
inv_lines = self.env["account.move.line"].search(
[
("asset_id", "=", asset_id),
("move_id.type", "in", ("out_invoice", "out_refund")),
("move_id.move_type", "in", ("out_invoice", "out_refund")),
]
)
for line in inv_lines: