Browse Source

[ADD] - Add unit tests

pull/307/head
sbejaoui 5 years ago
parent
commit
6b658a649b
  1. 2
      report_substitute/README.rst
  2. 1
      report_substitute/__init__.py
  3. 3
      report_substitute/__manifest__.py
  4. 29
      report_substitute/demo/action_report.xml
  5. 2
      report_substitute/models/__init__.py
  6. 16
      report_substitute/models/ir_actions_report.py
  7. 6
      report_substitute/models/ir_actions_report_substitution_rule.py
  8. 2
      report_substitute/readme/USAGE.rst
  9. 12
      report_substitute/security/ir_actions_report_substitution_rule.xml
  10. 2
      report_substitute/static/description/index.html
  11. 1
      report_substitute/tests/__init__.py
  12. 48
      report_substitute/tests/test_report_substitute.py
  13. 4
      report_substitute/views/ir_actions_report.xml

2
report_substitute/README.rst

@ -42,7 +42,7 @@ To use this module, you need to:
#. Go to 'Actions' / 'Reports' #. Go to 'Actions' / 'Reports'
#. Select the desired report you want to substitute
#. Select the desired report you want to 'Substitution Rules'
#. In the substitutions page add a new line #. In the substitutions page add a new line

1
report_substitute/__init__.py

@ -1 +1,2 @@
from . import models from . import models
from . import tests

3
report_substitute/__manifest__.py

@ -13,7 +13,8 @@
'website': 'https://github.com/acsone/reporting-engine', 'website': 'https://github.com/acsone/reporting-engine',
'depends': ['base'], 'depends': ['base'],
'data': [ 'data': [
'security/ir_actions_report_substitution_criteria.xml',
'security/ir_actions_report_substitution_rule.xml',
'views/ir_actions_report.xml', 'views/ir_actions_report.xml',
], ],
'demo': ['demo/action_report.xml'],
} }

29
report_substitute/demo/action_report.xml

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="substitution_report">
<div class="page">Substitution Report</div>
</template>
<report id="substitution_report_print"
string="Substitution For Technical guide"
model="ir.module.module"
report_type="qweb-pdf"
file="report_substitute.substitution_report"
name="report_substitute.substitution_report"/>
<record id="substitution_rule_demo_1" model="ir.actions.report.substitution.rule">
<field name="action_report_id" ref="base.ir_module_reference_print"/>
<field name="substitution_action_report_id" ref="report_substitute.substitution_report_print"/>
</record>
<template id="substitution_report_2">
<div class="page">Substitution Report 2</div>
</template>
<report id="substitution_report_print_2"
string="Substitution 2 For Technical guide"
model="ir.module.module"
report_type="qweb-pdf"
file="report_substitute.substitution_report_2"
name="report_substitute.substitution_report_2"/>
</odoo>

2
report_substitute/models/__init__.py

@ -1,2 +1,2 @@
from . import ir_actions_report from . import ir_actions_report
from . import ir_actions_report_substitution_criteria
from . import ir_actions_report_substitution_rule

16
report_substitute/models/ir_actions_report.py

@ -1,7 +1,7 @@
# Copyright 2019 ACSONE SA/NV # Copyright 2019 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models, _
from odoo import api, fields, models
from odoo.tools.safe_eval import safe_eval from odoo.tools.safe_eval import safe_eval
@ -9,10 +9,10 @@ class IrActionReport(models.Model):
_inherit = 'ir.actions.report' _inherit = 'ir.actions.report'
action_report_substitution_criteria_ids = fields.One2many(
comodel_name="ir.actions.report.substitution.criteria",
action_report_substitution_rule_ids = fields.One2many(
comodel_name="ir.actions.report.substitution.rule",
inverse_name="action_report_id", inverse_name="action_report_id",
string="Substitution Criteria",
string="Substitution Rules",
) )
@api.multi @api.multi
@ -20,13 +20,13 @@ class IrActionReport(models.Model):
self.ensure_one() self.ensure_one()
model = self.env[model] model = self.env[model]
for ( for (
substitution_report_criteria
) in self.action_report_substitution_criteria_ids:
domain = safe_eval(substitution_report_criteria.domain)
substitution_report_rule
) in self.action_report_substitution_rule_ids:
domain = safe_eval(substitution_report_rule.domain)
domain.append(('id', 'in', active_ids)) domain.append(('id', 'in', active_ids))
if set(model.search(domain).ids) == set(active_ids): if set(model.search(domain).ids) == set(active_ids):
return ( return (
substitution_report_criteria.substitution_action_report_id
substitution_report_rule.substitution_action_report_id
) )
return False return False

6
report_substitute/models/ir_actions_report_substitution_criteria.py → report_substitute/models/ir_actions_report_substitution_rule.py

@ -4,10 +4,10 @@
from odoo import fields, models from odoo import fields, models
class ActionsReportSubstitutionCriteria(models.Model):
class ActionsReportSubstitutionRule(models.Model):
_name = 'ir.actions.report.substitution.criteria'
_description = 'Action Report Substitution Criteria'
_name = 'ir.actions.report.substitution.rule'
_description = 'Action Report Substitution Rule'
_order = 'sequence ASC' _order = 'sequence ASC'
sequence = fields.Integer(default=10) sequence = fields.Integer(default=10)

2
report_substitute/readme/USAGE.rst

