summaryrefslogtreecommitdiff
path: root/addons/account_test/report
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/account_test/report
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/account_test/report')
-rw-r--r--addons/account_test/report/__init__.py4
-rw-r--r--addons/account_test/report/accounting_assert_test_reports.xml12
-rw-r--r--addons/account_test/report/report_account_test.py75
-rw-r--r--addons/account_test/report/report_account_test_templates.xml21
4 files changed, 112 insertions, 0 deletions
diff --git a/addons/account_test/report/__init__.py b/addons/account_test/report/__init__.py
new file mode 100644
index 00000000..8476cf00
--- /dev/null
+++ b/addons/account_test/report/__init__.py
@@ -0,0 +1,4 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from . import report_account_test
diff --git a/addons/account_test/report/accounting_assert_test_reports.xml b/addons/account_test/report/accounting_assert_test_reports.xml
new file mode 100644
index 00000000..bf2af639
--- /dev/null
+++ b/addons/account_test/report/accounting_assert_test_reports.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<odoo>
+ <record id="account_assert_test_report" model="ir.actions.report">
+ <field name="name">Accounting Tests</field>
+ <field name="model">accounting.assert.test</field>
+ <field name="report_type">qweb-pdf</field>
+ <field name="report_name">account_test.report_accounttest</field>
+ <field name="report_file">account_test.report_accounttest</field>
+ <field name="binding_model_id" ref="model_accounting_assert_test"/>
+ <field name="binding_type">report</field>
+ </record>
+</odoo>
diff --git a/addons/account_test/report/report_account_test.py b/addons/account_test/report/report_account_test.py
new file mode 100644
index 00000000..546c5820
--- /dev/null
+++ b/addons/account_test/report/report_account_test.py
@@ -0,0 +1,75 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+import datetime
+from odoo import api, models, _
+from odoo.tools.safe_eval import safe_eval
+#
+# Use period and Journal for selection or resources
+#
+
+
+class ReportAssertAccount(models.AbstractModel):
+ _name = 'report.account_test.report_accounttest'
+ _description = 'Account Test Report'
+
+ @api.model
+ def execute_code(self, code_exec):
+ def reconciled_inv():
+ """
+ returns the list of invoices that are set as reconciled = True
+ """
+ return self.env['account.move'].search([('reconciled', '=', True)]).ids
+
+ def order_columns(item, cols=None):
+ """
+ This function is used to display a dictionary as a string, with its columns in the order chosen.
+
+ :param item: dict
+ :param cols: list of field names
+ :returns: a list of tuples (fieldname: value) in a similar way that would dict.items() do except that the
+ returned values are following the order given by cols
+ :rtype: [(key, value)]
+ """
+ if cols is None:
+ cols = list(item)
+ return [(col, item.get(col)) for col in cols if col in item]
+
+ localdict = {
+ 'cr': self.env.cr,
+ 'uid': self.env.uid,
+ 'reconciled_inv': reconciled_inv, # specific function used in different tests
+ 'result': None, # used to store the result of the test
+ 'column_order': None, # used to choose the display order of columns (in case you are returning a list of dict)
+ '_': _,
+ }
+ safe_eval(code_exec, localdict, mode="exec", nocopy=True)
+ result = localdict['result']
+ column_order = localdict.get('column_order', None)
+
+ if not isinstance(result, (tuple, list, set)):
+ result = [result]
+ if not result:
+ result = [_('The test was passed successfully')]
+ else:
+ def _format(item):
+ if isinstance(item, dict):
+ return ', '.join(["%s: %s" % (tup[0], tup[1]) for tup in order_columns(item, column_order)])
+ else:
+ return item
+ result = [_format(rec) for rec in result]
+
+ return result
+
+ @api.model
+ def _get_report_values(self, docids, data=None):
+ report = self.env['ir.actions.report']._get_report_from_name('account_test.report_accounttest')
+ records = self.env['accounting.assert.test'].browse(self.ids)
+ return {
+ 'doc_ids': self._ids,
+ 'doc_model': report.model,
+ 'docs': records,
+ 'data': data,
+ 'execute_code': self.execute_code,
+ 'datetime': datetime
+ }
diff --git a/addons/account_test/report/report_account_test_templates.xml b/addons/account_test/report/report_account_test_templates.xml
new file mode 100644
index 00000000..9ee84b08
--- /dev/null
+++ b/addons/account_test/report/report_account_test_templates.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<odoo>
+<template id="report_accounttest">
+ <t t-call="web.html_container">
+ <t t-call="web.internal_layout">
+ <div class="page">
+ <h2>Accounting tests on <span t-esc="datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')"/></h2>
+ <div t-foreach="docs" t-as="o">
+ <p>
+ <strong>Name:</strong> <span t-field="o.name"/><br/>
+ <strong>Description:</strong> <span t-field="o.desc"/>
+ </p>
+ <p t-foreach="execute_code(o.code_exec)" t-as="test_result">
+ <span t-esc="test_result"/>
+ </p>
+ </div>
+ </div>
+ </t>
+ </t>
+</template>
+</odoo>