2
0

[MIG] account_asset_batch_compute: Migration to 13.0

This commit is contained in:
Alba Riera 2021-02-22 18:39:52 +01:00 committed by Javier Iniesta
parent ec7d5b5906
commit cf12172e4b
9 changed files with 68 additions and 53 deletions

View File

@ -14,13 +14,13 @@ Account Asset Batch Compute
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3 :alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--financial--tools-lightgray.png?logo=github .. |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/12.0/account_asset_batch_compute :target: https://github.com/OCA/account-financial-tools/tree/13.0/account_asset_batch_compute
:alt: OCA/account-financial-tools :alt: OCA/account-financial-tools
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/account-financial-tools-12-0/account-financial-tools-12-0-account_asset_batch_compute :target: https://translation.odoo-community.org/projects/account-financial-tools-13-0/account-financial-tools-13-0-account_asset_batch_compute
:alt: Translate me on Weblate :alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png .. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/92/12.0 :target: https://runbot.odoo-community.org/runbot/92/13.0
:alt: Try me on Runbot :alt: Try me on Runbot
|badge1| |badge2| |badge3| |badge4| |badge5| |badge1| |badge2| |badge3| |badge4| |badge5|
@ -29,7 +29,6 @@ Add the possibility to compute assets in batch.
This module adds a flag on compute assets wizard in order to execute This module adds a flag on compute assets wizard in order to execute
this process in batch. this process in batch.
**Table of contents** **Table of contents**
.. contents:: .. contents::
@ -41,7 +40,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-financial-tools/issues>`_. 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. 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 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_batch_compute%0Aversion:%2012.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_batch_compute%0Aversion:%2013.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. Do not contact contributors directly about support or help with technical issues.
@ -52,13 +51,14 @@ Authors
~~~~~~~ ~~~~~~~
* ACSONE SA/NV * ACSONE SA/NV
* Eficent * ForgeFlow
Contributors Contributors
~~~~~~~~~~~~ ~~~~~~~~~~~~
* Adrien Peiffer * Adrien Peiffer
* Jordi Ballester Alomar <jordi.ballester@eficent.com> * Jordi Ballester Alomar <jordi.ballester@forgeflow.com>
* Alba Riera <alba.riera@creublanca.es>
Maintainers Maintainers
~~~~~~~~~~~ ~~~~~~~~~~~
@ -73,6 +73,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and mission is to support the collaborative development of Odoo features and
promote its widespread use. promote its widespread use.
This module is part of the `OCA/account-financial-tools <https://github.com/OCA/account-financial-tools/tree/12.0/account_asset_batch_compute>`_ project on GitHub. This module is part of the `OCA/account-financial-tools <https://github.com/OCA/account-financial-tools/tree/13.0/account_asset_batch_compute>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@ -5,10 +5,10 @@
"name": "Account Asset Batch Compute", "name": "Account Asset Batch Compute",
"summary": """ "summary": """
Add the possibility to compute assets in batch""", Add the possibility to compute assets in batch""",
"version": "12.0.1.0.0", "version": "13.0.1.0.0",
"license": "AGPL-3", "license": "AGPL-3",
"author": "ACSONE SA/NV," "Eficent," "Odoo Community Association (OCA)", "author": "ACSONE SA/NV,ForgeFlow,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-financial-tools", "website": "https://github.com/OCA/account-financial-tools",
"depends": ["account_asset_management", "queue_job",], "depends": ["account_asset_management", "queue_job"],
"data": ["wizards/account_asset_compute_views.xml",], "data": ["wizards/account_asset_compute_views.xml", "data/queue_data.xml"],
} }

View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<record model="queue.job.channel" id="channel_account_asset_batch_compute">
<field name="name">account_asset_batch_compute</field>
<field name="parent_id" ref="queue_job.channel_root" />
</record>
<record id="job_function_account_asset_compute_entries" model="queue.job.function">
<field name="model_id" ref="account_asset_management.model_account_asset" />
<field name="method">_compute_entries</field>
<field name="channel_id" ref="channel_account_asset_batch_compute" />
</record>
<record
id="job_function_account_asset_compute_asset_compute"
model="queue.job.function"
>
<field
name="model_id"
ref="account_asset_management.model_account_asset_compute"
/>
<field name="method">asset_compute</field>
<field name="channel_id" ref="channel_account_asset_batch_compute" />
</record>
</odoo>

View File

