[MIG] report_label

[IMP] allow to create report.paperformat.label without creating each time report.paperformat item
[FIX] Remove useless data that are specific Label: Agipa 114016
[REF] simplify UI, removing custom entry for ir.actions.server
[ADD] migration script to migrate name field
[IMP] Add label_background_color to allow to easily define background-color for label. (That can be usefull to debug label positions)
[DOC] update screenshots to new V16 versions
[IMP] Set body and html margin to 0 to to able to be predictive when designing a label sheet
[IMP] replace style by class in the label template, reducing the size of the html code generated.
[IMP] replace label_template by label_template_view_id on the ir.actions.server model, removing useless xml and python code. (provide migration scripts)
[REF] Split wizard file into wizard and wizard line file, following OCA guidelines
This commit is contained in:
Sylvain LE GAL
2023-01-03 11:17:16 +01:00
parent fe3537b11b
commit 85bb60b356
25 changed files with 217 additions and 189 deletions

View File

@@ -1 +1,2 @@
from . import report_label_wizard
from . import report_label_wizard_line

View File

@@ -38,11 +38,13 @@ class ReportLabelWizard(models.TransientModel):
required=True,
default=lambda self: self.env.context.get("label_paperformat_id"),
)
label_template = fields.Char(
"Label QWeb Template",
label_template_view_id = fields.Many2one(
string="Label QWeb Template",
comodel_name="ir.ui.view",
readonly=True,
required=True,
default=lambda self: self.env.context.get("label_template"),
default=lambda self: self.env.context.get("label_template_view_id"),
)
offset = fields.Integer(
help="Number of labels to skip when printing",
@@ -59,7 +61,7 @@ class ReportLabelWizard(models.TransientModel):
self.ensure_one()
return {
"label_format": self.label_paperformat_id.read()[0],
"label_template": self.label_template,
"label_template": self.label_template_view_id.key,
"offset": self.offset,
"res_model": self.model_id.model,
"lines": [
@@ -79,30 +81,3 @@ class ReportLabelWizard(models.TransientModel):
"paperformat_id": self.label_paperformat_id.paperformat_id.id,
}
return action
class ReportLabelWizardLine(models.TransientModel):
_name = "report.label.wizard.line"
_description = "Report Label Wizard Line"
_order = "sequence"
wizard_id = fields.Many2one(
"report.label.wizard",
"Wizard",
required=True,
ondelete="cascade",
)
sequence = fields.Integer(default=10)
res_id = fields.Integer("Resource ID", required=True)
res_name = fields.Char(compute="_compute_res_name")
quantity = fields.Integer(default=1, required=True)
@api.depends("wizard_id.model_id", "res_id")
def _compute_res_name(self):
wizard = self.mapped("wizard_id")
wizard.ensure_one()
res_model = wizard.model_id.model
res_ids = self.mapped("res_id")
names_map = dict(self.env[res_model].browse(res_ids).name_get())
for rec in self:
rec.res_name = names_map.get(rec.res_id)

View File

@@ -21,7 +21,7 @@
<field name="offset" />
<field name="model_id" invisible="1" />
<field name="label_paperformat_id" />
<field name="label_template" invisible="1" />
<field name="label_template_view_id" invisible="1" />
</group>
</group>
</sheet>

View File

@@ -0,0 +1,29 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
class ReportLabelWizardLine(models.TransientModel):
_name = "report.label.wizard.line"
_description = "Report Label Wizard Line"
_order = "sequence"
wizard_id = fields.Many2one(
"report.label.wizard",
"Wizard",
required=True,
ondelete="cascade",
)
sequence = fields.Integer(default=10)
res_id = fields.Integer("Resource ID", required=True)
res_name = fields.Char(compute="_compute_res_name")
quantity = fields.Integer(default=1, required=True)
@api.depends("wizard_id.model_id", "res_id")
def _compute_res_name(self):
wizard = self.mapped("wizard_id")
wizard.ensure_one()
res_model = wizard.model_id.model
res_ids = self.mapped("res_id")
names_map = dict(self.env[res_model].browse(res_ids).name_get())
for rec in self:
rec.res_name = names_map.get(rec.res_id)