From d6c6ad7e5ba50cbd8d57be4c28d7de8746e00141 Mon Sep 17 00:00:00 2001 From: Andrea Date: Tue, 24 Jul 2018 16:43:49 +0200 Subject: [PATCH 1/4] Extract method to ease extensions --- l10n_nl_xaf_auditfile_export/__manifest__.py | 2 +- .../models/xaf_auditfile_export.py | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/l10n_nl_xaf_auditfile_export/__manifest__.py b/l10n_nl_xaf_auditfile_export/__manifest__.py index 7691e43a5..713468da1 100644 --- a/l10n_nl_xaf_auditfile_export/__manifest__.py +++ b/l10n_nl_xaf_auditfile_export/__manifest__.py @@ -3,7 +3,7 @@ { "name": "XAF auditfile export", - "version": "11.0.1.0.1", + "version": "11.0.1.1.0", "author": "Therp BV, Odoo Community Association (OCA)", "license": "AGPL-3", "category": "Accounting & Finance", diff --git a/l10n_nl_xaf_auditfile_export/models/xaf_auditfile_export.py b/l10n_nl_xaf_auditfile_export/models/xaf_auditfile_export.py index e68a22a3f..de28147c6 100644 --- a/l10n_nl_xaf_auditfile_export/models/xaf_auditfile_export.py +++ b/l10n_nl_xaf_auditfile_export/models/xaf_auditfile_export.py @@ -71,11 +71,17 @@ def check_dates(self): raise exceptions.ValidationError( _('Starting date must be anterior ending date!')) + @api.multi + def _get_auditfile_template(self): + '''return the qweb template to be rendered''' + return "l10n_nl_xaf_auditfile_export.auditfile_template" + @api.multi def button_generate(self): self.date_generated = fields.Datetime.now(self) + auditfile_template = self._get_auditfile_template() xml = self.env['ir.ui.view'].render_template( - "l10n_nl_xaf_auditfile_export.auditfile_template", + auditfile_template, values={ 'self': self, }, From caf2725f8cc0cbe19650beba41416b96e1b11035 Mon Sep 17 00:00:00 2001 From: Andrea Date: Thu, 26 Jul 2018 11:56:00 +0200 Subject: [PATCH 2/4] Add basic tests --- .../tests/__init__.py | 3 ++ .../test_l10n_nl_xaf_auditfile_export.py | 51 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 l10n_nl_xaf_auditfile_export/tests/__init__.py create mode 100644 l10n_nl_xaf_auditfile_export/tests/test_l10n_nl_xaf_auditfile_export.py diff --git a/l10n_nl_xaf_auditfile_export/tests/__init__.py b/l10n_nl_xaf_auditfile_export/tests/__init__.py new file mode 100644 index 000000000..8c1ca88d5 --- /dev/null +++ b/l10n_nl_xaf_auditfile_export/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import test_l10n_nl_xaf_auditfile_export diff --git a/l10n_nl_xaf_auditfile_export/tests/test_l10n_nl_xaf_auditfile_export.py b/l10n_nl_xaf_auditfile_export/tests/test_l10n_nl_xaf_auditfile_export.py new file mode 100644 index 000000000..d39e3a7c9 --- /dev/null +++ b/l10n_nl_xaf_auditfile_export/tests/test_l10n_nl_xaf_auditfile_export.py @@ -0,0 +1,51 @@ +# Copyright 2018 Onestein () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo.tests.common import TransactionCase + + +class TestXafAuditfileExport(TransactionCase): + + def test_01_default_values(self): + ''' Check that the default values are filled on creation ''' + record = self.env['xaf.auditfile.export'].create({}) + + self.assertTrue(record) + self.assertTrue(record.name) + self.assertFalse(record.auditfile) + self.assertTrue(record.auditfile_name) + self.assertTrue(record.company_id) + self.assertTrue(record.date_start) + self.assertTrue(record.date_end) + self.assertFalse(record.date_generated) + self.assertTrue(record.fiscalyear_name) + + def test_02_export_success(self): + ''' Do a basic auditfile export ''' + record = self.env['xaf.auditfile.export'].create({}) + record.button_generate() + + self.assertTrue(record.name) + self.assertTrue(record.auditfile) + self.assertTrue(record.auditfile_name) + self.assertTrue(record.company_id) + self.assertTrue(record.date_start) + self.assertTrue(record.date_end) + self.assertTrue(record.date_generated) + self.assertTrue(record.fiscalyear_name) + + def test_03_export_error(self): + ''' Failure to export an auditfile ''' + record = self.env['xaf.auditfile.export'].create({}) + record.company_id.country_id = False + record.button_generate() + + self.assertTrue(record) + self.assertTrue(record.name) + self.assertFalse(record.auditfile) + self.assertTrue(record.auditfile_name) + self.assertTrue(record.company_id) + self.assertTrue(record.date_start) + self.assertTrue(record.date_end) + self.assertTrue(record.date_generated) + self.assertTrue(record.fiscalyear_name) From fa2460ce89a0d8027616cac7d8da46c823e3747c Mon Sep 17 00:00:00 2001 From: Andrea Date: Fri, 27 Jul 2018 14:00:24 +0200 Subject: [PATCH 3/4] Make filename field stored + code review --- .../models/xaf_auditfile_export.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/l10n_nl_xaf_auditfile_export/models/xaf_auditfile_export.py b/l10n_nl_xaf_auditfile_export/models/xaf_auditfile_export.py index de28147c6..2e32d5436 100644 --- a/l10n_nl_xaf_auditfile_export/models/xaf_auditfile_export.py +++ b/l10n_nl_xaf_auditfile_export/models/xaf_auditfile_export.py @@ -24,8 +24,9 @@ class XafAuditfileExport(models.Model): _order = 'date_start desc' @api.depends('name') - def _auditfile_name_get(self): - self.auditfile_name = '%s.xaf' % self.name + def _compute_auditfile_name(self): + for item in self: + item.auditfile_name = '%s.xaf' % item.name @api.multi def _compute_fiscalyear_name(self): @@ -39,7 +40,10 @@ def _compute_fiscalyear_name(self): fiscalyear_name = fields.Char(compute='_compute_fiscalyear_name') auditfile = fields.Binary('Auditfile', readonly=True, copy=False) auditfile_name = fields.Char( - 'Auditfile filename', compute=_auditfile_name_get) + 'Auditfile filename', + compute='_compute_auditfile_name', + store=True + ) date_generated = fields.Datetime( 'Date generated', readonly=True, copy=False) company_id = fields.Many2one('res.company', 'Company', required=True) From dd2035fb0cd76f858710b6c0434d6689b83d217c Mon Sep 17 00:00:00 2001 From: Andrea Date: Fri, 27 Jul 2018 14:16:59 +0200 Subject: [PATCH 4/4] Add group in view for extra options --- l10n_nl_xaf_auditfile_export/views/xaf_auditfile_export.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/l10n_nl_xaf_auditfile_export/views/xaf_auditfile_export.xml b/l10n_nl_xaf_auditfile_export/views/xaf_auditfile_export.xml index 8c0804984..15be4cb31 100644 --- a/l10n_nl_xaf_auditfile_export/views/xaf_auditfile_export.xml +++ b/l10n_nl_xaf_auditfile_export/views/xaf_auditfile_export.xml @@ -31,6 +31,8 @@ + +