@ -1,12 +1,12 @@
# Translation of Odoo Server. # Translation of Odoo Server.
# This file contains the translation of the following modules: # This file contains the translation of the following modules:
# * account_asset_batch_compute # * account_asset_batch_compute
# #
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Odoo Server 12.0\n" "Project-Id-Version: Odoo Server 13.0\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"Last-Translator: <>\n" "Last-Translator: \n"
"Language-Team: \n" "Language-Team: \n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
@ -29,14 +29,13 @@ msgid "Compute Assets"
msgstr "" msgstr ""
#. module: account_asset_batch_compute #. module: account_asset_batch_compute
#: code:addons/account_asset_batch_compute/wizards/account_asset_compute.py:31 #: code:addons/account_asset_batch_compute/wizards/account_asset_compute.py:0
#, python-format #, python-format
msgid "Creating jobs to create moves for assets to %s" msgid "Creating jobs to create moves for assets to %s"
msgstr "" msgstr ""
#. module: account_asset_batch_compute #. module: account_asset_batch_compute
#: code:addons/account_asset_batch_compute/models/account_asset.py:29 #: code:addons/account_asset_batch_compute/models/account_asset.py:0
#, python-format #, python-format
msgid "Creating move for asset with id %s to %s" msgid "Creating move for asset with id %s to %s"
msgstr "" msgstr ""

View File

