From f5541768a6af90565de79e782d39643b9f5bfc11 Mon Sep 17 00:00:00 2001 From: "Nicolas (vin)" Date: Thu, 19 May 2022 14:34:02 +0000 Subject: [PATCH] [IMP] account: new journals audit report Improvement in two ways: - Implement a new, accounting report version of the existing journals audit pdf report, and remove the old journal audit report (PDF only). - Remove the menu items in "accounting" that opens the group by view of journal items with different filters. Now, these will be linked to actions on lines in the different reports available to the user. Also render the "journal items" menu visible without debug mode. Task id #2838182 closes odoo/odoo#92438 Related: odoo/upgrade#3560 Related: odoo/enterprise#27840 Signed-off-by: Quentin De Paoli --- addons/account/__manifest__.py | 1 - addons/account/report/__init__.py | 1 - addons/account/report/account_journal.py | 121 ----------- addons/account/views/account_menuitem.xml | 12 +- addons/account/views/account_move_views.xml | 3 + addons/account/views/report_journal.xml | 228 -------------------- 6 files changed, 4 insertions(+), 362 deletions(-) delete mode 100644 addons/account/report/account_journal.py delete mode 100644 addons/account/views/report_journal.xml diff --git a/addons/account/__manifest__.py b/addons/account/__manifest__.py index 70ab7d84935..522f7ca5ee9 100644 --- a/addons/account/__manifest__.py +++ b/addons/account/__manifest__.py @@ -55,7 +55,6 @@ You could use this simplified accounting in case you work with an (external) acc 'report/account_invoice_report_view.xml', 'views/account_cash_rounding_view.xml', 'wizard/account_report_common_view.xml', - 'views/report_journal.xml', 'views/tax_adjustments.xml', 'wizard/wizard_tax_adjustments_view.xml', 'views/ir_module_views.xml', diff --git a/addons/account/report/__init__.py b/addons/account/report/__init__.py index 7c1966465e6..f8bfe8e4ba3 100644 --- a/addons/account/report/__init__.py +++ b/addons/account/report/__init__.py @@ -2,5 +2,4 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from . import account_invoice_report -from . import account_journal from . import account_hash_integrity_templates diff --git a/addons/account/report/account_journal.py b/addons/account/report/account_journal.py deleted file mode 100644 index a327ef76364..00000000000 --- a/addons/account/report/account_journal.py +++ /dev/null @@ -1,121 +0,0 @@ -# -*- coding: utf-8 -*- - -import time -from odoo import api, models, _ -from odoo.exceptions import UserError - - -class ReportJournal(models.AbstractModel): - _name = 'report.account.report_journal' - _description = 'Account Journal Report' - - def lines(self, target_move, journal_ids, sort_selection, data): - if isinstance(journal_ids, int): - journal_ids = [journal_ids] - - move_state = ['draft', 'posted'] - if target_move == 'posted': - move_state = ['posted'] - - query_get_clause = self._get_query_get_clause(data) - params = [tuple(move_state), tuple(journal_ids)] + query_get_clause[2] - query = 'SELECT "account_move_line".id FROM ' + query_get_clause[0] + ', account_move am, account_account acc WHERE "account_move_line".account_id = acc.id AND "account_move_line".move_id=am.id AND am.state IN %s AND "account_move_line".journal_id IN %s AND ' + query_get_clause[1] + ' ORDER BY ' - if sort_selection == 'date': - query += '"account_move_line".date' - else: - query += 'am.name' - query += ', "account_move_line".move_id, acc.code' - self.env.cr.execute(query, tuple(params)) - ids = (x[0] for x in self.env.cr.fetchall()) - return self.env['account.move.line'].browse(ids) - - def _sum_debit(self, data, journal_id): - move_state = ['draft', 'posted'] - if data['form'].get('target_move', 'all') == 'posted': - move_state = ['posted'] - - query_get_clause = self._get_query_get_clause(data) - params = [tuple(move_state), tuple(journal_id.ids)] + query_get_clause[2] - self.env.cr.execute('SELECT SUM(debit) FROM ' + query_get_clause[0] + ', account_move am ' - 'WHERE "account_move_line".move_id=am.id AND am.state IN %s AND "account_move_line".journal_id IN %s AND ' + query_get_clause[1] + ' ', - tuple(params)) - return self.env.cr.fetchone()[0] or 0.0 - - def _sum_credit(self, data, journal_id): - move_state = ['draft', 'posted'] - if data['form'].get('target_move', 'all') == 'posted': - move_state = ['posted'] - - query_get_clause = self._get_query_get_clause(data) - params = [tuple(move_state), tuple(journal_id.ids)] + query_get_clause[2] - self.env.cr.execute('SELECT SUM(credit) FROM ' + query_get_clause[0] + ', account_move am ' - 'WHERE "account_move_line".move_id=am.id AND am.state IN %s AND "account_move_line".journal_id IN %s AND ' + query_get_clause[1] + ' ', - tuple(params)) - return self.env.cr.fetchone()[0] or 0.0 - - def _get_taxes(self, data, journal_id): - move_state = ['draft', 'posted'] - if data['form'].get('target_move', 'all') == 'posted': - move_state = ['posted'] - - query_get_clause = self._get_query_get_clause(data) - params = [tuple(move_state), tuple(journal_id.ids)] + query_get_clause[2] - query = """ - SELECT rel.account_tax_id, SUM("account_move_line".balance) AS base_amount - FROM account_move_line_account_tax_rel rel, """ + query_get_clause[0] + """ - LEFT JOIN account_move am ON "account_move_line".move_id = am.id - WHERE "account_move_line".id = rel.account_move_line_id - AND am.state IN %s - AND "account_move_line".journal_id IN %s - AND """ + query_get_clause[1] + """ - GROUP BY rel.account_tax_id""" - self.env.cr.execute(query, tuple(params)) - ids = [] - base_amounts = {} - for row in self.env.cr.fetchall(): - ids.append(row[0]) - base_amounts[row[0]] = row[1] - - - res = {} - for tax in self.env['account.tax'].browse(ids): - self.env.cr.execute('SELECT sum(debit - credit) FROM ' + query_get_clause[0] + ', account_move am ' - 'WHERE "account_move_line".move_id=am.id AND am.state IN %s AND "account_move_line".journal_id IN %s AND ' + query_get_clause[1] + ' AND tax_line_id = %s', - tuple(params + [tax.id])) - res[tax] = { - 'base_amount': base_amounts[tax.id], - 'tax_amount': self.env.cr.fetchone()[0] or 0.0, - } - if journal_id.type == 'sale': - #sales operation are credits - res[tax]['base_amount'] = res[tax]['base_amount'] * -1 - res[tax]['tax_amount'] = res[tax]['tax_amount'] * -1 - return res - - def _get_query_get_clause(self, data): - return self.env['account.move.line'].with_context(data['form'].get('used_context', {}))._query_get() - - @api.model - def _get_report_values(self, docids, data=None): - if not data.get('form'): - raise UserError(_("Form content is missing, this report cannot be printed.")) - - target_move = data['form'].get('target_move', 'all') - sort_selection = data['form'].get('sort_selection', 'date') - - res = {} - for journal in data['form']['journal_ids']: - res[journal] = self.with_context(data['form'].get('used_context', {})).lines(target_move, journal, sort_selection, data) - return { - 'doc_ids': data['form']['journal_ids'], - 'doc_model': self.env['account.journal'], - 'data': data, - 'docs': self.env['account.journal'].browse(data['form']['journal_ids']), - 'time': time, - 'lines': res, - 'sum_credit': self._sum_credit, - 'sum_debit': self._sum_debit, - 'get_taxes': self._get_taxes, - 'company_id': self.env['res.company'].browse( - data['form']['company_id'][0]), - } diff --git a/addons/account/views/account_menuitem.xml b/addons/account/views/account_menuitem.xml index 767a9b47ab3..479a65a42e9 100644 --- a/addons/account/views/account_menuitem.xml +++ b/addons/account/views/account_menuitem.xml @@ -26,17 +26,7 @@ - - - - - - - - - - - + diff --git a/addons/account/views/account_move_views.xml b/addons/account/views/account_move_views.xml index 0b04e7a1b7f..7585b129c42 100644 --- a/addons/account/views/account_move_views.xml +++ b/addons/account/views/account_move_views.xml @@ -370,6 +370,9 @@ + + + diff --git a/addons/account/views/report_journal.xml b/addons/account/views/report_journal.xml deleted file mode 100644 index 67d33763c46..00000000000 --- a/addons/account/views/report_journal.xml +++ /dev/null @@ -1,228 +0,0 @@ - - - -