@ -2,7 +2,7 @@ To use this module, you need to:
#. Go to 'Actions' / 'Reports' #. Go to 'Actions' / 'Reports'
#. Select the desired report you want to substitute
#. Select the desired report you want to 'Substitution Rules'
#. In the substitutions page add a new line #. In the substitutions page add a new line

12
report_substitute/security/ir_actions_report_substitution_criteria.xml → report_substitute/security/ir_actions_report_substitution_rule.xml

@ -4,18 +4,18 @@
<odoo> <odoo>
<record model="ir.model.access" id="action_report_substitution_criteria_user_access">
<field name="name">action.report.substitution.criteria user access</field>
<field name="model_id" ref="model_ir_actions_report_substitution_criteria"/>
<record model="ir.model.access" id="action_report_substitution_rule_user_access">
<field name="name">action.report.substitution.rule user access</field>
<field name="model_id" ref="model_ir_actions_report_substitution_rule"/>
<field name="perm_read" eval="1"/> <field name="perm_read" eval="1"/>
<field name="perm_create" eval="0"/> <field name="perm_create" eval="0"/>
<field name="perm_write" eval="0"/> <field name="perm_write" eval="0"/>
<field name="perm_unlink" eval="0"/> <field name="perm_unlink" eval="0"/>
</record> </record>
<record model="ir.model.access" id="action_report_substitution_criteria_manager_access">
<field name="name">action.report.substitution.criteria manager access</field>
<field name="model_id" ref="model_ir_actions_report_substitution_criteria"/>
<record model="ir.model.access" id="action_report_substitution_rule_manager_access">
<field name="name">action.report.substitution.rule manager access</field>
<field name="model_id" ref="model_ir_actions_report_substitution_rule"/>
<field name="group_id" ref="base.group_system"/> <field name="group_id" ref="base.group_system"/>
<field name="perm_read" eval="1"/> <field name="perm_read" eval="1"/>
<field name="perm_create" eval="1"/> <field name="perm_create" eval="1"/>

2
report_substitute/static/description/index.html

@ -391,7 +391,7 @@ reports for different companies.</p>
<p>To use this module, you need to:</p> <p>To use this module, you need to:</p>
<ol class="arabic simple"> <ol class="arabic simple">
<li>Go to ‘Actions’ / ‘Reports’</li> <li>Go to ‘Actions’ / ‘Reports’</li>
<li>Select the desired report you want to substitute</li>
<li>Select the desired report you want to ‘Substitution Rules’</li>
<li>In the substitutions page add a new line</li> <li>In the substitutions page add a new line</li>
<li>Select the substitution report action</li> <li>Select the substitution report action</li>
<li>Set a domain to specify when this substitution should happen</li> <li>Set a domain to specify when this substitution should happen</li>

1
report_substitute/tests/__init__.py

@ -0,0 +1 @@
from . import test_report_substitute

48
report_substitute/tests/test_report_substitute.py

@ -0,0 +1,48 @@
# Copyright 2019 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.tests.common import TransactionCase
class TestReportSubstitute(TransactionCase):
def setUp(self):
# In the demo file we create a new report for ir.module.module model
# with a substation rule from the original report action
super(TestReportSubstitute, self).setUp()
self.action_report = self.env.ref('base.ir_module_reference_print')
self.res_ids = self.env.ref('base.module_base').ids
self.substitution_rule = self.env.ref(
'report_substitute.substitution_rule_demo_1'
)
def test_substitution(self):
res = str(self.action_report.render(res_ids=self.res_ids)[0])
self.assertIn('<div class="page">Substitution Report</div>', res)
# remove the substation rule
self.substitution_rule.unlink()
res = str(self.action_report.render(res_ids=self.res_ids)[0])
self.assertNotIn('<div class="page">Substitution Report</div>', res)
def test_recursive_substitution(self):
res = str(self.action_report.render(res_ids=self.res_ids)[0])
self.assertNotIn('<div class="page">Substitution Report 2</div>', res)
self.env['ir.actions.report.substitution.rule'].create(
{
'substitution_action_report_id': self.env.ref(
'report_substitute.substitution_report_print_2'
).id,
'action_report_id': self.env.ref(
'report_substitute.substitution_report_print'
).id,
}
)
res = str(self.action_report.render(res_ids=self.res_ids)[0])
self.assertIn('<div class="page">Substitution Report 2</div>', res)
def test_substitution_with_domain(self):
self.substitution_rule.write({'domain': "[('name', '=', 'base')]"})
res = str(self.action_report.render(res_ids=self.res_ids)[0])
self.assertIn('<div class="page">Substitution Report</div>', res)
self.substitution_rule.write({'domain': "[('name', '!=', 'base')]"})
res = str(self.action_report.render(res_ids=self.res_ids)[0])
self.assertNotIn('<div class="page">Substitution Report</div>', res)

4
report_substitute/views/ir_actions_report.xml

@ -11,8 +11,8 @@
<field name="inherit_id" ref="base.act_report_xml_view"/> <field name="inherit_id" ref="base.act_report_xml_view"/>
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath expr="//page[@name='advanced']" position="after"> <xpath expr="//page[@name='advanced']" position="after">
<page name="report_substitution_criteria" string="Substitutions">
<field name="action_report_substitution_criteria_ids">
<page name="report_substitution_rule" string="Substitution Rules">
<field name="action_report_substitution_rule_ids">
<tree> <tree>
<field name="sequence" widget="handle"/> <field name="sequence" widget="handle"/>
<field name="substitution_action_report_id"/> <field name="substitution_action_report_id"/>

Loading…
Cancel
Save