[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

@@ -8,7 +8,10 @@
/> />
</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" />
@@ -23,11 +26,18 @@
<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,31 +10,27 @@ 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
@@ -42,11 +38,13 @@ class IrActionsServer(models.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_template": action.label_template,
"label_paperformat_id": action.label_paperformat_id.id, "label_paperformat_id": action.label_paperformat_id.id,
"res_model_id": action.model_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

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

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

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

View File

@@ -26,7 +26,13 @@
</group> </group>
</sheet> </sheet>
<footer> <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" /> <button special="cancel" string="Cancel" />
</footer> </footer>
</form> </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,
)