Browse Source

[IMP] - manage subtitute report for multi-action

pull/307/head
sbejaoui 5 years ago
parent
commit
ea774aab9c
  1. 1
      report_substitute/__manifest__.py
  2. 17
      report_substitute/models/ir_actions_report.py
  3. 35
      report_substitute/static/src/js/action_manager.js
  4. 8
      report_substitute/views/assets_backend.xml

1
report_substitute/__manifest__.py

@ -14,6 +14,7 @@
'depends': ['base'],
'data': [
'security/ir_actions_report_substitution_rule.xml',
'views/assets_backend.xml',
'views/ir_actions_report.xml',
],
'demo': ['demo/action_report.xml'],

17
report_substitute/models/ir_actions_report.py

@ -25,11 +25,22 @@ class IrActionReport(models.Model):
domain = safe_eval(substitution_report_rule.domain)
domain.append(('id', 'in', active_ids))
if set(model.search(domain).ids) == set(active_ids):
return (
substitution_report_rule.substitution_action_report_id
)
return substitution_report_rule.substitution_action_report_id
return False
@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'])
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
@api.multi
def render(self, res_ids, data=None):
substitution_report = self._get_substitution_report(

35
report_substitute/static/src/js/action_manager.js

@ -0,0 +1,35 @@
// Copyright 2019 ACSONE SA/NV
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
odoo.define('report_substitute.action_report_substitute', function(require) {
"use strict";
var ActionManager = require('web.ActionManager');
ActionManager.include({
/**
* Intercept action handling substitute the report action
* @override
*/
_handleAction: function(action, options) {
if (action.type === 'ir.actions.report' &&
action.context.active_ids) {
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',
args: [action, active_ids]
}).then(function(action_id) {
callersArguments[0] = action_id
return _super.apply(self, callersArguments);
});
}
return this._super.apply(this, arguments);
},
});
});

8
report_substitute/views/assets_backend.xml

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<template id="assets_backend" name="report assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/report_substitute/static/src/js/action_manager.js"></script>
</xpath>
</template>
</openerp>
Loading…
Cancel
Save