From 3751379f1e9a4c215fb6eb898b4ccc67659b9ace Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 10 May 2022 21:51:50 +0700 Subject: initial commit 2 --- addons/product/report/__init__.py | 4 ++ addons/product/report/product_packaging.xml | 46 +++++++++++++ addons/product/report/product_pricelist_report.py | 68 ++++++++++++++++++ .../report/product_pricelist_report_templates.xml | 79 +++++++++++++++++++++ .../product/report/product_product_templates.xml | 80 ++++++++++++++++++++++ addons/product/report/product_reports.xml | 67 ++++++++++++++++++ .../product/report/product_template_templates.xml | 29 ++++++++ 7 files changed, 373 insertions(+) create mode 100644 addons/product/report/__init__.py create mode 100644 addons/product/report/product_packaging.xml create mode 100644 addons/product/report/product_pricelist_report.py create mode 100644 addons/product/report/product_pricelist_report_templates.xml create mode 100644 addons/product/report/product_product_templates.xml create mode 100644 addons/product/report/product_reports.xml create mode 100644 addons/product/report/product_template_templates.xml (limited to 'addons/product/report') 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 @@ + + + + + + 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 @@ + + + + + + + + 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 @@ + + + + + + + + + + + + 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 @@ + + + + + Product Label (PDF) + product.product + qweb-pdf + product.report_productlabel + product.report_productlabel + 'Products Labels - %s' % (object.name) + + report + + + + Product Label (PDF) + product.template + qweb-pdf + product.report_producttemplatelabel + product.report_producttemplatelabel + 'Products Labels - %s' % (object.name) + + report + + + + Product Barcode (PDF) + product.product + qweb-pdf + product.report_productbarcode + product.report_productbarcode + 'Products barcode - %s' % (object.name) + + report + + + + Product Barcode (PDF) + product.template + qweb-pdf + product.report_producttemplatebarcode + product.report_producttemplatebarcode + 'Products barcode - %s' % (object.name) + + report + + + + Product Packaging (PDF) + product.packaging + qweb-pdf + product.report_packagingbarcode + product.report_packagingbarcode + 'Products packaging - %s' % (object.name) + + report + + + + Pricelist + product.product + qweb-pdf + product.report_pricelist + product.report_pricelist + + + 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 @@ + + + + + -- cgit v1.2.3