[IMP] - add unit tests
parent
ed669b00a3
commit
1393f84ca6
|
@ -41,17 +41,17 @@ class IrActionReport(models.Model):
|
|||
return action_report
|
||||
|
||||
@api.model
|
||||
def get_substitution_report_dict(self, action_report_dict, active_ids):
|
||||
if action_report_dict.get('id'):
|
||||
action_report = self.browse(action_report_dict['id'])
|
||||
def get_substitution_report_action(self, action, active_ids):
|
||||
if action.get('id'):
|
||||
action_report = self.browse(action['id'])
|
||||
substitution_report = action_report
|
||||
while substitution_report:
|
||||
action_report = substitution_report
|
||||
substitution_report = action_report._get_substitution_report(
|
||||
action_report.model, active_ids
|
||||
)
|
||||
action_report_dict.update(action_report.read()[0])
|
||||
return action_report_dict
|
||||
action.update(action_report.read()[0])
|
||||
return action
|
||||
|
||||
@api.multi
|
||||
def render(self, res_ids, data=None):
|
||||
|
|
|
@ -14,17 +14,19 @@ odoo.define("report_substitute.action_report_substitute", function (require) {
|
|||
|
||||
_handleAction: function (action, options) {
|
||||
if (action.type === "ir.actions.report" &&
|
||||
action.context.active_ids) {
|
||||
action.context.active_ids &&
|
||||
action.action_report_substitution_rule_ids &&
|
||||
action.action_report_substitution_rule_ids != 0) {
|
||||
var active_ids = action.context.active_ids;
|
||||
var self = this;
|
||||
var _super = this._super;
|
||||
var callersArguments = arguments;
|
||||
return this._rpc({
|
||||
model: "ir.actions.report",
|
||||
method: "get_substitution_report_dict",
|
||||
method: "get_substitution_report_action",
|
||||
args: [action, active_ids]
|
||||
}).then(function (action_id) {
|
||||
callersArguments[0] = action_id
|
||||
}).then(function (substitution_action) {
|
||||
callersArguments[0] = substitution_action
|
||||
return _super.apply(self, callersArguments);
|
||||
});
|
||||
|
||||
|
@ -34,4 +36,4 @@ odoo.define("report_substitute.action_report_substitute", function (require) {
|
|||
|
||||
});
|
||||
|
||||
});
|
||||
});
|
|
@ -46,3 +46,21 @@ class TestReportSubstitute(TransactionCase):
|
|||
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)
|
||||
|
||||
def test_substitution_with_action_dict(self):
|
||||
substitution_report_action = self.env[
|
||||
'ir.actions.report'
|
||||
].get_substitution_report_action(
|
||||
self.action_report.read()[0], self.res_ids
|
||||
)
|
||||
self.assertEqual(
|
||||
substitution_report_action['id'],
|
||||
self.substitution_rule.substitution_action_report_id.id,
|
||||
)
|
||||
|
||||
def test_substitution_with_report_action(self):
|
||||
res = self.action_report.report_action(self.res_ids)
|
||||
self.assertEqual(
|
||||
res['report_name'],
|
||||
self.substitution_rule.substitution_action_report_id.report_name,
|
||||
)
|
||||
|
|
|
@ -11,18 +11,21 @@ class MailComposeMessage(models.TransientModel):
|
|||
@api.multi
|
||||
@api.onchange('template_id')
|
||||
def onchange_template_id_wrapper(self):
|
||||
old_report_template = False
|
||||
if (
|
||||
self.template_id
|
||||
and self.template_id.report_template
|
||||
and self.env.context.get('active_ids')
|
||||
):
|
||||
active_ids = self.env.context.get('active_ids')
|
||||
old_report_template = self.template_id.report_template
|
||||
self.template_id.report_template = (
|
||||
old_report_template.get_substitution_report(active_ids)
|
||||
)
|
||||
res = super().onchange_template_id_wrapper()
|
||||
if old_report_template:
|
||||
self.template_id.report_template = old_report_template
|
||||
return res
|
||||
if self.template_id:
|
||||
report_template = self.template_id.report_template
|
||||
if (
|
||||
report_template
|
||||
and report_template.action_report_substitution_rule_ids
|
||||
and self.env.context.get('active_ids')
|
||||
):
|
||||
active_ids = self.env.context.get('active_ids')
|
||||
old_report_template = report_template
|
||||
self.template_id.report_template = (
|
||||
old_report_template.get_substitution_report(active_ids)
|
||||
)
|
||||
onchange_result_with_substituted_report = (
|
||||
super().onchange_template_id_wrapper()
|
||||
)
|
||||
self.template_id.report_template = old_report_template
|
||||
return onchange_result_with_substituted_report
|
||||
return super().onchange_template_id_wrapper()
|
||||
|
|
Loading…
Reference in New Issue