[IMP] report_label: black, isort, prettier

This commit is contained in:
Stefan Rijnhart
2021-04-20 15:20:22 +02:00
parent 7605b7c15e
commit c6c0ef3fd4
17 changed files with 167 additions and 131 deletions

View File

@@ -1,26 +1,24 @@
{ {
'name': 'Report Labels', "name": "Report Labels",
'version': '12.0.1.0.0', "version": "12.0.1.0.0",
'summary': 'Print configurable self-adhesive labels reports', "summary": "Print configurable self-adhesive labels reports",
'author': 'Iván Todorovich, Moka Tourisme, Odoo Community Association (OCA)', "author": "Iván Todorovich, Moka Tourisme, Odoo Community Association (OCA)",
'website': 'https://github.com/OCA/reporting-engine', "website": "https://github.com/OCA/reporting-engine",
'license': 'AGPL-3', "license": "AGPL-3",
'category': 'Reporting', "category": "Reporting",
'maintainers': [ "maintainers": ["ivantodorovich"],
'ivantodorovich' "depends": [
"base",
], ],
'depends': [ "data": [
'base', "security/ir.model.access.csv",
"data/paperformat_label.xml",
"views/ir_actions_server.xml",
"views/report_paperformat_label.xml",
"reports/report_label.xml",
"wizards/report_label_wizard.xml",
], ],
'data': [ "demo": [
'security/ir.model.access.csv', "demo/demo.xml",
'data/paperformat_label.xml',
'views/ir_actions_server.xml',
'views/report_paperformat_label.xml',
'reports/report_label.xml',
'wizards/report_label_wizard.xml',
], ],
'demo': [
'demo/demo.xml',
]
} }

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8" ?>
<odoo> <odoo>
<data noupdate="1"> <data noupdate="1">
@@ -6,21 +6,21 @@
<field name="name">Label: Agipa 114016</field> <field name="name">Label: Agipa 114016</field>
<field name="format">A5</field> <field name="format">A5</field>
<field name="orientation">Portrait</field> <field name="orientation">Portrait</field>
<field name="margin_top" eval="5"/> <field name="margin_top" eval="5" />
<field name="margin_right" eval="13"/> <field name="margin_right" eval="13" />
<field name="margin_bottom" eval="0"/> <field name="margin_bottom" eval="0" />
<field name="margin_left" eval="13"/> <field name="margin_left" eval="13" />
<field name="dpi" eval="82"/> <field name="dpi" eval="82" />
<field name="label_width" eval="38"/> <field name="label_width" eval="38" />
<field name="label_height" eval="19"/> <field name="label_height" eval="19" />
<field name="label_padding_top" eval="1"/> <field name="label_padding_top" eval="1" />
<field name="label_padding_right" eval="1"/> <field name="label_padding_right" eval="1" />
<field name="label_padding_bottom" eval="1"/> <field name="label_padding_bottom" eval="1" />
<field name="label_padding_left" eval="1"/> <field name="label_padding_left" eval="1" />
<field name="label_margin_top" eval="1"/> <field name="label_margin_top" eval="1" />
<field name="label_margin_right" eval="1"/> <field name="label_margin_right" eval="1" />
<field name="label_margin_bottom" eval="1"/> <field name="label_margin_bottom" eval="1" />
<field name="label_margin_left" eval="1"/> <field name="label_margin_left" eval="1" />
</record> </record>
</data> </data>

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8" ?>
<odoo> <odoo>
<template id="label_template_partner_address" name="Partner Label: Address"> <template id="label_template_partner_address" name="Partner Label: Address">
@@ -8,26 +8,36 @@
/> />
</template> </template>
<record id="report_paperformat_label_partner_address" model="report.paperformat.label"> <record
id="report_paperformat_label_partner_address"
model="report.paperformat.label"
>
<field name="name">Partner Label</field> <field name="name">Partner Label</field>
<field name="format">A4</field> <field name="format">A4</field>
<field name="label_height" eval="42.3"/> <field name="label_height" eval="42.3" />
<field name="label_width" eval="60"/> <field name="label_width" eval="60" />
<field name="label_padding_top" eval="5"/> <field name="label_padding_top" eval="5" />
<field name="label_padding_right" eval="5"/> <field name="label_padding_right" eval="5" />
<field name="label_padding_bottom" eval="5"/> <field name="label_padding_bottom" eval="5" />
<field name="label_padding_left" eval="5"/> <field name="label_padding_left" eval="5" />
</record> </record>
<record id="actions_server_label_partner_address" model="ir.actions.server"> <record id="actions_server_label_partner_address" model="ir.actions.server">
<field name="name">Print Address Labels</field> <field name="name">Print Address Labels</field>
<field name="state">report_label</field> <field name="state">report_label</field>
<field name="model_id" ref="base.model_res_partner"/> <field name="model_id" ref="base.model_res_partner" />
<field name="label_paperformat_id" ref="report_paperformat_label_partner_address"/> <field
name="label_paperformat_id"
ref="report_paperformat_label_partner_address"
/>
<field name="label_template">report_label.label_template_partner_address</field> <field name="label_template">report_label.label_template_partner_address</field>
</record> </record>
<!-- Create context action --> <!-- Create context action -->
<function model="ir.actions.server" eval="[ref('actions_server_label_partner_address')]" name="create_action"/> <function
model="ir.actions.server"
eval="[ref('actions_server_label_partner_address')]"
name="create_action"
/>
</odoo> </odoo>