@ -1,24 +1,13 @@
# Copyright 2016 ACSONE SA/NV # Copyright 2016 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import logging from odoo import _, models
from odoo import _, api, models
_logger = logging.getLogger(__name__)
try:
from odoo.addons.queue_job.job import job
except ImportError:
_logger.debug("Can not `import queue_job`.")
class AccountAsset(models.Model): class AccountAsset(models.Model):
_inherit = "account.asset" _inherit = "account.asset"
@api.multi
@job(default_channel="root.account_asset_batch_compute")
def _compute_entries(self, date_end, check_triggers=False): def _compute_entries(self, date_end, check_triggers=False):
if self.env.context.get( if self.env.context.get(
"asset_batch_processing", False "asset_batch_processing", False

View File

@ -1,2 +1,3 @@
* Adrien Peiffer * Adrien Peiffer
* Jordi Ballester Alomar <jordi.ballester@eficent.com> * Jordi Ballester Alomar <jordi.ballester@forgeflow.com>
* Alba Riera <alba.riera@creublanca.es>

View File

@ -367,7 +367,7 @@ ul.auto-toc {
!! This file is generated by oca-gen-addon-readme !! !! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !! !! 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/12.0/account_asset_batch_compute"><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-12-0/account-financial-tools-12-0-account_asset_batch_compute"><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/12.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/13.0/account_asset_batch_compute"><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_batch_compute"><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>Add the possibility to compute assets in batch. <p>Add the possibility to compute assets in batch.
This module adds a flag on compute assets wizard in order to execute This module adds a flag on compute assets wizard in order to execute
this process in batch.</p> this process in batch.</p>
@ -388,7 +388,7 @@ this process in batch.</p>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/account-financial-tools/issues">GitHub Issues</a>. <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. 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 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_batch_compute%0Aversion:%2012.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_batch_compute%0Aversion:%2013.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> <p>Do not contact contributors directly about support or help with technical issues.</p>
</div> </div>
<div class="section" id="credits"> <div class="section" id="credits">
@ -397,14 +397,15 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<h2><a class="toc-backref" href="#id3">Authors</a></h2> <h2><a class="toc-backref" href="#id3">Authors</a></h2>
<ul class="simple"> <ul class="simple">
<li>ACSONE SA/NV</li> <li>ACSONE SA/NV</li>
<li>Eficent</li> <li>ForgeFlow</li>
</ul> </ul>
</div> </div>
<div class="section" id="contributors"> <div class="section" id="contributors">
<h2><a class="toc-backref" href="#id4">Contributors</a></h2> <h2><a class="toc-backref" href="#id4">Contributors</a></h2>
<ul class="simple"> <ul class="simple">
<li>Adrien Peiffer</li> <li>Adrien Peiffer</li>
<li>Jordi Ballester Alomar &lt;<a class="reference external" href="mailto:jordi.ballester&#64;eficent.com">jordi.ballester&#64;eficent.com</a>&gt;</li> <li>Jordi Ballester Alomar &lt;<a class="reference external" href="mailto:jordi.ballester&#64;forgeflow.com">jordi.ballester&#64;forgeflow.com</a>&gt;</li>
<li>Alba Riera &lt;<a class="reference external" href="mailto:alba.riera&#64;creublanca.es">alba.riera&#64;creublanca.es</a>&gt;</li>
</ul> </ul>
</div> </div>
<div class="section" id="maintainers"> <div class="section" id="maintainers">
@ -414,7 +415,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose <p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and mission is to support the collaborative development of Odoo features and
promote its widespread use.</p> 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/12.0/account_asset_batch_compute">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/13.0/account_asset_batch_compute">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> <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>
</div> </div>

View File

@ -1,5 +1,5 @@
# Copyright 2016-19 ACSONE SA/NV # Copyright 2016-19 ACSONE SA/NV
# Copyright 2019 Eficent Business and IT Consulting Services, S.L. # Copyright 2019 ForgeFlow S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import time import time
from datetime import date from datetime import date
@ -19,7 +19,7 @@ class TestAccountAssetBatchCompute(TransactionCase):
self.asset_profile_model = self.env["account.asset.profile"] self.asset_profile_model = self.env["account.asset.profile"]
self.account_account_type_model = self.env["account.account.type"] self.account_account_type_model = self.env["account.account.type"]
self.account_type_regular = self.account_account_type_model.create( self.account_type_regular = self.account_account_type_model.create(
{"name": "Test Regular", "type": "other",} {"name": "Test Regular", "type": "other", "internal_group": "liability"}
) )
self.account = self.env["account.account"].create( self.account = self.env["account.account"].create(
{ {
@ -29,7 +29,7 @@ class TestAccountAssetBatchCompute(TransactionCase):
} }
) )
self.journal = self.env["account.journal"].create( self.journal = self.env["account.journal"].create(
{"name": "Test Journal", "code": "TJ", "type": "general",} {"name": "Test Journal", "code": "TJ", "type": "general"}
) )
self.profile = self.asset_profile_model.create( self.profile = self.asset_profile_model.create(
{ {
@ -65,7 +65,7 @@ class TestAccountAssetBatchCompute(TransactionCase):
self.nextmonth = first_day_of_month + relativedelta.relativedelta(months=1) self.nextmonth = first_day_of_month + relativedelta.relativedelta(months=1)
self.asset01.date_start = first_day_of_month self.asset01.date_start = first_day_of_month
def test_1(self): def test_no_batch_processing(self):
wiz = self.wiz_obj.create( wiz = self.wiz_obj.create(
{"batch_processing": False, "date_end": self.nextmonth} {"batch_processing": False, "date_end": self.nextmonth}
) )
@ -87,7 +87,7 @@ class TestAccountAssetBatchCompute(TransactionCase):
) )
self.assertTrue(len(depreciation_line) == 1) self.assertTrue(len(depreciation_line) == 1)
def test_2(self): def test_batch_processing(self):
wiz = self.wiz_obj.create( wiz = self.wiz_obj.create(
{"batch_processing": True, "date_end": self.nextmonth} {"batch_processing": True, "date_end": self.nextmonth}
) )
@ -112,6 +112,13 @@ class TestAccountAssetBatchCompute(TransactionCase):
jobs = self.env["queue.job"].search( jobs = self.env["queue.job"].search(
[("name", "=", job_name)], order="date_created desc", limit=1 [("name", "=", job_name)], order="date_created desc", limit=1
) )
self.assertEqual(
jobs.job_function_id,
self.env.ref(
"account_asset_batch_compute."
"job_function_account_asset_compute_asset_compute"
),
)
self.assertTrue(len(jobs) == 1) self.assertTrue(len(jobs) == 1)
job = Job.load(self.env, jobs.uuid) job = Job.load(self.env, jobs.uuid)
# perform job # perform job
@ -127,6 +134,12 @@ class TestAccountAssetBatchCompute(TransactionCase):
[("name", "=", job_name)], order="date_created desc", limit=1 [("name", "=", job_name)], order="date_created desc", limit=1
) )
self.assertTrue(len(jobs) == 1) self.assertTrue(len(jobs) == 1)
self.assertEqual(
jobs.job_function_id,
self.env.ref(
"account_asset_batch_compute.job_function_account_asset_compute_entries"
),
)
job = Job.load(self.env, jobs.uuid) job = Job.load(self.env, jobs.uuid)
job.perform() job.perform()
depreciation_line = self.asset01.depreciation_line_ids.filtered( depreciation_line = self.asset01.depreciation_line_ids.filtered(

View File

@ -1,16 +1,7 @@
# Copyright 2016-2017 ACSONE SA/NV # Copyright 2016-2017 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import logging from odoo import _, fields, models
from odoo import _, api, fields, models
_logger = logging.getLogger(__name__)
try:
from odoo.addons.queue_job.job import job
except ImportError:
_logger.debug("Can not `import queue_job`.")
class AccountAssetCompute(models.TransientModel): class AccountAssetCompute(models.TransientModel):
@ -19,8 +10,6 @@ class AccountAssetCompute(models.TransientModel):
batch_processing = fields.Boolean() batch_processing = fields.Boolean()
@api.multi
@job(default_channel="root.account_asset_batch_compute")
def asset_compute(self): def asset_compute(self):
self.ensure_one() self.ensure_one()
if not self.batch_processing: if not self.batch_processing: