| 1 |
import { rpc } from "@web/core/network/rpc"; |
| 2 |
import { registry } from "@web/core/registry"; |
| 3 |
import { user } from "@web/core/user"; |
| 4 |
import { downloadReport } from "@web/webclient/actions/reports/utils"; |
| 5 |
|
| 6 |
export const reportService = { |
| 7 |
dependencies: ["ui", "orm", "pos"], |
| 8 |
start(env, { ui, orm, pos }) { |
| 9 |
const reportActionsCache = {}; |
| 10 |
return { |
| 11 |
async doAction(reportXmlId, active_ids) { |
| 12 |
ui.block(); |
| 13 |
try { |
| 14 |
reportActionsCache[reportXmlId] ||= rpc("/web/action/load", { |
| 15 |
action_id: reportXmlId, |
| 16 |
}); |
| 17 |
const reportAction = await reportActionsCache[reportXmlId]; |
| 18 |
// await instead of return because we want the ui to stay blocked |
| 19 |
await downloadReport( |
| 20 |
rpc, |
| 21 |
{ ...reportAction, context: { active_ids } }, |
| 22 |
"pdf", |
| 23 |
user.context |
| 24 |
); |
| 25 |
} finally { |
| 26 |
ui.unblock(); |
| 27 |
} |
| 28 |
}, |
| 29 |
}; |
| 30 |
}, |
| 31 |
}; |
| 32 |
|
| 33 |
registry.category("services").add("report", reportService); |