View File

@@ -10,5 +10,6 @@ class IrActionsReport(models.Model):
res = super().get_paperformat() res = super().get_paperformat()
if self.env.context.get("paperformat_id"): if self.env.context.get("paperformat_id"):
res = self.env["report.paperformat"].browse( res = self.env["report.paperformat"].browse(
self.env.context.get("paperformat_id")) self.env.context.get("paperformat_id")
)
return res return res

View File

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

View File

@@ -1,4 +1,4 @@
from odoo import models, fields from odoo import fields, models
class ReportPaperformatLabel(models.Model): class ReportPaperformatLabel(models.Model):

View File

@@ -1 +1 @@
This module allows you to create self-adhesive label printing actions on any model. This module allows you to create self-adhesive label printing actions on any model.

View File

@@ -1,3 +1,3 @@
* `wkhtmltopdf` doesn't always respect dpi, and mm measures don't match. For * `wkhtmltopdf` doesn't always respect dpi, and mm measures don't match. For
this matter, it's recommended to use this module along with this matter, it's recommended to use this module along with
`report_wkhtmltopdf_param` and enable `--disable-smart-shrinking`. `report_wkhtmltopdf_param` and enable `--disable-smart-shrinking`.

View File

@@ -2,4 +2,4 @@
2. Click *Action* and your label report action name. 2. Click *Action* and your label report action name.
3. Select the number of labels per record to print, and click Print. 3. Select the number of labels per record to print, and click Print.
.. image:: ../static/description/label_wizard.png .. image:: ../static/description/label_wizard.png

View File

@@ -1,20 +1,20 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8" ?>
<odoo> <odoo>
<template id="report_label_template"> <template id="report_label_template">
<t t-call="web.basic_layout"> <t t-call="web.basic_layout">
<t t-set="full_width" t-value="True"/> <t t-set="full_width" t-value="True" />
<t t-set="label_style"> <t t-set="label_style">
height: <t t-esc="label_format['label_height']"/>mm; height: <t t-esc="label_format['label_height']" />mm;
width: <t t-esc="label_format['label_width']"/>mm; width: <t t-esc="label_format['label_width']" />mm;
padding-top: <t t-esc="label_format['label_padding_top']"/>mm; padding-top: <t t-esc="label_format['label_padding_top']" />mm;
padding-right: <t t-esc="label_format['label_padding_right']"/>mm; padding-right: <t t-esc="label_format['label_padding_right']" />mm;
padding-bottom: <t t-esc="label_format['label_padding_bottom']"/>mm; padding-bottom: <t t-esc="label_format['label_padding_bottom']" />mm;
padding-left: <t t-esc="label_format['label_padding_left']"/>mm; padding-left: <t t-esc="label_format['label_padding_left']" />mm;
margin-top: <t t-esc="label_format['label_margin_top']"/>mm; margin-top: <t t-esc="label_format['label_margin_top']" />mm;
margin-right: <t t-esc="label_format['label_margin_right']"/>mm; margin-right: <t t-esc="label_format['label_margin_right']" />mm;
margin-bottom: <t t-esc="label_format['label_margin_bottom']"/>mm; margin-bottom: <t t-esc="label_format['label_margin_bottom']" />mm;
margin-left: <t t-esc="label_format['label_margin_left']"/>mm; margin-left: <t t-esc="label_format['label_margin_left']" />mm;
display: inline-block; display: inline-block;
overflow: hidden; overflow: hidden;
float: left; float: left;
@@ -24,13 +24,16 @@
</t> </t>
<!-- Offset: Skip the first [offset] labels --> <!-- Offset: Skip the first [offset] labels -->
<t t-foreach="range(0, offset)" t-as="i"> <t t-foreach="range(0, offset)" t-as="i">
<div t-att-style="label_style"></div> <div t-att-style="label_style" />
</t> </t>
<t t-foreach="lines" t-as="line"> <t t-foreach="lines" t-as="line">
<t t-foreach="range(0, line['quantity'])" t-as="i"> <t t-foreach="range(0, line['quantity'])" t-as="i">
<div t-att-style="label_style"> <div t-att-style="label_style">
<t t-call="{{label_template}}"> <t t-call="{{label_template}}">
<t t-set="record" t-value="docs.env[res_model].browse(line['res_id'])"/> <t
t-set="record"
t-value="docs.env[res_model].browse(line['res_id'])"
/>
</t> </t>
</div> </div>
</t> </t>

