[ADD] report_label

This commit is contained in:
Ivàn Todorovich
2020-11-19 10:34:23 -03:00
committed by Stefan Rijnhart
parent 1b1e9a4d9f
commit c6f34b6609
25 changed files with 549 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
from . import report_paperformat_label
from . import ir_actions_server
from . import ir_actions_report

View File

@@ -0,0 +1,14 @@
from odoo import api, models
class IrActionsReport(models.Model):
_inherit = "ir.actions.report"
@api.model
def get_paperformat(self):
# Allow to define paperformat via context
res = super().get_paperformat()
if self.env.context.get("paperformat_id"):
res = self.env["report.paperformat"].browse(
self.env.context.get("paperformat_id"))
return res

View File

@@ -0,0 +1,57 @@
from odoo import api, models, fields
class IrActionsServer(models.Model):
_inherit = "ir.actions.server"
state = fields.Selection(
selection_add=[("report_label", "Print self-adhesive labels")]
)
label_template = fields.Char(
"Label QWeb Template",
help="The QWeb template key to render the labels",
states={
"report_label": [("required", True)]
}
)
label_paperformat_id = fields.Many2one(
"report.paperformat.label",
"Label Paper Format",
states={
"report_label": [("required", True)]
}
)
@api.multi
def report_label_associated_view(self):
""" View the associated qweb templates """
self.ensure_one()
action = self.env.ref('base.action_ui_view', raise_if_not_found=False)
if not action or len(self.label_template.split('.')) < 2:
return False
res = action.read()[0]
res['domain'] = [
('type', '=', 'qweb'),
'|',
('name', 'ilike', self.label_template.split('.')[1]),
('key', '=', self.label_template),
]
return res
@api.model
def run_action_report_label_multi(self, action, eval_context=None):
""" Show report label wizard """
context = dict(self.env.context)
context.update({
"label_template": action.label_template,
"label_paperformat_id": action.label_paperformat_id.id,
"res_model_id": action.model_id.id,
})
return {
"name": action.name,
"type": "ir.actions.act_window",
"res_model": "report.label.wizard",
"context": str(context),
"view_mode": "form",
"target": "new",
}

View File

@@ -0,0 +1,38 @@
from odoo import models, fields
class ReportPaperformatLabel(models.Model):
_name = "report.paperformat.label"
_inherits = {"report.paperformat": "paperformat_id"}
_description = "Label Paper Format"
paperformat_id = fields.Many2one(
"report.paperformat",
string="Paper Format",
required=True,
ondelete="cascade",
)
label_width = fields.Float(
"Label Width (mm)",
default=60,
required=True,
)
label_height = fields.Float(
"Label Height (mm)",
default=42.3,
required=True,
)
label_padding_top = fields.Float("Label Padding Top (mm)", default=2)
label_padding_right = fields.Float("Label Padding Right (mm)", default=2)
label_padding_bottom = fields.Float("Label Padding Bottom (mm)", default=2)
label_padding_left = fields.Float("Label Padding Left (mm)", default=2)
label_margin_top = fields.Float("Label Margin Top (mm)", default=2)
label_margin_right = fields.Float("Label Margin Right (mm)", default=2)
label_margin_bottom = fields.Float("Label Margin Bottom (mm)", default=2)
label_margin_left = fields.Float("Label Margin Left (mm)", default=2)
# Overload inherits defaults
orientation = fields.Selection(inherited=True, default="Portrait")
header_spacing = fields.Integer(inherited=True, default=0)
margin_top = fields.Float(inherited=True, default=7)
margin_bottom = fields.Float(inherited=True, default=7)