Initial commit
This commit is contained in:
1
garazd_product_label_pro/report/__init__.py
Normal file
1
garazd_product_label_pro/report/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import product_label_report
|
||||
15
garazd_product_label_pro/report/product_label_report.py
Normal file
15
garazd_product_label_pro/report/product_label_report.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from odoo import models
|
||||
|
||||
|
||||
class ReportGarazdProductLabelFromTemplate(models.AbstractModel):
|
||||
_name = 'report.garazd_product_label.report_product_label_from_template'
|
||||
_description = 'Custom Product Label Report'
|
||||
|
||||
def _get_report_values(self, docids, data):
|
||||
labels = self.env['print.product.label.line'].browse(data.get('ids', []))
|
||||
return {
|
||||
'doc_model': 'print.product.label.line',
|
||||
'doc_ids': labels.ids,
|
||||
'docs': labels,
|
||||
'data': data.get('data'),
|
||||
}
|
||||
103
garazd_product_label_pro/report/product_label_reports.xml
Normal file
103
garazd_product_label_pro/report/product_label_reports.xml
Normal file
@@ -0,0 +1,103 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<odoo>
|
||||
|
||||
<record id="paperformat_label_custom_50x25" model="report.paperformat">
|
||||
<field name="name">Label: 50x25 mm</field>
|
||||
<field name="format">custom</field>
|
||||
<field name="page_height">25</field>
|
||||
<field name="page_width">50</field>
|
||||
<field name="orientation">Portrait</field>
|
||||
<field name="margin_top">0</field>
|
||||
<field name="margin_bottom">0</field>
|
||||
<field name="margin_left">0</field>
|
||||
<field name="margin_right">0</field>
|
||||
<field name="header_spacing">0</field>
|
||||
<field name="header_line" eval="False"/>
|
||||
<field name="disable_shrinking" eval="True"/>
|
||||
<field name="dpi">96</field>
|
||||
<field name="default" eval="False"/>
|
||||
</record>
|
||||
|
||||
<record id="paperformat_label_custom_100x100" model="report.paperformat">
|
||||
<field name="name">Label: 100x100mm</field>
|
||||
<field name="format">custom</field>
|
||||
<field name="page_height">100</field>
|
||||
<field name="page_width">100</field>
|
||||
<field name="orientation">Portrait</field>
|
||||
<field name="margin_top">0</field>
|
||||
<field name="margin_bottom">0</field>
|
||||
<field name="margin_left">0</field>
|
||||
<field name="margin_right">0</field>
|
||||
<field name="disable_shrinking" eval="True"/>
|
||||
<field name="header_spacing">0</field>
|
||||
<field name="dpi">96</field>
|
||||
<field name="default" eval="False"/>
|
||||
</record>
|
||||
|
||||
<record id="paperformat_label_a4_63x38" model="report.paperformat">
|
||||
<field name="name">Label: A4 63x38mm</field>
|
||||
<field name="format">A4</field>
|
||||
<field name="page_height">0</field>
|
||||
<field name="page_width">0</field>
|
||||
<field name="orientation">Portrait</field>
|
||||
<field name="margin_top">9</field>
|
||||
<field name="margin_bottom">0</field>
|
||||
<field name="margin_left">8</field>
|
||||
<field name="margin_right">7</field>
|
||||
<field name="header_line" eval="False"/>
|
||||
<field name="header_spacing">0</field>
|
||||
<field name="disable_shrinking" eval="True"/>
|
||||
<field name="dpi">96</field>
|
||||
<field name="default" eval="False"/>
|
||||
</record>
|
||||
|
||||
<record id="paperformat_label_a4_99x38" model="report.paperformat">
|
||||
<field name="name">Label: A4 99x38mm</field>
|
||||
<field name="format">A4</field>
|
||||
<field name="page_height">0</field>
|
||||
<field name="page_width">0</field>
|
||||
<field name="orientation">Portrait</field>
|
||||
<field name="margin_top">10</field>
|
||||
<field name="margin_bottom">0</field>
|
||||
<field name="margin_left">5</field>
|
||||
<field name="margin_right">5</field>
|
||||
<field name="header_line" eval="False"/>
|
||||
<field name="header_spacing">0</field>
|
||||
<field name="disable_shrinking" eval="True"/>
|
||||
<field name="dpi">96</field>
|
||||
<field name="default" eval="False"/>
|
||||
</record>
|
||||
|
||||
<record id="paperformat_label_letter_66x25" model="report.paperformat">
|
||||
<field name="name">Label: Letter 1"x2⅝"</field>
|
||||
<field name="format">Letter</field>
|
||||
<field name="page_height">0</field>
|
||||
<field name="page_width">0</field>
|
||||
<field name="orientation">Portrait</field>
|
||||
<field name="margin_top">12</field>
|
||||
<field name="margin_bottom">8</field>
|
||||
<field name="margin_left">4.76</field>
|
||||
<field name="margin_right">4.76</field>
|
||||
<field name="disable_shrinking" eval="True"/>
|
||||
<field name="header_spacing">0</field>
|
||||
<field name="dpi">96</field>
|
||||
<field name="default" eval="False"/>
|
||||
</record>
|
||||
|
||||
<record id="paperformat_label_letter_101x50" model="report.paperformat">
|
||||
<field name="name">Label: Letter 4"x2"</field>
|
||||
<field name="format">Letter</field>
|
||||
<field name="page_height">0</field>
|
||||
<field name="page_width">0</field>
|
||||
<field name="orientation">Portrait</field>
|
||||
<field name="margin_top">12.7</field>
|
||||
<field name="margin_bottom">8</field>
|
||||
<field name="margin_left">4.76</field>
|
||||
<field name="margin_right">4.76</field>
|
||||
<field name="disable_shrinking" eval="True"/>
|
||||
<field name="header_spacing">0</field>
|
||||
<field name="dpi">96</field>
|
||||
<field name="default" eval="False"/>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
94
garazd_product_label_pro/report/product_label_templates.xml
Normal file
94
garazd_product_label_pro/report/product_label_templates.xml
Normal file
@@ -0,0 +1,94 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<odoo>
|
||||
|
||||
<template id="product_label_from_template">
|
||||
<div name="label_div">
|
||||
<div name="transform_div">
|
||||
<t t-foreach="label.wizard_id.template_id.section_ids" t-as="section">
|
||||
<div t-if="section.active" t-attf-style="{{section.get_html_style(label)}}">
|
||||
<t t-set="value" t-value="section.get_value(label)"/>
|
||||
<t t-if="section.widget == 'barcode'">
|
||||
<t t-set="barcode_div_size" t-value="'width: 85%; height: 100%;'"/>
|
||||
<t t-set="barcode_size" t-value="section.get_barcode_size()"/>
|
||||
<!-- Barcode parameters: addons/web/controllers/report.py(#59 - report_barcode()), odoo/addons/base/models/ir_actions_report.py(#675 - barcode()) -->
|
||||
<div t-out="str(value)" style="padding: 0; height: 100%;" t-options="{'widget': 'barcode', 'width': barcode_size['width'], 'height': barcode_size['height'], 'quiet': 0, 'symbology': section.barcode_symbology, 'img_style': barcode_div_size, 'humanreadable': int(section.barcode_is_humanreadable)}"/>
|
||||
</t>
|
||||
<t t-elif="section.widget == 'price'">
|
||||
<div t-field="label.price" t-options="{'widget': 'monetary', 'label_price': True, 'display_currency': label.currency_id}"/>
|
||||
</t>
|
||||
<t t-elif="section.widget == 'qr_code'">
|
||||
<t t-set="qr_code_size_px" t-value="section.height * 40"/>
|
||||
<img t-att-src="'/report/barcode/?barcode_type=QR&value=%s&width=%d&height=%d'%(value, qr_code_size_px, qr_code_size_px)" t-attf-style="display: block; height: 100%; width: {{ section.height - section.padding_top - section.padding_bottom }}mm;"/>
|
||||
</t>
|
||||
<t t-elif="section.widget == 'image'">
|
||||
<div t-attf-style="width:100%;height:100%;background-image:url({{ section.get_image_url(label) }});background-size:contain;background-repeat:no-repeat;background-position:center;"/>
|
||||
</t>
|
||||
<t t-elif="section.type == 'image'">
|
||||
<div t-attf-style="width:100%;height:100%;background-image:url(/web/image/print.product.label.section/{{ section.id }}/image);background-size:contain;background-repeat:no-repeat;background-position:center;"/>
|
||||
</t>
|
||||
<t t-elif="section.type == 'product_attributes'">
|
||||
<t t-if="section.widget == 'attribute_list'">
|
||||
<div t-foreach="section.get_attribute_data(label)" t-as="attr">
|
||||
<span t-if="section.with_product_attribute_name" t-out="attr['name']" class="mx-1"/>
|
||||
<t t-foreach="attr['values']" t-as="attr_value">
|
||||
<span t-att-class="'badge rounded bg-%s text-%s mr-1 px-2 py-1' % ('dark' if attr_value['active'] else 'light', 'light' if attr_value['active'] else 'dark')">
|
||||
<t t-out="attr_value['name']"/>
|
||||
</span>
|
||||
</t>
|
||||
</div>
|
||||
</t>
|
||||
<div t-else="" t-foreach="section.get_attribute_data(label)" t-as="attr" class="d-inline-flex flex-wrap">
|
||||
<span class="mw-100 mx-1">
|
||||
<t t-if="section.with_product_attribute_name" class="mr-1"><t t-out="attr['name']"/>: </t>
|
||||
<t t-foreach="attr['values']" t-as="attr_value">
|
||||
<span t-if="attr_value['active']" t-out="attr_value['name']" style="padding-left: 3px;"/>
|
||||
</t>
|
||||
</span>
|
||||
</div>
|
||||
</t>
|
||||
<t t-elif="section.type == 'multi_price'">
|
||||
<t t-foreach="section.get_value(label)" t-as="price">
|
||||
<t t-out="price['amount']"/>
|
||||
<small>(from <t t-out="price['qty']"/> <t t-out="label.product_id.uom_id.name"/>)</small>
|
||||
<br/>
|
||||
</t>
|
||||
</t>
|
||||
<div t-else="" t-out="value"/>
|
||||
</div>
|
||||
</t>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template id="report_product_label_from_template" inherit_id="garazd_product_label.report_product_label_from_template">
|
||||
<xpath expr="//t[@t-call='web.basic_layout']" position="inside">
|
||||
<style>body {margin: 0 !important; padding: 0 !important;}</style>
|
||||
<t t-set="index" t-value="0"/>
|
||||
<t t-set="cols" t-value="data.get('cols', 1)"/>
|
||||
<t t-set="rows" t-value="data.get('rows', 1)"/>
|
||||
<t t-set="labels_per_sheet" t-value="cols * rows"/>
|
||||
<t t-set="skip" t-value="data.get('skip_places', 0)"/>
|
||||
<t t-foreach="docs" t-as="label">
|
||||
<t t-set="qty" t-value="1"/>
|
||||
<t t-if="label.qty" t-set="qty" t-value="label.qty"/>
|
||||
<t t-if="labels_per_sheet" t-foreach="range(not index and (qty + skip) or qty)" t-as="label_index">
|
||||
<div t-if="index % labels_per_sheet == 0" style="page-break-before: always;"/>
|
||||
<!-- Horizontal gap between labels -->
|
||||
<t t-if="index and index % cols == 0 and index % labels_per_sheet != 0" t-set="horizontal_gap" t-value="'height: 1px; margin-bottom: %.2fmm;' % data.get('row_gap', 0)"/>
|
||||
<t t-else="" t-set="horizontal_gap" t-value="''"/>
|
||||
<!-- New line -->
|
||||
<div t-if="index % cols == 0" t-att-style="'clear:both;' + horizontal_gap"/>
|
||||
<!-- Vertical gap between labels -->
|
||||
<t t-if="index % cols != 0" t-set="vertical_gap" t-value="'margin-left: %.2fmm;' % data.get('col_gap', 0)"/>
|
||||
<t t-else="" t-set="vertical_gap" t-value="''"/>
|
||||
<!-- Label <div> block -->
|
||||
<div t-att-style="data.get('label_style', '') + vertical_gap">
|
||||
<t t-if="index >= skip" t-call="garazd_product_label_pro.product_label_from_template"/>
|
||||
</div>
|
||||
<t t-set="index" t-value="index + 1"/>
|
||||
</t>
|
||||
</t>
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user