View File

@@ -1,13 +1,14 @@
from odoo.tests import common
from ast import literal_eval from ast import literal_eval
from odoo.tests import common
class TestReportLabel(common.TransactionCase): class TestReportLabel(common.TransactionCase):
def setUp(self): def setUp(self):
super().setUp() super().setUp()
self.partner_label = self.env.ref( self.partner_label = self.env.ref(
"report_label.actions_server_label_partner_address") "report_label.actions_server_label_partner_address"
)
def test_01_print_partner_label(self): def test_01_print_partner_label(self):
self.partner_label.create_action() self.partner_label.create_action()

View File

@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8" ?>
<odoo> <odoo>
<record id="view_server_action_form" model="ir.ui.view"> <record id="view_server_action_form" model="ir.ui.view">
<field name="model">ir.actions.server</field> <field name="model">ir.actions.server</field>
<field name="inherit_id" ref="base.view_server_action_form"/> <field name="inherit_id" ref="base.view_server_action_form" />
<field name="arch" type="xml"> <field name="arch" type="xml">
<header position="inside"> <header position="inside">
<button <button
@@ -15,8 +15,14 @@
/> />
</header> </header>
<field name="type" position="after"> <field name="type" position="after">
<field name="label_paperformat_id" attrs="{'invisible': [('state', '!=', 'report_label')]}"/> <field
<field name="label_template" attrs="{'invisible': [('state', '!=', 'report_label')]}"/> name="label_paperformat_id"
attrs="{'invisible': [('state', '!=', 'report_label')]}"
/>
<field
name="label_template"
attrs="{'invisible': [('state', '!=', 'report_label')]}"
/>
</field> </field>
</field> </field>
</record> </record>
@@ -35,6 +41,7 @@
name="Label Reports" name="Label Reports"
action="report_label_action" action="report_label_action"
parent="base.reporting_menuitem" parent="base.reporting_menuitem"
sequence="3"/> sequence="3"
/>
</odoo> </odoo>

View File

