[RFR] Apply a mapping instead of separate queries

This commit is contained in:
Pedro M. Baeza
2020-02-04 15:36:10 +01:00
committed by Borruso
parent 6cf151aa48
commit d9702bceab
4 changed files with 51 additions and 88 deletions

View File

@@ -14,13 +14,13 @@ Tax Balance
: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--reporting-lightgray.png?logo=github
:target: https://github.com/OCA/account-financial-reporting/tree/12.0/account_tax_balance
:target: https://github.com/OCA/account-financial-reporting/tree/13.0/account_tax_balance
:alt: OCA/account-financial-reporting
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/account-financial-reporting-12-0/account-financial-reporting-12-0-account_tax_balance
:target: https://translation.odoo-community.org/projects/account-financial-reporting-13-0/account-financial-reporting-13-0-account_tax_balance
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/91/12.0
:target: https://runbot.odoo-community.org/runbot/91/13.0
:alt: Try me on Runbot
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -49,7 +49,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-financial-reporting/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-reporting/issues/new?body=module:%20account_tax_balance%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-reporting/issues/new?body=module:%20account_tax_balance%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.
@@ -87,6 +87,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-reporting <https://github.com/OCA/account-financial-reporting/tree/12.0/account_tax_balance>`_ project on GitHub.
This module is part of the `OCA/account-financial-reporting <https://github.com/OCA/account-financial-reporting/tree/13.0/account_tax_balance>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@@ -1,7 +1,10 @@
# © 2020 Opener B.V. <https://opener.amsterdam>
# Copyright 2020 Opener B.V. <https://opener.amsterdam>
# Copyright 2020 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import logging
from psycopg2 import sql
def pre_init_hook(cr):
""" Precreate move_type and fill with appropriate values to prevent
@@ -10,66 +13,32 @@ def pre_init_hook(cr):
important as one move can have move lines on accounts of multiple types
and the move type is set in the order of precedence. """
logger = logging.getLogger(__name__)
logger.info('Add account_move.move_type column if it does not yet exist')
cr.execute(
"ALTER TABLE account_move ADD COLUMN IF NOT EXISTS move_type VARCHAR")
cr.execute(
"""
UPDATE account_move am SET move_type = 'liquidity'
FROM account_move_line aml
WHERE aml.account_id IN (
SELECT id FROM account_account
WHERE internal_type = 'liquidity')
AND aml.move_id = am.id AND am.move_type IS NULL
""")
logger.info('%s move set to type liquidity', cr.rowcount)
cr.execute(
"""
UPDATE account_move am SET move_type = 'payable'
FROM account_move_line aml
WHERE aml.account_id IN (
SELECT id FROM account_account
WHERE internal_type = 'payable')
AND aml.move_id = am.id AND am.move_type IS NULL
AND aml.balance < 0
""")
logger.info('%s move set to type payable', cr.rowcount)
cr.execute(
"""
UPDATE account_move am SET move_type = 'payable_refund'
FROM account_move_line aml
WHERE aml.account_id IN (
SELECT id FROM account_account
WHERE internal_type = 'payable')
AND aml.move_id = am.id AND am.move_type IS NULL
AND aml.balance >= 0
""")
logger.info('%s move set to type payable_refund', cr.rowcount)
cr.execute(
"""
UPDATE account_move am SET move_type = 'receivable'
FROM account_move_line aml
WHERE aml.account_id IN (
SELECT id FROM account_account
WHERE internal_type = 'receivable')
AND aml.move_id = am.id AND am.move_type IS NULL
AND aml.balance > 0
""")
logger.info('%s move set to type receivable', cr.rowcount)
cr.execute(
"""
UPDATE account_move am SET move_type = 'receivable_refund'
FROM account_move_line aml
WHERE aml.account_id IN (
SELECT id FROM account_account
WHERE internal_type = 'receivable')
AND aml.move_id = am.id AND am.move_type IS NULL
AND aml.balance <= 0
""")
logger.info('%s move set to type receivable_refund', cr.rowcount)
cr.execute(
"""
UPDATE account_move am SET move_type = 'other'
WHERE am.move_type IS NULL
""")
logger.info('%s move set to type other', cr.rowcount)
logger.info("Add account_move.move_type column if it does not yet exist")
cr.execute("ALTER TABLE account_move ADD COLUMN IF NOT EXISTS move_type VARCHAR")
MAPPING = [
("liquidity", "liquidity", False),
("payable", "payable", "AND aml.balance < 0"),
("payable_refund", "payable", "AND aml.balance >= 0"),
("receivable", "receivable", "AND aml.balance < 0"),
("receivable_refund", "receivable", "AND aml.balance >= 0"),
("other", False, False),
]
for move_type, internal_type, extra_where in MAPPING:
args = [move_type]
query = sql.SQL("UPDATE account_move am SET move_type = %s")
if internal_type:
query += sql.SQL(
"""FROM account_move_line aml
WHERE aml.account_id IN (
SELECT id FROM account_account
WHERE internal_type = %s)
AND aml.move_id = am.id AND am.move_type IS NULL
"""
)
args.append(internal_type)
else:
query += sql.SQL("WHERE am.move_type IS NULL")
if extra_where:
query += sql.SQL(extra_where)
cr.execute(query, tuple(args))
logger.info("%s move set to type %s", move_type, cr.rowcount)

View File

@@ -1,12 +1,12 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * account_tax_balance
# * account_tax_balance
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Project-Id-Version: Odoo Server 13.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: <>\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
@@ -14,16 +14,11 @@ msgstr ""
"Plural-Forms: \n"
#. module: account_tax_balance
#: code:addons/account_tax_balance/wizard/open_tax_balances.py:48
#: code:addons/account_tax_balance/wizard/open_tax_balances.py:0
#, python-format
msgid "%(name)s: %(target)s from %(from)s to %(to)s"
msgstr ""
#. module: account_tax_balance
#: model_terms:ir.ui.view,arch_db:account_tax_balance.view_tax_search_balance
msgid "Account"
msgstr ""
#. module: account_tax_balance
#: model_terms:ir.ui.view,arch_db:account_tax_balance.view_tax_search_balance
#: model_terms:ir.ui.view,arch_db:account_tax_balance.view_tax_tree_balance
@@ -31,12 +26,12 @@ msgid "Account Tax"
msgstr ""
#. module: account_tax_balance
#: selection:wizard.open.tax.balances,target_move:0
#: model:ir.model.fields.selection,name:account_tax_balance.selection__wizard_open_tax_balances__target_move__all
msgid "All Entries"
msgstr ""
#. module: account_tax_balance
#: selection:wizard.open.tax.balances,target_move:0
#: model:ir.model.fields.selection,name:account_tax_balance.selection__wizard_open_tax_balances__target_move__posted
msgid "All Posted Entries"
msgstr ""
@@ -87,7 +82,7 @@ msgstr ""
#. module: account_tax_balance
#: model:ir.model.fields,field_description:account_tax_balance.field_wizard_open_tax_balances__date_range_id
msgid "Date range"
msgid "Date Range"
msgstr ""
#. module: account_tax_balance
@@ -97,7 +92,7 @@ msgstr ""
#. module: account_tax_balance
#: model:ir.model.fields,field_description:account_tax_balance.field_wizard_open_tax_balances__from_date
msgid "From date"
msgid "From Date"
msgstr ""
#. module: account_tax_balance
@@ -192,7 +187,7 @@ msgstr ""
#. module: account_tax_balance
#: model:ir.model.fields,field_description:account_tax_balance.field_wizard_open_tax_balances__to_date
msgid "To date"
msgid "To Date"
msgstr ""
#. module: account_tax_balance
@@ -211,7 +206,7 @@ msgid "Total Base Balance"
msgstr ""
#. module: account_tax_balance
#: code:addons/account_tax_balance/models/account_tax.py:90
#: code:addons/account_tax_balance/models/account_tax.py:0
#, python-format
msgid "Unsupported search operator"
msgstr ""
@@ -255,4 +250,3 @@ msgstr ""
#: model_terms:ir.ui.view,arch_db:account_tax_balance.wizard_open_tax_balances
msgid "or"
msgstr ""

View File

@@ -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-reporting/tree/12.0/account_tax_balance"><img alt="OCA/account-financial-reporting" src="https://img.shields.io/badge/github-OCA%2Faccount--financial--reporting-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/account-financial-reporting-12-0/account-financial-reporting-12-0-account_tax_balance"><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/91/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-reporting/tree/13.0/account_tax_balance"><img alt="OCA/account-financial-reporting" src="https://img.shields.io/badge/github-OCA%2Faccount--financial--reporting-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/account-financial-reporting-13-0/account-financial-reporting-13-0-account_tax_balance"><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/91/13.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This module allows to compute tax balances within a certain date range.
It depends on date_range module and exposes compute methods that can be called by other modules
(like localization ones).</p>
@@ -397,7 +397,7 @@ It depends on date_range module and exposes compute methods that can be ca
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/account-financial-reporting/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-reporting/issues/new?body=module:%20account_tax_balance%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-reporting/issues/new?body=module:%20account_tax_balance%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>
</div>
<div class="section" id="credits">
@@ -429,7 +429,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
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-reporting/tree/12.0/account_tax_balance">OCA/account-financial-reporting</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/account-financial-reporting/tree/13.0/account_tax_balance">OCA/account-financial-reporting</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>