From cd93363ef875efbff51a33a41288dbc15069ec87 Mon Sep 17 00:00:00 2001 From: mreficent Date: Thu, 23 Apr 2020 15:33:10 +0200 Subject: [PATCH] [MIG] mis_builder_cash_flow: Migration to 13.0 --- mis_builder_cash_flow/__manifest__.py | 4 +-- mis_builder_cash_flow/data/mis_report.xml | 8 +++--- .../i18n/mis_builder_cash_flow.pot | 2 +- .../models/mis_cash_flow_forecast_line.py | 5 ++-- mis_builder_cash_flow/report/mis_cash_flow.py | 26 +++++++------------ mis_builder_cash_flow/tests/test_cash_flow.py | 14 +++++----- oca_dependencies.txt | 1 + 7 files changed, 26 insertions(+), 34 deletions(-) diff --git a/mis_builder_cash_flow/__manifest__.py b/mis_builder_cash_flow/__manifest__.py index 7e872274..61fcfb0c 100644 --- a/mis_builder_cash_flow/__manifest__.py +++ b/mis_builder_cash_flow/__manifest__.py @@ -3,11 +3,11 @@ { "name": "MIS Builder Cash Flow", - "version": "12.0.1.3.0", + "version": "13.0.1.0.0", "license": "LGPL-3", "author": "ADHOC SA, " "Odoo Community Association (OCA)", "website": "https://github.com/OCA/mis-builder", - "depends": ["mis_builder",], + "depends": ["mis_builder"], "data": [ "security/mis_cash_flow_security.xml", "report/mis_cash_flow_views.xml", diff --git a/mis_builder_cash_flow/data/mis_report.xml b/mis_builder_cash_flow/data/mis_report.xml index 74222d3e..3cd9636a 100644 --- a/mis_builder_cash_flow/data/mis_report.xml +++ b/mis_builder_cash_flow/data/mis_report.xml @@ -16,7 +16,7 @@ 20 bal[][('account_id.internal_type', '=', 'liquidity'), ('line_type', '=', 'move_line'), ('account_id.hide_in_cash_flow', '=', False)] + >bal[][('account_internal_type', '=', 'liquidity'), ('line_type', '=', 'move_line'), ('account_id.hide_in_cash_flow', '=', False)] @@ -36,7 +36,7 @@ 50 bal[][('account_id.internal_type', '=', 'receivable'), ('full_reconcile_id', '=', False), ('line_type', '=', 'move_line'), ('account_id.hide_in_cash_flow', '=', False)] + >bal[][('account_internal_type', '=', 'receivable'), ('full_reconcile_id', '=', False), ('line_type', '=', 'move_line'), ('account_id.hide_in_cash_flow', '=', False)] @@ -68,7 +68,7 @@ 100 bal[][('account_id.internal_type', '=', 'payable'), ('full_reconcile_id', '=', False), ('line_type', '=', 'move_line'), ('account_id.hide_in_cash_flow', '=', False)] + >bal[][('account_internal_type', '=', 'payable'), ('full_reconcile_id', '=', False), ('line_type', '=', 'move_line'), ('account_id.hide_in_cash_flow', '=', False)] @@ -101,7 +101,7 @@ 150 bale[][('account_id.hide_in_cash_flow', '=', False), '|', ('line_type', '=', 'forecast_line'), ('line_type', '=', 'move_line'), '|', ('account_id.internal_type', '=', 'liquidity'), ('account_id.internal_type', 'in', ('receivable', 'payable')), ('full_reconcile_id', '=', False)] + >bale[][('account_id.hide_in_cash_flow', '=', False), '|', ('line_type', '=', 'forecast_line'), ('line_type', '=', 'move_line'), '|', ('account_internal_type', '=', 'liquidity'), ('account_internal_type', 'in', ('receivable', 'payable')), ('full_reconcile_id', '=', False)] 'Cash Flow - Good' if balance >= 0.0 else 'Cash Flow - Bad' diff --git a/mis_builder_cash_flow/i18n/mis_builder_cash_flow.pot b/mis_builder_cash_flow/i18n/mis_builder_cash_flow.pot index 1edf6fbc..8ba8cb2d 100644 --- a/mis_builder_cash_flow/i18n/mis_builder_cash_flow.pot +++ b/mis_builder_cash_flow/i18n/mis_builder_cash_flow.pot @@ -4,7 +4,7 @@ # 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" "Language-Team: \n" diff --git a/mis_builder_cash_flow/models/mis_cash_flow_forecast_line.py b/mis_builder_cash_flow/models/mis_cash_flow_forecast_line.py index d9c1bc6c..e01cd3f7 100644 --- a/mis_builder_cash_flow/models/mis_cash_flow_forecast_line.py +++ b/mis_builder_cash_flow/models/mis_cash_flow_forecast_line.py @@ -14,7 +14,7 @@ class MisCashFlowForecastLine(models.Model): comodel_name="account.account", string="Account", required=True, - help="The account of the forecast line is only for informative " "purpose", + help="The account of the forecast line is only for informative purpose", ) partner_id = fields.Many2one(comodel_name="res.partner", string="Partner",) name = fields.Char(required=True, default="/",) @@ -27,10 +27,9 @@ class MisCashFlowForecastLine(models.Model): index=True, ) - @api.multi @api.constrains("company_id", "account_id") def _check_company_id_account_id(self): if self.filtered(lambda x: x.company_id != x.account_id.company_id): raise ValidationError( - _("The Company and the Company of the Account must be the " "same.") + _("The Company and the Company of the Account must be the same.") ) diff --git a/mis_builder_cash_flow/report/mis_cash_flow.py b/mis_builder_cash_flow/report/mis_cash_flow.py index e9909d0b..025e3aca 100644 --- a/mis_builder_cash_flow/report/mis_cash_flow.py +++ b/mis_builder_cash_flow/report/mis_cash_flow.py @@ -2,7 +2,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from psycopg2.extensions import AsIs -from odoo import api, fields, models, tools +from odoo import fields, models, tools class MisCashFlow(models.Model): @@ -47,15 +47,12 @@ class MisCashFlow(models.Model): full_reconcile_id = fields.Many2one( "account.full.reconcile", string="Matching Number", readonly=True, index=True, ) - user_type_id = fields.Many2one( - "account.account.type", auto_join=True, readonly=True, index=True, + account_internal_type = fields.Selection( + related="account_id.user_type_id.type", readonly=True ) - @api.model_cr def init(self): - account_type_receivable = self.env.ref("account.data_account_type_receivable") - query = ( - """ + query = """ SELECT -- we use negative id to avoid duplicates and we don't use -- ROW_NUMBER() because the performance was very poor @@ -77,15 +74,14 @@ class MisCashFlow(models.Model): aml.full_reconcile_id as full_reconcile_id, aml.partner_id as partner_id, aml.company_id as company_id, - aml.user_type_id as user_type_id, aml.name as name, - aml.date_maturity as date + COALESCE(aml.date_maturity, aml.date) as date FROM account_move_line as aml UNION ALL SELECT fl.id as id, CAST('forecast_line' AS varchar) as line_type, - Null as move_line_id, + NULL as move_line_id, fl.account_id as account_id, CASE WHEN fl.balance > 0 @@ -97,23 +93,19 @@ class MisCashFlow(models.Model): THEN -fl.balance ELSE 0.0 END AS credit, - Null as reconciled, - Null as full_reconcile_id, + NULL as reconciled, + NULL as full_reconcile_id, fl.partner_id as partner_id, fl.company_id as company_id, - %i as user_type_id, fl.name as name, fl.date as date FROM mis_cash_flow_forecast_line as fl """ - % account_type_receivable.id - ) tools.drop_view_if_exists(self.env.cr, self._table) self._cr.execute( - "CREATE OR REPLACE VIEW %s AS %s", (AsIs(self._table), AsIs(query)) + "CREATE OR REPLACE VIEW %s AS (%s)", (AsIs(self._table), AsIs(query)) ) - @api.multi def action_open_related_line(self): self.ensure_one() if self.line_type == "move_line": diff --git a/mis_builder_cash_flow/tests/test_cash_flow.py b/mis_builder_cash_flow/tests/test_cash_flow.py index 84656001..a9c6cc9d 100644 --- a/mis_builder_cash_flow/tests/test_cash_flow.py +++ b/mis_builder_cash_flow/tests/test_cash_flow.py @@ -5,12 +5,11 @@ from datetime import timedelta from odoo.exceptions import ValidationError from odoo.fields import Date -from odoo.tests.common import TransactionCase, at_install, post_install +from odoo.tests.common import TransactionCase, tagged from odoo.tools import mute_logger -@at_install(False) -@post_install(True) +@tagged("post_install", "-at_install") class TestCashFlow(TransactionCase): def setUp(self): super().setUp() @@ -61,7 +60,7 @@ class TestCashFlow(TransactionCase): def test_company_constrain(self): with self.assertRaises(ValidationError): self.env["mis.cash_flow.forecast_line"].create( - {"account_id": self.account.id, "date": Date.today(), "balance": 1000,} + {"account_id": self.account.id, "date": Date.today(), "balance": 1000} ) def test_report_instance(self): @@ -71,6 +70,7 @@ class TestCashFlow(TransactionCase): "name": "Move", "journal_id": self.journal.id, "company_id": self.company.id, + "type": "entry", "line_ids": [ ( 0, @@ -114,11 +114,11 @@ class TestCashFlow(TransactionCase): ], ignore_rows=["balance", "period_balance", "in_total"], ) - date = Date.from_string(Date.today()) + timedelta(weeks=8) + date = Date.today() + timedelta(weeks=8) self.env["mis.cash_flow.forecast_line"].create( { "account_id": self.account.id, - "date": Date.to_string(date), + "date": date, "balance": 1000, "company_id": self.company.id, } @@ -133,7 +133,7 @@ class TestCashFlow(TransactionCase): ignore_rows=["balance", "period_balance", "in_total"], ) - def check_matrix(self, args=False, ignore_rows=False): + def check_matrix(self, args=None, ignore_rows=None): if not args: args = [] if not ignore_rows: diff --git a/oca_dependencies.txt b/oca_dependencies.txt index 5cd2498e..3a636c03 100644 --- a/oca_dependencies.txt +++ b/oca_dependencies.txt @@ -1,2 +1,3 @@ +mis-builder server-ux reporting-engine