@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8" ?>
<odoo> <odoo>
<record id="paperformat_label_view_form" model="ir.ui.view"> <record id="paperformat_label_view_form" model="ir.ui.view">
<field name="model">report.paperformat.label</field> <field name="model">report.paperformat.label</field>
<field name="inherit_id" ref="base.paperformat_view_form"/> <field name="inherit_id" ref="base.paperformat_view_form" />
<field name="mode">primary</field> <field name="mode">primary</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<!-- Hide irrelevant fields --> <!-- Hide irrelevant fields -->
@@ -20,20 +20,20 @@
<form position="inside"> <form position="inside">
<group name="label"> <group name="label">
<group name="label_size" string="Label Size" colspan="2"> <group name="label_size" string="Label Size" colspan="2">
<field name="label_height"/> <field name="label_height" />
<field name="label_width"/> <field name="label_width" />
</group> </group>
<group name="label_padding" string="Label Padding"> <group name="label_padding" string="Label Padding">
<field string="Top (mm)" name="label_padding_top"/> <field string="Top (mm)" name="label_padding_top" />
<field string="Right (mm)" name="label_padding_right"/> <field string="Right (mm)" name="label_padding_right" />
<field string="Bottom (mm)" name="label_padding_bottom"/> <field string="Bottom (mm)" name="label_padding_bottom" />
<field string="Left (mm)" name="label_padding_left"/> <field string="Left (mm)" name="label_padding_left" />
</group> </group>
<group name="label_margin" string="Label Margin"> <group name="label_margin" string="Label Margin">
<field string="Top (mm)" name="label_margin_top"/> <field string="Top (mm)" name="label_margin_top" />
<field string="Right (mm)" name="label_margin_right"/> <field string="Right (mm)" name="label_margin_right" />
<field string="Bottom (mm)" name="label_margin_bottom"/> <field string="Bottom (mm)" name="label_margin_bottom" />
<field string="Left (mm)" name="label_margin_left"/> <field string="Left (mm)" name="label_margin_left" />
</group> </group>
</group> </group>
</form> </form>
@@ -44,9 +44,9 @@
<field name="model">report.paperformat.label</field> <field name="model">report.paperformat.label</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<tree string="Label paper format configuration"> <tree string="Label paper format configuration">
<field name="name"/> <field name="name" />
<field name="label_height"/> <field name="label_height" />
<field name="label_width"/> <field name="label_width" />
</tree> </tree>
</field> </field>
</record> </record>
@@ -65,6 +65,7 @@
name="Label Paper Formats" name="Label Paper Formats"
action="paperformat_label_action" action="paperformat_label_action"
parent="base.reporting_menuitem" parent="base.reporting_menuitem"
sequence="2"/> sequence="2"
/>
</odoo> </odoo>

View File

@@ -1,4 +1,4 @@
from odoo import api, models, fields from odoo import api, fields, models
class ReportLabelWizard(models.TransientModel): class ReportLabelWizard(models.TransientModel):
@@ -7,16 +7,20 @@ class ReportLabelWizard(models.TransientModel):
@api.model @api.model
def _default_line_ids(self): def _default_line_ids(self):
""" Compute line_ids based on context """ """Compute line_ids based on context"""
active_model = self.env.context.get("active_model") active_model = self.env.context.get("active_model")
active_ids = self.env.context.get("active_ids", []) active_ids = self.env.context.get("active_ids", [])
if not active_model or not active_ids: if not active_model or not active_ids:
return False return False
return [ return [
(0, 0, { (
"res_id": res_id, 0,
"quantity": 1, 0,
}) {
"res_id": res_id,
"quantity": 1,
},
)
for res_id in active_ids for res_id in active_ids
] ]

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8" ?>
<odoo> <odoo>
<record id="report_label_wizard_view_form" model="ir.ui.view"> <record id="report_label_wizard_view_form" model="ir.ui.view">
@@ -10,24 +10,30 @@
</group> </group>
<field name="line_ids"> <field name="line_ids">
<tree editable="bottom" create="false"> <tree editable="bottom" create="false">
<field name="sequence" widget="handle"/> <field name="sequence" widget="handle" />
<field name="res_id" invisible="1"/> <field name="res_id" invisible="1" />
<field name="res_name" string="Record"/> <field name="res_name" string="Record" />
<field name="quantity"/> <field name="quantity" />
</tree> </tree>
</field> </field>
<group name="settings" string="Settings"> <group name="settings" string="Settings">
<group> <group>
<field name="offset"/> <field name="offset" />
<field name="model_id" invisible="1"/> <field name="model_id" invisible="1" />
<field name="label_paperformat_id"/> <field name="label_paperformat_id" />
<field name="label_template" invisible="1"/> <field name="label_template" invisible="1" />
</group> </group>
</group> </group>
</sheet> </sheet>
<footer> <footer>
<button name="print_report" string="Print" type="object" icon="fa-print" class="oe_highlight"/> <button
<button special="cancel" string="Cancel"/> name="print_report"
string="Print"
type="object"
icon="fa-print"
class="oe_highlight"
/>
<button special="cancel" string="Cancel" />
</footer> </footer>
</form> </form>
</field> </field>

View File

@@ -0,0 +1 @@
../../../../report_label

View File

@@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)