[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

@@ -8,7 +8,10 @@
/>
</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" />
@@ -23,11 +26,18 @@
<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="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,31 +10,27 @@ 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"""
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
@@ -42,11 +38,13 @@ class IrActionsServer(models.Model):
def run_action_report_label_multi(self, action, eval_context=None):
"""Show report label wizard"""
context = dict(self.env.context)
context.update({
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

@@ -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

@@ -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

@@ -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):
@@ -13,10 +13,14 @@ class ReportLabelWizard(models.TransientModel):
if not active_model or not active_ids:
return False
return [
(0, 0, {
(
0,
0,
{
"res_id": res_id,
"quantity": 1,
})
},
)
for res_id in active_ids
]

View File

@@ -26,7 +26,13 @@
</group>
</sheet>
<footer>
<button name="print_report" string="Print" type="object" icon="fa-print" class="oe_highlight"/>
<button
name="print_report"
string="Print"
type="object"
icon="fa-print"
class="oe_highlight"
/>
<button special="cancel" string="Cancel" />
</footer>
</form>

View File

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

View File

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