diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/product/report | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/product/report')
| -rw-r--r-- | addons/product/report/__init__.py | 4 | ||||
| -rw-r--r-- | addons/product/report/product_packaging.xml | 46 | ||||
| -rw-r--r-- | addons/product/report/product_pricelist_report.py | 68 | ||||
| -rw-r--r-- | addons/product/report/product_pricelist_report_templates.xml | 79 | ||||
| -rw-r--r-- | addons/product/report/product_product_templates.xml | 80 | ||||
| -rw-r--r-- | addons/product/report/product_reports.xml | 67 | ||||
| -rw-r--r-- | addons/product/report/product_template_templates.xml | 29 |
7 files changed, 373 insertions, 0 deletions
diff --git a/addons/product/report/__init__.py b/addons/product/report/__init__.py new file mode 100644 index 00000000..53767888 --- /dev/null +++ b/addons/product/report/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import product_pricelist_report diff --git a/addons/product/report/product_packaging.xml b/addons/product/report/product_packaging.xml new file mode 100644 index 00000000..e9f462bc --- /dev/null +++ b/addons/product/report/product_packaging.xml @@ -0,0 +1,46 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<odoo>
+ <data>
+ <template id="report_packagingbarcode">
+ <t t-call="web.basic_layout">
+ <div class="page">
+ <t t-foreach="docs" t-as="packaging">
+ <div class="col-4" style="padding:0;"> + <table class="table table-condensed" style="border-bottom: 0px solid white !important;width: 3in;"> + <tr> + <th style="text-align: left;"> + <strong t-field="packaging.name"/> + </th> + </tr> + <tr> + <td> + <strong t-field="packaging.product_id.display_name"/> + </td> + </tr> + <tr> + <td> + <div class="o_row"> + <strong>Qty: </strong> + <strong t-field="packaging.qty"/> + <strong t-field="packaging.product_uom_id" groups="uom.group_uom"/> + </div> + </td> + </tr> + <t t-if="packaging.barcode"> + <tr> + <td style="text-align: center; vertical-align: middle;" class="col-5"> + <img alt="Barcode" t-if="len(packaging.barcode) == 13" t-att-src="'/report/barcode/?type=%s&value=%s&width=%s&height=%s' % ('EAN13', packaging.barcode, 600, 150)" style="width:100%;height:20%;"/> + <img alt="Barcode" t-elif="len(packaging.barcode) == 8" t-att-src="'/report/barcode/?type=%s&value=%s&width=%s&height=%s' % ('EAN8', packaging.barcode, 600, 150)" style="width:100%;height:20%;"/> + <img alt="Barcode" t-else="" t-att-src="'/report/barcode/?type=%s&value=%s&width=%s&height=%s' % ('Code128', packaging.barcode, 600, 150)" style="width:100%;height:20%;"/> + <span t-field="packaging.barcode"/> + </td> + </tr> + </t> + </table> + </div>
+ </t>
+ </div>
+ </t>
+ </template>
+ </data>
+</odoo>
diff --git a/addons/product/report/product_pricelist_report.py b/addons/product/report/product_pricelist_report.py new file mode 100644 index 00000000..9a0e1ba7 --- /dev/null +++ b/addons/product/report/product_pricelist_report.py @@ -0,0 +1,68 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, models + + +class report_product_pricelist(models.AbstractModel): + _name = 'report.product.report_pricelist' + _description = 'Pricelist Report' + + def _get_report_values(self, docids, data): + product_ids = [int(i) for i in data['active_ids'].split(',')] + pricelist_id = data['pricelist_id'] and int(data['pricelist_id']) or None + quantities = [int(i) for i in data['quantities'].split(',')] or [1] + return self._get_report_data(data['active_model'], product_ids, pricelist_id, quantities, 'pdf') + + @api.model + def get_html(self): + render_values = self._get_report_data( + self.env.context.get('active_model'), + self.env.context.get('active_ids'), + self.env.context.get('pricelist_id'), + self.env.context.get('quantities') or [1] + ) + return self.env.ref('product.report_pricelist_page')._render(render_values) + + def _get_report_data(self, active_model, active_ids, pricelist_id, quantities, report_type='html'): + products = [] + is_product_tmpl = active_model == 'product.template' + + ProductClass = self.env['product.template'] if is_product_tmpl else self.env['product.product'] + ProductPricelist = self.env['product.pricelist'] + pricelist = ProductPricelist.browse(pricelist_id) + if not pricelist: + pricelist = ProductPricelist.search([], limit=1) + + if is_product_tmpl: + records = ProductClass.browse(active_ids) if active_ids else ProductClass.search([('sale_ok', '=', True)]) + for product in records: + product_data = self._get_product_data(is_product_tmpl, product, pricelist, quantities) + variants = [] + if len(product.product_variant_ids) > 1: + for variant in product.product_variant_ids: + variants.append(self._get_product_data(False, variant, pricelist, quantities)) + product_data['variants'] = variants + products.append(product_data) + else: + records = ProductClass.browse(active_ids) if active_ids else ProductClass.search([('sale_ok', '=', True)]) + for product in records: + products.append(self._get_product_data(is_product_tmpl, product, pricelist, quantities)) + + return { + 'pricelist': pricelist, + 'products': products, + 'quantities': quantities, + 'is_product_tmpl': is_product_tmpl, + 'is_html_type': report_type == 'html', + } + + def _get_product_data(self, is_product_tmpl, product, pricelist, quantities): + data = { + 'id': product.id, + 'name': is_product_tmpl and product.name or product.display_name, + 'price': dict.fromkeys(quantities, 0.0), + } + for qty in quantities: + data['price'][qty] = pricelist.get_product_price(product, qty, False) + return data diff --git a/addons/product/report/product_pricelist_report_templates.xml b/addons/product/report/product_pricelist_report_templates.xml new file mode 100644 index 00000000..9a394764 --- /dev/null +++ b/addons/product/report/product_pricelist_report_templates.xml @@ -0,0 +1,79 @@ +<?xml version="1.0" encoding="utf-8"?> +<odoo> + + <template id="report_pricelist_page"> + <div class="container bg-white p-4 my-4"> + <div class="row my-3"> + <div class="col-12"> + <h2 t-if="is_html_type"> + Pricelist: + <a href="#" class="o_action" data-model="product.pricelist" t-att-data-res-id="pricelist.id"> + <t t-esc="pricelist.display_name"/> + </a> + </h2> + <h2 t-else=""> + Pricelist: <t t-esc="pricelist.display_name"/> + </h2> + </div> + </div> + <div class="row"> + <div class="col-12"> + <table class="table table-sm"> + <thead> + <tr> + <th>Products</th> + <t t-foreach="quantities" t-as="qty"> + <th class="text-right"><t t-esc="qty"/> Units</th> + </t> + </tr> + </thead> + <tbody> + <t t-foreach="products" t-as="product"> + <tr> + <td t-att-class="is_product_tmpl and 'font-weight-bold' or None"> + <a t-if="is_html_type" href="#" class="o_action" t-att-data-model="is_product_tmpl and 'product.template' or 'product.product'" t-att-data-res-id="product['id']"> + <t t-esc="product['name']"/> + </a> + <t t-else=""> + <t t-esc="product['name']"/> + </t> + </td> + <t t-foreach="quantities" t-as="qty"> + <td class="text-right"> + <t t-esc="product['price'][qty]" t-options='{"widget": "monetary", "display_currency": pricelist.currency_id}'/> + </td> + </t> + </tr> + <t t-if="is_product_tmpl"> + <tr t-foreach="product['variants']" t-as="variant"> + <td> + <a t-if="is_html_type" href="#" class="o_action ml-4" data-model="product.product" t-att-data-res-id="variant['id']"> + <t t-esc="variant['name']"/> + </a> + <span t-else="" class="ml-4" t-esc="variant['name']"/> + </td> + <t t-foreach="quantities" t-as="qty"> + <td class="text-right"> + <t t-esc="variant['price'][qty]" t-options='{"widget": "monetary", "display_currency": pricelist.currency_id}'/> + </td> + </t> + </tr> + </t> + </t> + </tbody> + </table> + </div> + </div> + </div> + </template> + + <template id="report_pricelist"> + <t t-call="web.basic_layout"> + <div class="page"> + <t t-call="product.report_pricelist_page"/> + </div> + <p style="page-break-before:always;"> </p> + </t> + </template> + +</odoo> diff --git a/addons/product/report/product_product_templates.xml b/addons/product/report/product_product_templates.xml new file mode 100644 index 00000000..564fe745 --- /dev/null +++ b/addons/product/report/product_product_templates.xml @@ -0,0 +1,80 @@ +<?xml version="1.0" encoding="UTF-8"?> +<odoo> + <data> + <template id="report_simple_label"> + <div style="width: 32%; display: inline-table; height:14rem;"> + <table class="table table-bordered mb-0" style="border: 2px solid black;"> + <tr> + <th class="table-active text-left" style="height: 4rem;"> + <strong t-field="product.display_name"/> + </th> + </tr> + <tr> + <td style="height: 2rem"> + <strong>Price:</strong> + <strong t-field="product.lst_price" t-options="{'widget': 'monetary', 'display_currency': product.company_id.currency_id}"/> + </td> + </tr> + <tr> + <td class="text-center align-middle" style="height: 6rem"> + <t t-if="product.barcode"> + <img alt="Barcode" t-if="len(product.barcode) == 13" t-att-src="'/report/barcode/?type=%s&value=%s&width=%s&height=%s' % ('EAN13', quote_plus(product.barcode or ''), 600, 150)" style="width:100%;height::4rem;"/> + <img alt="Barcode" t-elif="len(product.barcode) == 8" t-att-src="'/report/barcode/?type=%s&value=%s&width=%s&height=%s' % ('EAN8', quote_plus(product.barcode or ''), 600, 150)" style="width:100%;height::4rem;"/> + <img alt="Barcode" t-else="" t-att-src="'/report/barcode/?type=%s&value=%s&width=%s&height=%s' % ('Code128', quote_plus(product.barcode or ''), 600, 150)" style="width:100%;height::4rem;"/> + <span t-field="product.barcode"/> + </t> + <t t-else=""><span class="text-muted">No barcode available</span></t> + </td> + </tr> + </table> + </div> + </template> + + <template id="report_productlabel"> + <t t-call="web.basic_layout"> + <div class="page"> + <t t-foreach="docs" t-as="product"> + <t t-call="product.report_simple_label"> + <t t-set="product" t-value="product"/> + </t> + </t> + </div> + </t> + </template> + + <template id="report_simple_barcode"> + <div style="width: 32%; display: inline-table; height: 10rem;"> + <table class="table table-bordered mb-0" style="border: 2px solid black;"> + <tr> + <th class="table-active text-left" style="height: 4rem;"> + <strong t-field="product.display_name"/> + </th> + </tr> + <tr> + <td class="text-center align-middle" style="height: 6rem;"> + <t t-if="product.barcode"> + <img alt="Barcode" t-if="len(product.barcode) == 13" t-att-src="'/report/barcode/?type=%s&value=%s&width=%s&height=%s' % ('EAN13', quote_plus(product.barcode or ''), 600, 150)" style="width:100%;height:4rem;"/> + <img alt="Barcode" t-elif="len(product.barcode) == 8" t-att-src="'/report/barcode/?type=%s&value=%s&width=%s&height=%s' % ('EAN8', quote_plus(product.barcode or ''), 600, 150)" style="width:100%;height:4rem;"/> + <img alt="Barcode" t-else="" t-att-src="'/report/barcode/?type=%s&value=%s&width=%s&height=%s' % ('Code128', quote_plus(product.barcode or ''), 600, 150)" style="width:100%;height:4rem"/> + <span t-field="product.barcode"/> + </t> + <t t-else=""><span class="text-muted">No barcode available</span></t> + </td> + </tr> + </table> + </div> + </template> + + <template id="report_productbarcode"> + <t t-call="web.basic_layout"> + <div class="page"> + <t t-foreach="docs" t-as="product"> + <t t-call="product.report_simple_barcode"> + <t t-set="product" t-value="product"/> + </t> + </t> + </div> + </t> + </template> + </data> +</odoo> diff --git a/addons/product/report/product_reports.xml b/addons/product/report/product_reports.xml new file mode 100644 index 00000000..35e033a9 --- /dev/null +++ b/addons/product/report/product_reports.xml @@ -0,0 +1,67 @@ +<?xml version="1.0" encoding="utf-8"?> +<odoo> + <data> + <record id="report_product_label" model="ir.actions.report"> + <field name="name">Product Label (PDF)</field> + <field name="model">product.product</field> + <field name="report_type">qweb-pdf</field> + <field name="report_name">product.report_productlabel</field> + <field name="report_file">product.report_productlabel</field> + <field name="print_report_name">'Products Labels - %s' % (object.name)</field> + <field name="binding_model_id" ref="product.model_product_product"/> + <field name="binding_type">report</field> + </record> + + <record id="report_product_template_label" model="ir.actions.report"> + <field name="name">Product Label (PDF)</field> + <field name="model">product.template</field> + <field name="report_type">qweb-pdf</field> + <field name="report_name">product.report_producttemplatelabel</field> + <field name="report_file">product.report_producttemplatelabel</field> + <field name="print_report_name">'Products Labels - %s' % (object.name)</field> + <field name="binding_model_id" ref="product.model_product_template"/> + <field name="binding_type">report</field> + </record> + + <record id="report_product_product_barcode" model="ir.actions.report"> + <field name="name">Product Barcode (PDF)</field> + <field name="model">product.product</field> + <field name="report_type">qweb-pdf</field> + <field name="report_name">product.report_productbarcode</field> + <field name="report_file">product.report_productbarcode</field> + <field name="print_report_name">'Products barcode - %s' % (object.name)</field> + <field name="binding_model_id" ref="product.model_product_product"/> + <field name="binding_type">report</field> + </record> + + <record id="report_product_template_barcode" model="ir.actions.report"> + <field name="name">Product Barcode (PDF)</field> + <field name="model">product.template</field> + <field name="report_type">qweb-pdf</field> + <field name="report_name">product.report_producttemplatebarcode</field> + <field name="report_file">product.report_producttemplatebarcode</field> + <field name="print_report_name">'Products barcode - %s' % (object.name)</field> + <field name="binding_model_id" ref="product.model_product_template"/> + <field name="binding_type">report</field> + </record> + + <record id="report_product_packaging" model="ir.actions.report"> + <field name="name">Product Packaging (PDF)</field> + <field name="model">product.packaging</field> + <field name="report_type">qweb-pdf</field> + <field name="report_name">product.report_packagingbarcode</field> + <field name="report_file">product.report_packagingbarcode</field> + <field name="print_report_name">'Products packaging - %s' % (object.name)</field> + <field name="binding_model_id" ref="product.model_product_packaging"/> + <field name="binding_type">report</field> + </record> + + <record id="action_report_pricelist" model="ir.actions.report"> + <field name="name">Pricelist</field> + <field name="model">product.product</field> + <field name="report_type">qweb-pdf</field> + <field name="report_name">product.report_pricelist</field> + <field name="report_file">product.report_pricelist</field> + </record> + </data> +</odoo> diff --git a/addons/product/report/product_template_templates.xml b/addons/product/report/product_template_templates.xml new file mode 100644 index 00000000..11178472 --- /dev/null +++ b/addons/product/report/product_template_templates.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="utf-8"?> +<odoo> +<template id="report_producttemplatelabel"> + <t t-call="web.basic_layout"> + <div class="page"> + <t t-foreach="docs" t-as="template"> + <t t-foreach="template.product_variant_ids" t-as="product"> + <t t-call="product.report_simple_label"> + <t t-set="product" t-value="product"/> + </t> + </t> + </t> + </div> + </t> +</template> +<template id="report_producttemplatebarcode"> + <t t-call="web.basic_layout"> + <div class="page"> + <t t-foreach="docs" t-as="template"> + <t t-foreach="template.product_variant_ids" t-as="product"> + <t t-call="product.report_simple_barcode"> + <t t-set="product" t-value="product"/> + </t> + </t> + </t> + </div> + </t> +</template> +</odoo> |
