|
| 1 | +from odoo import api, models, fields |
| 2 | + |
| 3 | + |
| 4 | +class IrActionsServer(models.Model): |
| 5 | + _inherit = "ir.actions.server" |
| 6 | + |
| 7 | + state = fields.Selection( |
| 8 | + selection_add=[("report_label", "Print self-adhesive labels")] |
| 9 | + ) |
| 10 | + label_template = fields.Char( |
| 11 | + "Label QWeb Template", |
| 12 | + help="The QWeb template key to render the labels", |
| 13 | + states={ |
| 14 | + "report_label": [("required", True)] |
| 15 | + } |
| 16 | + ) |
| 17 | + label_paperformat_id = fields.Many2one( |
| 18 | + "report.paperformat.label", |
| 19 | + "Label Paper Format", |
| 20 | + states={ |
| 21 | + "report_label": [("required", True)] |
| 22 | + } |
| 23 | + ) |
| 24 | + |
| 25 | + @api.multi |
| 26 | + def report_label_associated_view(self): |
| 27 | + """ View the associated qweb templates """ |
| 28 | + self.ensure_one() |
| 29 | + action = self.env.ref('base.action_ui_view', raise_if_not_found=False) |
| 30 | + if not action or len(self.label_template.split('.')) < 2: |
| 31 | + return False |
| 32 | + res = action.read()[0] |
| 33 | + res['domain'] = [ |
| 34 | + ('type', '=', 'qweb'), |
| 35 | + '|', |
| 36 | + ('name', 'ilike', self.label_template.split('.')[1]), |
| 37 | + ('key', '=', self.label_template), |
| 38 | + ] |
| 39 | + return res |
| 40 | + |
| 41 | + @api.model |
| 42 | + def run_action_report_label_multi(self, action, eval_context=None): |
| 43 | + """ Show report label wizard """ |
| 44 | + context = dict(self.env.context) |
| 45 | + context.update({ |
| 46 | + "label_template": action.label_template, |
| 47 | + "label_paperformat_id": action.label_paperformat_id.id, |
| 48 | + "res_model_id": action.model_id.id, |
| 49 | + }) |
| 50 | + return { |
| 51 | + "name": action.name, |
| 52 | + "type": "ir.actions.act_window", |
| 53 | + "res_model": "report.label.wizard", |
| 54 | + "context": str(context), |
| 55 | + "view_mode": "form", |
| 56 | + "target": "new", |
| 57 | + } |
0 commit comments