From f06eacbadcea4c262b30e2f24353dbbc2b663f28 Mon Sep 17 00:00:00 2001 From: Frederik Jaeckel Date: Sun, 6 Nov 2022 15:40:23 +0100 Subject: [PATCH] =?UTF-8?q?auswertung:=20dashboard-window=20aktualisieren?= =?UTF-8?q?=20bei=20=C3=A4nderung=20der=20auswertung?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- evaluation.py | 25 +++++++++++++-- tests/test_report.py | 73 ++++++++++++++++++++++++++++++++++++++++++++ tryton.cfg | 2 ++ 3 files changed, 98 insertions(+), 2 deletions(-) diff --git a/evaluation.py b/evaluation.py index 81585ae..e72d43b 100644 --- a/evaluation.py +++ b/evaluation.py @@ -193,10 +193,13 @@ class Evaluation(sequence_ordered(), ModelSQL, ModelView): ActWin = pool.get('ir.action.act_window') ActView = pool.get('ir.action.act_window.view') Evaluation2 = pool.get('cashbook_report.evaluation') - - cls.uiview_delete(evaluations) + try : + DashboardAction = pool.get('dashboard.action') + except: + DashboardAction = None to_write_eval = [] + to_write_dbaction = [] for evaluation in evaluations: with Transaction().set_context({ '_check_access': False, @@ -226,6 +229,24 @@ class Evaluation(sequence_ordered(), ModelSQL, ModelView): 'dashb_actview': dashb_actview.id, }]) + # prepare update dasboard-action + if DashboardAction is not None: + if evaluation.dashb_actwin: + db_actions = DashboardAction.search([ + ('act_window.id', '=', evaluation.dashb_actwin.id), + ]) + if len(db_actions) > 0: + to_write_dbaction.extend([ + db_actions, + { + 'act_window': dashb_actwin.id, + }]) + + if len(to_write_dbaction) > 0: + DashboardAction.write(*to_write_dbaction) + + cls.uiview_delete(evaluations) + if len(to_write_eval) > 0: Evaluation2.write(*to_write_eval) diff --git a/tests/test_report.py b/tests/test_report.py index 4f1025b..a52c979 100644 --- a/tests/test_report.py +++ b/tests/test_report.py @@ -531,6 +531,79 @@ class ReportTestCase(CashbookTestCase): 'types': [('add', [x.id for x in Types.search([])])], }]) + @with_transaction() + def test_report_check_update_of_actionviews(self): + """ create 3x cashbooks, add evaluation, check created + form + actionview + """ + pool = Pool() + Evaluation = pool.get('cashbook_report.evaluation') + try : + DashboardAction = pool.get('dashboard.action') + except: + print('\n--== Module "dashboard" not installed ==--') + DashboardAction = None + + books = self.prep_report_3books() + + company = self.prep_company() + with Transaction().set_context({ + 'company': company.id, + }): + evaluation, = Evaluation.create([{ + 'name': 'Evaluation 1', + 'cashbooks': [('add', [x.id for x in books])], + }]) + + # add dashboard-action + if DashboardAction is not None: + dbaction, = DashboardAction.create([{ + 'user': Transaction().user, + 'act_window': evaluation.dashb_actwin.id, + }]) + self.assertEqual(dbaction.user.rec_name, 'Administrator') + self.assertEqual(dbaction.act_window.name, 'Evaluation 1') + + self.assertEqual(evaluation.dtype, 'cashbooks') + self.assertEqual(evaluation.chart, 'pie') + self.assertEqual(evaluation.legend, True) + self.assertEqual(evaluation.maincolor, 'default') + self.assertEqual(evaluation.bgcolor, '#ffffc0') + self.assertEqual(evaluation.currency.code, 'EUR') + + # check uiview + self.assertEqual(evaluation.ui_view_chart.model, 'cashbook_report.eval_line') + self.assertEqual(evaluation.ui_view_chart.module, 'cashbook_report') + self.assertEqual(evaluation.ui_view_chart.priority, 10) + self.assertEqual(evaluation.ui_view_chart.type, 'graph') + # action-window for dashbord + self.assertEqual(evaluation.dashb_actwin.name, 'Evaluation 1') + self.assertEqual(evaluation.dashb_actwin.res_model, + 'cashbook_report.eval_line') + self.assertEqual(evaluation.dashb_actwin.usage, + 'dashboard') + self.assertEqual(evaluation.dashb_actwin.domain, + '[["evaluation", "=", %d]]' % evaluation.id) + # action-view + self.assertEqual(evaluation.dashb_actview.sequence, 10) + self.assertEqual(evaluation.dashb_actview.view.id, + evaluation.ui_view_chart.id) + self.assertEqual(evaluation.dashb_actview.act_window.id, + evaluation.dashb_actwin.id) + + # update evaluation, this wil re-create the view/act-window + # and update the dashboard-view, without removing it + old_win_id = evaluation.dashb_actwin.id + Evaluation.write(*[ + [evaluation], + { + 'name': 'Evaluation 1a', + }]) + self.assertTrue(old_win_id != evaluation.dashb_actwin.id) + + if DashboardAction is not None: + self.assertEqual(DashboardAction.search_count([]), 1) + @with_transaction() def test_report_chart_pie_book_red(self): """ create 3x cashbooks, add bookings, diff --git a/tryton.cfg b/tryton.cfg index 39ede05..b53705c 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -3,6 +3,8 @@ version=6.0.2 depends: res cashbook +extras_depend: + dashboard xml: icon.xml message.xml