[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',
'version': '12.0.1.0.0',
'summary': 'Print configurable self-adhesive labels reports',
'author': 'Iván Todorovich, Moka Tourisme, Odoo Community Association (OCA)',
'website': 'https://github.com/OCA/reporting-engine',
'license': 'AGPL-3',
'category': 'Reporting',
'maintainers': [
'ivantodorovich'
"name": "Report Labels",
"version": "12.0.1.0.0",
"summary": "Print configurable self-adhesive labels reports",
"author": "Iván Todorovich, Moka Tourisme, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/reporting-engine",
"license": "AGPL-3",
"category": "Reporting",
"maintainers": ["ivantodorovich"],
"depends": [
"base",
],
'depends': [
'base',
"data": [
"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': [
'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',
"demo": [
"demo/demo.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>
<data noupdate="1">
@@ -6,21 +6,21 @@
<field name="name">Label: Agipa 114016</field>
<field name="format">A5</field>
<field name="orientation">Portrait</field>
<field name="margin_top" eval="5"/>
<field name="margin_right" eval="13"/>
<field name="margin_bottom" eval="0"/>
<field name="margin_left" eval="13"/>
<field name="dpi" eval="82"/>
<field name="label_width" eval="38"/>
<field name="label_height" eval="19"/>
<field name="label_padding_top" eval="1"/>
<field name="label_padding_right" eval="1"/>
<field name="label_padding_bottom" eval="1"/>
<field name="label_padding_left" eval="1"/>
<field name="label_margin_top" eval="1"/>
<field name="label_margin_right" eval="1"/>
<field name="label_margin_bottom" eval="1"/>
<field name="label_margin_left" eval="1"/>
<field name="margin_top" eval="5" />
<field name="margin_right" eval="13" />
<field name="margin_bottom" eval="0" />
<field name="margin_left" eval="13" />
<field name="dpi" eval="82" />
<field name="label_width" eval="38" />
<field name="label_height" eval="19" />
<field name="label_padding_top" eval="1" />
<field name="label_padding_right" eval="1" />
<field name="label_padding_bottom" eval="1" />
<field name="label_padding_left" eval="1" />
<field name="label_margin_top" eval="1" />
<field name="label_margin_right" eval="1" />
<field name="label_margin_bottom" eval="1" />
<field name="label_margin_left" eval="1" />
</record>
</data>

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<template id="label_template_partner_address" name="Partner Label: Address">
@@ -8,26 +8,36 @@
/>
</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="format">A4</field>
<field name="label_height" eval="42.3"/>
<field name="label_width" eval="60"/>
<field name="label_padding_top" eval="5"/>
<field name="label_padding_right" eval="5"/>
<field name="label_padding_bottom" eval="5"/>
<field name="label_padding_left" eval="5"/>
<field name="label_height" eval="42.3" />
<field name="label_width" eval="60" />
<field name="label_padding_top" eval="5" />
<field name="label_padding_right" eval="5" />
<field name="label_padding_bottom" eval="5" />
<field name="label_padding_left" eval="5" />
</record>
<record id="actions_server_label_partner_address" model="ir.actions.server">
<field name="name">Print Address Labels</field>
<field name="state">report_label</field>
<field name="model_id" ref="base.model_res_partner"/>
<field name="label_paperformat_id" ref="report_paperformat_label_partner_address"/>
<field name="model_id" ref="base.model_res_partner" />
<field
name="label_paperformat_id"
ref="report_paperformat_label_partner_address"
/>
<field name="label_template">report_label.label_template_partner_address</field>
</record>
<!-- 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>

View File

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

View File

@@ -1,4 +1,4 @@
from odoo import api, models, fields
from odoo import api, fields, models
class IrActionsServer(models.Model):
@@ -10,43 +10,41 @@ class IrActionsServer(models.Model):
label_template = fields.Char(
"Label QWeb Template",
help="The QWeb template key to render the labels",
states={
"report_label": [("required", True)]
}
states={"report_label": [("required", True)]},
)
label_paperformat_id = fields.Many2one(
"report.paperformat.label",
"Label Paper Format",
states={
"report_label": [("required", True)]
}
states={"report_label": [("required", True)]},
)
@api.multi
def report_label_associated_view(self):
""" View the associated qweb templates """
"""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:
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),
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 """
"""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,
})
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",

View File

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

View File

@@ -1,20 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<template id="report_label_template">
<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">
height: <t t-esc="label_format['label_height']"/>mm;
width: <t t-esc="label_format['label_width']"/>mm;
padding-top: <t t-esc="label_format['label_padding_top']"/>mm;
padding-right: <t t-esc="label_format['label_padding_right']"/>mm;
padding-bottom: <t t-esc="label_format['label_padding_bottom']"/>mm;
padding-left: <t t-esc="label_format['label_padding_left']"/>mm;
margin-top: <t t-esc="label_format['label_margin_top']"/>mm;
margin-right: <t t-esc="label_format['label_margin_right']"/>mm;
margin-bottom: <t t-esc="label_format['label_margin_bottom']"/>mm;
margin-left: <t t-esc="label_format['label_margin_left']"/>mm;
height: <t t-esc="label_format['label_height']" />mm;
width: <t t-esc="label_format['label_width']" />mm;
padding-top: <t t-esc="label_format['label_padding_top']" />mm;
padding-right: <t t-esc="label_format['label_padding_right']" />mm;
padding-bottom: <t t-esc="label_format['label_padding_bottom']" />mm;
padding-left: <t t-esc="label_format['label_padding_left']" />mm;
margin-top: <t t-esc="label_format['label_margin_top']" />mm;
margin-right: <t t-esc="label_format['label_margin_right']" />mm;
margin-bottom: <t t-esc="label_format['label_margin_bottom']" />mm;
margin-left: <t t-esc="label_format['label_margin_left']" />mm;
display: inline-block;
overflow: hidden;
float: left;
@@ -24,13 +24,16 @@
</t>
<!-- Offset: Skip the first [offset] labels -->
<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-foreach="lines" t-as="line">
<t t-foreach="range(0, line['quantity'])" t-as="i">
<div t-att-style="label_style">
<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>
</div>
</t>

View File

@@ -1,13 +1,14 @@
from odoo.tests import common
from ast import literal_eval
from odoo.tests import common
class TestReportLabel(common.TransactionCase):
def setUp(self):
super().setUp()
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):
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>
<record id="view_server_action_form" model="ir.ui.view">
<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">
<header position="inside">
<button
@@ -15,8 +15,14 @@
/>
</header>
<field name="type" position="after">
<field name="label_paperformat_id" attrs="{'invisible': [('state', '!=', 'report_label')]}"/>
<field name="label_template" attrs="{'invisible': [('state', '!=', 'report_label')]}"/>
<field
name="label_paperformat_id"
attrs="{'invisible': [('state', '!=', 'report_label')]}"
/>
<field
name="label_template"
attrs="{'invisible': [('state', '!=', 'report_label')]}"
/>
</field>
</field>
</record>
@@ -35,6 +41,7 @@
name="Label Reports"
action="report_label_action"
parent="base.reporting_menuitem"
sequence="3"/>
sequence="3"
/>
</odoo>

View File

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

View File

@@ -1,4 +1,4 @@
from odoo import api, models, fields
from odoo import api, fields, models
class ReportLabelWizard(models.TransientModel):
@@ -7,16 +7,20 @@ class ReportLabelWizard(models.TransientModel):
@api.model
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_ids = self.env.context.get("active_ids", [])
if not active_model or not active_ids:
return False
return [
(0, 0, {
"res_id": res_id,
"quantity": 1,
})
(
0,
0,
{
"res_id": res_id,
"quantity": 1,
},
)
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>
<record id="report_label_wizard_view_form" model="ir.ui.view">
@@ -10,24 +10,30 @@
</group>
<field name="line_ids">
<tree editable="bottom" create="false">
<field name="sequence" widget="handle"/>
<field name="res_id" invisible="1"/>
<field name="res_name" string="Record"/>
<field name="quantity"/>
<field name="sequence" widget="handle" />
<field name="res_id" invisible="1" />
<field name="res_name" string="Record" />
<field name="quantity" />
</tree>
</field>
<group name="settings" string="Settings">
<group>
<field name="offset"/>
<field name="model_id" invisible="1"/>
<field name="label_paperformat_id"/>
<field name="label_template" invisible="1"/>
<field name="offset" />
<field name="model_id" invisible="1" />
<field name="label_paperformat_id" />
<field name="label_template" invisible="1" />
</group>
</group>
</sheet>
<footer>
<button name="print_report" string="Print" type="object" icon="fa-print" class="oe_highlight"/>
<button special="cancel" string="Cancel"/>
<button
name="print_report"
string="Print"
type="object"
icon="fa-print"
class="oe_highlight"
/>
<button special="cancel" string="Cancel" />
</footer>
</form>
</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,
)