Skip to content

Commit 85bb60b

Browse files
committed
[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
1 parent fe3537b commit 85bb60b

25 files changed

+217
-189
lines changed

report_label/__manifest__.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
22
{
33
"name": "Report Labels",
4-
"version": "14.0.1.0.0",
4+
"version": "16.0.1.0.0",
55
"summary": "Print configurable self-adhesive labels reports",
66
"author": "Iván Todorovich, Moka Tourisme, Odoo Community Association (OCA)",
77
"website": "https://github.com/OCA/reporting-engine",
@@ -13,7 +13,6 @@
1313
],
1414
"data": [
1515
"security/ir.model.access.csv",
16-
"data/paperformat_label.xml",
1716
"views/ir_actions_server.xml",
1817
"views/report_paperformat_label.xml",
1918
"reports/report_label.xml",

report_label/data/paperformat_label.xml

-27
This file was deleted.

report_label/demo/demo.xml

+26-5
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,36 @@
88
/>
99
</template>
1010

11+
<record id="report_paperformat_partner_address" model="report.paperformat">
12+
<field name="name">Paperformat for labels (A4: 210mm x 297mm)</field>
13+
<field name="format">A4</field>
14+
<field name="dpi">96</field>
15+
<field name="orientation">Portrait</field>
16+
<field name="margin_top">0</field>
17+
<field name="margin_bottom">0</field>
18+
<field name="margin_right">0</field>
19+
<field name="margin_left">0</field>
20+
<field name="header_spacing">0</field>
21+
<field name="disable_shrinking" eval="True" />
22+
</record>
23+
1124
<record
1225
id="report_paperformat_label_partner_address"
1326
model="report.paperformat.label"
1427
>
15-
<field name="name">Partner Label</field>
16-
<field name="format">A4</field>
17-
<field name="label_height" eval="42.3" />
18-
<field name="label_width" eval="60" />
28+
<field name="name">Partner Labels (3 x 6 = 18 labels per sheet)</field>
29+
<field name="paperformat_id" ref="report_paperformat_partner_address" />
30+
<field name="label_height" eval="49.5" />
31+
<field name="label_width" eval="70" />
1932
<field name="label_padding_top" eval="5" />
2033
<field name="label_padding_right" eval="5" />
2134
<field name="label_padding_bottom" eval="5" />
2235
<field name="label_padding_left" eval="5" />
36+
<field name="label_margin_top" eval="0" />
37+
<field name="label_margin_right" eval="0" />
38+
<field name="label_margin_bottom" eval="0" />
39+
<field name="label_margin_left" eval="0" />
40+
<field name="label_background_color">#729fcf</field>
2341
</record>
2442

2543
<record id="actions_server_label_partner_address" model="ir.actions.server">
@@ -30,7 +48,10 @@
3048
name="label_paperformat_id"
3149
ref="report_paperformat_label_partner_address"
3250
/>
33-
<field name="label_template">report_label.label_template_partner_address</field>
51+
<field
52+
name="label_template_view_id"
53+
ref="report_label.label_template_partner_address"
54+
/>
3455
</record>
3556

3657
<!-- Create context action -->

report_label/i18n/report_label.pot

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Translation of Odoo Server.
22
# This file contains the translation of the following modules:
3-
# * report_label
3+
# * report_label
44
#
55
msgid ""
66
msgstr ""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
2+
3+
from openupgradelib import openupgrade
4+
5+
from odoo.tools.sql import column_exists
6+
7+
8+
@openupgrade.migrate()
9+
def migrate(env, version):
10+
if not column_exists(env.cr, "base_comment_template", "models"):
11+
openupgrade.logged_query(
12+
env.cr,
13+
"ALTER TABLE report_paperformat_label ADD COLUMN name char",
14+
)
15+
openupgrade.logged_query(
16+
env.cr,
17+
"""
18+
UPDATE report_paperformat_label rpfl
19+
SET name = rpf.name
20+
FROM report_paperformat rpf
21+
WHERE rpfl.name is null
22+
AND rpfl.paperformat_id = rpf.id;
23+
""",
24+
)
25+
26+
if not column_exists(env.cr, "ir_act_server", "label_template_view_id"):
27+
openupgrade.logged_query(
28+
env.cr,
29+
"ALTER TABLE ir_act_server ADD COLUMN label_template_view_id integer;",
30+
)
31+
openupgrade.logged_query(
32+
env.cr,
33+
"""
34+
UPDATE ir_act_server ias
35+
SET label_template_view_id = iuv.id
36+
FROM ir_ui_view iuv
37+
WHERE ias.label_template is not null
38+
AND iuv.key = ias.label_template;
39+
""",
40+
)

report_label/models/ir_actions_server.py

+5-18
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ class IrActionsServer(models.Model):
99
selection_add=[("report_label", "Print self-adhesive labels")],
1010
ondelete={"report_label": "cascade"},
1111
)
12-
label_template = fields.Char(
13-
"Label QWeb Template",
12+
label_template_view_id = fields.Many2one(
13+
string="Label QWeb Template",
14+
comodel_name="ir.ui.view",
15+
domain=[("type", "=", "qweb")],
1416
help="The QWeb template key to render the labels",
1517
states={"report_label": [("required", True)]},
1618
)
@@ -20,27 +22,12 @@ class IrActionsServer(models.Model):
2022
states={"report_label": [("required", True)]},
2123
)
2224

23-
def report_label_associated_view(self):
24-
"""View the associated qweb templates"""
25-
self.ensure_one()
26-
action = self.env.ref("base.action_ui_view", raise_if_not_found=False)
27-
if not action or len(self.label_template.split(".")) < 2:
28-
return False
29-
res = action.read()[0]
30-
res["domain"] = [
31-
("type", "=", "qweb"),
32-
"|",
33-
("name", "ilike", self.label_template.split(".")[1]),
34-
("key", "=", self.label_template),
35-
]
36-
return res
37-
3825
def _run_action_report_label_multi(self, eval_context=None):
3926
"""Show report label wizard"""
4027
context = dict(self.env.context)
4128
context.update(
4229
{
43-
"label_template": self.label_template,
30+
"label_template_view_id": self.label_template_view_id.id,
4431
"label_paperformat_id": self.label_paperformat_id.id,
4532
"res_model_id": self.model_id.id,
4633
}

report_label/models/report_paperformat_label.py

+3-7
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33

44
class ReportPaperformatLabel(models.Model):
55
_name = "report.paperformat.label"
6-
_inherits = {"report.paperformat": "paperformat_id"}
76
_description = "Label Paper Format"
87

8+
name = fields.Char(required=True)
9+
910
paperformat_id = fields.Many2one(
1011
"report.paperformat",
1112
string="Paper Format",
@@ -22,6 +23,7 @@ class ReportPaperformatLabel(models.Model):
2223
default=42.3,
2324
required=True,
2425
)
26+
label_background_color = fields.Char(default="#FFFFFF")
2527
label_padding_top = fields.Float("Label Padding Top (mm)", default=2)
2628
label_padding_right = fields.Float("Label Padding Right (mm)", default=2)
2729
label_padding_bottom = fields.Float("Label Padding Bottom (mm)", default=2)
@@ -30,9 +32,3 @@ class ReportPaperformatLabel(models.Model):
3032
label_margin_right = fields.Float("Label Margin Right (mm)", default=2)
3133
label_margin_bottom = fields.Float("Label Margin Bottom (mm)", default=2)
3234
label_margin_left = fields.Float("Label Margin Left (mm)", default=2)
33-
34-
# Overload inherits defaults
35-
orientation = fields.Selection(inherited=True, default="Portrait")
36-
header_spacing = fields.Integer(inherited=True, default=0)
37-
margin_top = fields.Float(inherited=True, default=7)
38-
margin_bottom = fields.Float(inherited=True, default=7)

report_label/readme/CONFIGURE.rst

+24-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,27 @@
1-
Go to **Settings > Technical > Analysis > Label Paper Format** and create
2-
your self-adhesive label paper formats.
1+
**Configure your Report Label Paperformat**
32

4-
.. image:: ../static/description/configure_paperformat.png
3+
* Go to "Settings > Technical > Reporting > Label Paper Format"
54

6-
Go to **Settings > Technical > Analysis > Label Report** and create your label
7-
report, and its context action. You'll also need to create or reuse a
8-
QWeb template for you label.
5+
* Create your self-adhesive label paper formats.
96

10-
.. image:: ../static/description/configure_report_label.png
7+
You should reuse or create a Paperformat.
8+
9+
.. image:: ../static/description/report_paperformat_label_form.png
10+
11+
**Configure your Server action**
12+
13+
* Go to "Settings > Technical > Actions > Server Actions"
14+
15+
Create your label report :
16+
17+
* In the 'Action to do' field, select 'Print Self-adhesive Labels'
18+
19+
* In the 'Label Paper Format' field, select your label paper format previously created
20+
21+
* In the 'Label Qweb Template' create or reuse a QWeb template for your label.
22+
23+
.. image:: ../static/description/ir_actions_server.png
24+
25+
**Importante Note**
26+
27+
`By design <https://github.com/OCA/reporting-engine/blob/14.0/report_label/reports/report_label.xml#L34>`_, the variable used in this QWeb template must be named `record`.

report_label/readme/ROADMAP.rst

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
Known issues:
22

3-
* `wkhtmltopdf` doesn't always respect dpi, and mm measures don't match. For
4-
this matter, it's recommended to use this module along with
5-
`report_wkhtmltopdf_param` and enable `--disable-smart-shrinking`.
6-
73
* This module depends on `base_automation` only because this module extends
84
`ir.actions.server` with a new kind of action, and `base.automation` inherits
95
from `ir.actions.server` by delegation in such a way that the modules cannot
106
be loaded in another order.
7+
To do when migrating in version > 16 :
8+
1. remove ``base_automation`` dependency
9+
2. install ``report_label``
10+
3. install then ``base_automation``.
11+
If the installation of ``base_automation`` works, the dependency can be
12+
replaced by ``base``.

report_label/readme/USAGE.rst

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
1. In the target model's tree view, select the records to print.
2-
2. Click *Action* and your label report action name.
3-
3. Select the number of labels per record to print, and click Print.
1+
* In the target model's tree view, select the records to print.
2+
* Click *Action* and your label report action name.
3+
* Select the number of labels per record to print, and click Print.
44

5-
.. image:: ../static/description/label_wizard.png
5+
you can optionaly define an offset
6+
7+
.. image:: ../static/description/report_label_wizard_form.png
8+
9+
The items will be printed in a pdf document.
10+
11+
.. image:: ../static/description/report_result.png

report_label/reports/report_label.xml

+30-22
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,41 @@
22
<odoo>
33

44
<template id="report_label_template">
5-
<t t-call="web.basic_layout">
6-
<t t-set="full_width" t-value="True" />
7-
<t t-set="label_style">
8-
height: <t t-esc="label_format['label_height']" />mm;
9-
width: <t t-esc="label_format['label_width']" />mm;
10-
padding-top: <t t-esc="label_format['label_padding_top']" />mm;
11-
padding-right: <t t-esc="label_format['label_padding_right']" />mm;
12-
padding-bottom: <t t-esc="label_format['label_padding_bottom']" />mm;
13-
padding-left: <t t-esc="label_format['label_padding_left']" />mm;
14-
margin-top: <t t-esc="label_format['label_margin_top']" />mm;
15-
margin-right: <t t-esc="label_format['label_margin_right']" />mm;
16-
margin-bottom: <t t-esc="label_format['label_margin_bottom']" />mm;
17-
margin-left: <t t-esc="label_format['label_margin_left']" />mm;
18-
display: inline-block;
19-
overflow: hidden;
20-
float: left;
21-
position: relative;
22-
page-break-inside: avoid;
23-
box-sizing: border-box;
24-
</t>
5+
6+
<t t-call="web.report_layout">
7+
<style type="text/css">
8+
html, body {
9+
margin: 0px;
10+
padding: 0px;
11+
}
12+
.label_style {
13+
height: <t t-esc="label_format['label_height']" />mm;
14+
width: <t t-esc="label_format['label_width']" />mm;
15+
padding-top: <t t-esc="label_format['label_padding_top']" />mm;
16+
padding-right: <t t-esc="label_format['label_padding_right']" />mm;
17+
padding-bottom: <t t-esc="label_format['label_padding_bottom']" />mm;
18+
padding-left: <t t-esc="label_format['label_padding_left']" />mm;
19+
margin-top: <t t-esc="label_format['label_margin_top']" />mm;
20+
margin-right: <t t-esc="label_format['label_margin_right']" />mm;
21+
margin-bottom: <t t-esc="label_format['label_margin_bottom']" />mm;
22+
margin-left: <t t-esc="label_format['label_margin_left']" />mm;
23+
background-color: <t t-esc="label_format['label_background_color']" />;
24+
display: inline-block;
25+
overflow: hidden;
26+
float: left;
27+
position: relative;
28+
page-break-inside: avoid;
29+
box-sizing: border-box;
30+
}
31+
</style>
32+
2533
<!-- Offset: Skip the first [offset] labels -->
2634
<t t-foreach="range(0, offset)" t-as="i">
27-
<div t-att-style="label_style" />
35+
<div class="label_style" />
2836
</t>
2937
<t t-foreach="lines" t-as="line">
3038
<t t-foreach="range(0, line['quantity'])" t-as="i">
31-
<div t-att-style="label_style">
39+
<div class="label_style">
3240
<t t-call="{{label_template}}">
3341
<t
3442
t-set="record"
Binary file not shown.
Binary file not shown.
Loading
-21.9 KB
Binary file not shown.
Loading
Loading
Loading

report_label/tests/test_report_label.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ def test_01_print_partner_label(self):
2222
"discard_logo_check": True,
2323
}
2424
)
25-
wizard = self.env[model].with_context(context).create({})
25+
wizard = self.env[model].with_context(**context).create({})
2626
report_action = wizard.print_report()
2727
self.assertEqual(report_action["type"], "ir.actions.report")

0 commit comments

Comments
 (0)