diff --git a/sale_report_generator/README.rst b/sale_report_generator/README.rst new file mode 100644 index 000000000..01d6ec26e --- /dev/null +++ b/sale_report_generator/README.rst @@ -0,0 +1,42 @@ +Sale All In One Report Generator +==================================== +* Sale All In One Dynamic Report For Odoo 15 community And Enterprise editions + +Installation +============ + - www.odoo.com/documentation/15.0/setup/install.html + - Install our custom addon + +License +------- +General Public License, Version 3 (LGPL v3). +(https://www.odoo.com/documentation/user/13.0/legal/licenses/licenses.html) + +Company +------- +* 'Cybrosys Techno Solutions `__ + +Credits +------- +* Developer: +(v15) Sruthi @ Cybrosys + + +Contacts +-------- +* Mail Contact : odoo@cybrosys.com + +Bug Tracker +----------- +Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. + +Maintainer +========== +This module is maintained by Cybrosys Technologies. + +For support and more information, please visit https://www.cybrosys.com + +Further information +=================== +HTML Description: ``__ + diff --git a/sale_report_generator/__init__.py b/sale_report_generator/__init__.py new file mode 100644 index 000000000..4a84e60d7 --- /dev/null +++ b/sale_report_generator/__init__.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +############################################################################# +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2022-TODAY Cybrosys Technologies(). +# +# You can modify it under the terms of the GNU AFFERO +# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +# (AGPL v3) along with this program. +# If not, see . +# +############################################################################# + +from . import models +from . import report +from . import controllers diff --git a/sale_report_generator/__manifest__.py b/sale_report_generator/__manifest__.py new file mode 100644 index 000000000..06710634f --- /dev/null +++ b/sale_report_generator/__manifest__.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +############################################################################# +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2022-TODAY Cybrosys Technologies(). +# +# You can modify it under the terms of the GNU AFFERO +# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +# (AGPL v3) along with this program. +# If not, see . +# +############################################################################# + +{ + 'name': 'Sales All In One Report Generator', + 'version': '15.0.1.0.0', + 'summary': "Dynamic Sales Report Maker", + 'description': "Dynamic Sales Report Maker", + 'category': 'Sale', + 'author': 'Cybrosys Techno Solutions', + 'maintainer': 'Cybrosys Techno Solutions', + 'company': 'Cybrosys Techno Solutions', + 'website': 'https://www.cybrosys.com', + 'depends': ['sale_management'], + 'data': [ + 'security/ir.model.access.csv', + 'views/sale_report.xml', + 'report/sale_order_report.xml' + ], + 'assets': { + 'web.assets_backend': [ + 'sale_report_generator/static/src/js/sale_report.js', + 'sale_report_generator/static/src/css/sale_report.css' + ], + 'web.assets_qweb': [ + 'sale_report_generator/static/src/xml/sale_report_view.xml', + ], + }, + 'images': ['static/description/banner.png'], + 'license': 'AGPL-3', + 'installable': True, + 'auto_install': False, + 'auto_install': False, +} diff --git a/sale_report_generator/controllers/__init__.py b/sale_report_generator/controllers/__init__.py new file mode 100644 index 000000000..8edd0b2d2 --- /dev/null +++ b/sale_report_generator/controllers/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +############################################################################# +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2022-TODAY Cybrosys Technologies(). +# +# You can modify it under the terms of the GNU AFFERO +# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +# (AGPL v3) along with this program. +# If not, see . +# +############################################################################# + +from . import main diff --git a/sale_report_generator/controllers/main.py b/sale_report_generator/controllers/main.py new file mode 100644 index 000000000..4e500a575 --- /dev/null +++ b/sale_report_generator/controllers/main.py @@ -0,0 +1,56 @@ +# -*- coding: utf-8 -*- +############################################################################# +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2022-TODAY Cybrosys Technologies(). +# +# You can modify it under the terms of the GNU AFFERO +# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +# (AGPL v3) along with this program. +# If not, see . +# +############################################################################# + +import json +from odoo import http +from odoo.http import content_disposition, request +from odoo.addons.web.controllers.main import _serialize_exception +from odoo.tools import html_escape + + +class TBXLSXReportController(http.Controller): + @http.route('/sale_dynamic_xlsx_reports', type='http', auth='user', methods=['POST'], csrf=False) + def get_report_xlsx(self, model, options, output_format, report_data, report_name, dfr_data, **kw): + uid = request.session.uid + report_obj = request.env[model].with_user(uid) + dfr_data = dfr_data + options = options + token = 'dummy-because-api-expects-one' + try: + if output_format == 'xlsx': + response = request.make_response( + None, + headers=[ + ('Content-Type', 'application/vnd.ms-excel'), + ('Content-Disposition', content_disposition(report_name + '.xlsx')) + ] + ) + report_obj.get_sale_xlsx_report(options, response, report_data, dfr_data) + response.set_cookie('fileToken', token) + return response + except Exception as e: + se = _serialize_exception(e) + error = { + 'code': 200, + 'message': 'Odoo Server Error', + 'data': se + } + return request.make_response(html_escape(json.dumps(error))) diff --git a/sale_report_generator/doc/RELEASE_NOTES.md b/sale_report_generator/doc/RELEASE_NOTES.md new file mode 100644 index 000000000..3ded3701e --- /dev/null +++ b/sale_report_generator/doc/RELEASE_NOTES.md @@ -0,0 +1,7 @@ +## Module + +#### 21.06.2022 +#### Version 15.0.1.0.0 +#### ADD +Initial Commit + diff --git a/sale_report_generator/models/__init__.py b/sale_report_generator/models/__init__.py new file mode 100644 index 000000000..9d1014f6e --- /dev/null +++ b/sale_report_generator/models/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +############################################################################# +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2022-TODAY Cybrosys Technologies(). +# +# You can modify it under the terms of the GNU AFFERO +# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +# (AGPL v3) along with this program. +# If not, see . +# +############################################################################# + +from . import sale_report diff --git a/sale_report_generator/models/sale_report.py b/sale_report_generator/models/sale_report.py new file mode 100644 index 000000000..566d53ea8 --- /dev/null +++ b/sale_report_generator/models/sale_report.py @@ -0,0 +1,564 @@ +# -*- coding: utf-8 -*- +############################################################################# +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2022-TODAY Cybrosys Technologies(). +# +# You can modify it under the terms of the GNU AFFERO +# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +# (AGPL v3) along with this program. +# If not, see . +# +############################################################################# + +from odoo import models, fields, api +import io +import json + +try: + from odoo.tools.misc import xlsxwriter +except ImportError: + import xlsxwriter + + +class SaleReportGenerator(models.Model): + _name = "sales.report" + + sale_report = fields.Char(string="Sale Report") + date_from = fields.Datetime(string="Date From") + date_to = fields.Datetime(string="Date to") + report_type = fields.Selection([ + ('report_by_order', 'Report By Order'), + ('report_by_order_detail', 'Report By Order Detail'), + ('report_by_product', 'Report By Product'), + ('report_by_categories', 'Report By Categories'), + ('report_by_salesperson', 'Report By Sales Person'), + ('report_by_state', 'Report By State')], default='report_by_order') + + @api.model + def sale_report(self, option): + orders = self.env['sale.order'].search([]) + report_values = self.env['sales.report'].search( + [('id', '=', option[0])]) + data = { + 'report_type': report_values.report_type, + 'model': self, + } + + if report_values.date_from: + data.update({ + 'date_from': report_values.date_from, + }) + if report_values.date_to: + data.update({ + 'date_to': report_values.date_to, + }) + filters = self.get_filter(option) + report = self._get_report_values(data) + lines = self._get_report_values(data).get('SALE') + main_line = self._get_report_values(data).get('sale_main') + + return { + 'name': "Sale Orders", + 'type': 'ir.actions.client', + 'tag': 's_r', + 'orders': data, + 'filters': filters, + 'report_lines': lines, + 'report_main_line': main_line, + } + + def get_filter(self, option): + data = self.get_filter_data(option) + filters = {} + if data.get('report_type') == 'report_by_order': + filters['report_type'] = 'Report By Order' + elif data.get('report_type') == 'report_by_order_detail': + filters['report_type'] = 'Report By Order Detail' + elif data.get('report_type') == 'report_by_product': + filters['report_type'] = 'Report By Product' + elif data.get('report_type') == 'report_by_categories': + filters['report_type'] = 'Report By Categories' + elif data.get('report_type') == 'report_by_salesperson': + filters['report_type'] = 'Report By Sales Person' + elif data.get('report_type') == 'report_by_state': + filters['report_type'] = 'Report By State' + else: + filters['report_type'] = 'report_by_order' + + return filters + + def get_filter_data(self, option): + r = self.env['sales.report'].search([('id', '=', option[0])]) + default_filters = {} + + filter_dict = { + 'report_type': r.report_type, + } + filter_dict.update(default_filters) + return filter_dict + + @api.model + def create(self, vals): + + res = super(SaleReportGenerator, self).create(vals) + return res + + def write(self, vals): + + res = super(SaleReportGenerator, self).write(vals) + return res + + def _get_report_sub_lines(self, data, report, date_from, date_to): + report_sub_lines = [] + new_filter = None + + if data.get('report_type') == 'report_by_order': + query = ''' + select so.id,so.name as number,so.date_order,so.partner_id,so.amount_total,so.user_id,res_partner.name as customer, + res_users.partner_id as user_partner,so.id as id,sum(sale_order_line.product_uom_qty), + (SELECT res_partner.name as sales_man FROM res_partner WHERE res_partner.id = res_users.partner_id) + from sale_order as so + inner join res_partner on so.partner_id = res_partner.id + inner join res_users on so.user_id = res_users.id + inner join sale_order_line on so.id = sale_order_line.order_id + + ''' + term = 'Where ' + if data.get('date_from'): + query += "Where so.date_order >= '%s' " % data.get('date_from') + term = 'AND ' + if data.get('date_to'): + query += term + "so.date_order <= '%s' " % data.get('date_to') + query += "group by so.user_id,res_users.partner_id," \ + "res_partner.name,so.partner_id,so.date_order," \ + "so.name,so.amount_total,so.id" + self._cr.execute(query) + report_by_order = self._cr.dictfetchall() + report_sub_lines.append(report_by_order) + + elif data.get('report_type') == 'report_by_order_detail': + query = ''' + SELECT so.id,so.name as number,so.date_order,res_partner.name as customer, + rc.name as company,product_template.name as product, + product_product.default_code,so_line.product_uom_qty, + so_line.price_subtotal,so.amount_total,so.partner_id, + so.user_id,ru.id,so_line.product_id,sum(so_line.product_uom_qty), + (SELECT res_partner.name as salesman FROM res_partner + WHERE res_partner.id = res_users.partner_id) from sale_order as so + inner join sale_order_line as so_line on so.id = so_line.order_id + inner join product_product ON so_line.product_id=product_product.id + inner join product_template ON product_product.product_tmpl_id = product_template.id + inner join res_partner on so.partner_id=res_partner.id inner join res_users on so.user_id = res_users.id + inner join res_company as rc on so.company_id=rc.id + inner join res_users as ru on so.user_id=ru.id + ''' + term = 'Where ' + if data.get('date_from'): + query += "Where so.date_order >= '%s' " % data.get('date_from') + term = 'AND ' + if data.get('date_to'): + query += term + "so.date_order <= '%s' " % data.get('date_to') + query += ''' group by so.user_id, so.name, so.id,so.date_order, + res_partner.name,rc.name,product_template.name, + product_product.default_code,so_line.product_uom_qty, + so_line.price_subtotal,so.amount_total,so.partner_id, + so.user_id,ru.id,so_line.product_id,res_users.partner_id + ''' + self._cr.execute(query) + report_by_order_details = self._cr.dictfetchall() + report_sub_lines.append(report_by_order_details) + + elif data.get('report_type') == 'report_by_product': + query = ''' + SELECT so.id,so.date_order,product_template.name as product, + product_category.name as category, + product_product.default_code,so_line.product_uom_qty, + so.amount_total,so.name as number + From sale_order as so + inner join sale_order_line as so_line on so.id = so_line.order_id + inner join product_product ON so_line.product_id=product_product.id + inner join product_template ON product_product.product_tmpl_id = product_template.id + inner join product_category on product_category.id = product_template.categ_id + ''' + term = 'Where ' + if data.get('date_from'): + query += "Where so.date_order >= '%s' " % data.get('date_from') + term = 'AND ' + if data.get('date_to'): + query += term + "so.date_order <= '%s' " % data.get('date_to') + query += "group by so.id,so.date_order,product_template.name,product_category.name,product_product.default_code,so_line.product_uom_qty" + self._cr.execute(query) + report_by_product = self._cr.dictfetchall() + report_sub_lines.append(report_by_product) + + elif data.get('report_type') == 'report_by_categories': + query = ''' + select product_category.name,sum(so_line.product_uom_qty) as qty,sum(so_line.price_subtotal) as amount_total + from sale_order_line as so_line + inner join product_template on so_line.product_id = product_template.id + inner join product_category on product_category.id = product_template.categ_id + inner join sale_order on so_line.order_id = sale_order.id + ''' + term = 'Where ' + if data.get('date_from'): + query += "Where sale_order.date_order >= '%s' " % data.get( + 'date_from') + term = 'AND ' + if data.get('date_to'): + query += term + "sale_order.date_order <= '%s' " % data.get( + 'date_to') + query += "group by product_category.name" + self._cr.execute(query) + report_by_categories = self._cr.dictfetchall() + report_sub_lines.append(report_by_categories) + + elif data.get('report_type') == 'report_by_salesperson': + query = ''' + select res_partner.name,sum(sale_order_line.product_uom_qty) as qty, + sum(sale_order_line.price_subtotal) as amount,count(so.id) as order + from sale_order as so + inner join res_users on so.user_id = res_users.id + inner join res_partner on res_users.partner_id = res_partner.id + inner join sale_order_line on so.id = sale_order_line.order_id + ''' + term = 'Where ' + if data.get('date_from'): + query += "Where so.date_order >= '%s' " % data.get('date_from') + term = 'AND ' + if data.get('date_to'): + query += term + "so.date_order <= '%s' " % data.get('date_to') + query += "group by res_partner.name" + self._cr.execute(query) + report_by_salesperson = self._cr.dictfetchall() + report_sub_lines.append(report_by_salesperson) + + elif data.get('report_type') == 'report_by_state': + query = ''' + select so.state,count(so.id),sum(sale_order_line.product_uom_qty) as qty, + sum(sale_order_line.price_subtotal) as amount from sale_order as so + inner join sale_order_line on so.id = sale_order_line.order_id + ''' + term = 'Where ' + if data.get('date_from'): + query += "Where so.date_order >= '%s' " % data.get('date_from') + term = 'AND ' + if data.get('date_to'): + query += term + "so.date_order <= '%s' " % data.get('date_to') + query += "group by so.state" + self._cr.execute(query) + report_by_state = self._cr.dictfetchall() + + report_sub_lines.append(report_by_state) + return report_sub_lines + + def _get_report_total_value(self, data, report): + report_main_lines = [] + if data.get('report_type') == 'report_by_order': + self._cr.execute(''' + select count(so.id) as order,sum(so.amount_total) as amount + from sale_order as so + ''') + report_by_order = self._cr.dictfetchall() + report_main_lines.append(report_by_order) + elif data.get('report_type') == 'report_by_order_detail': + self._cr.execute(''' + select count(so_line.id) as order,sum(so_line.price_subtotal) as total + from sale_order_line as so_line + ''') + report_by_order_detail = self._cr.dictfetchall() + report_main_lines.append(report_by_order_detail) + elif data.get('report_type') == 'report_by_product': + self._cr.execute(''' + select count(so_line.product_id) as order,sum(so_line.price_subtotal) as amount + from sale_order_line as so_line + ''') + report_by_product = self._cr.dictfetchall() + report_main_lines.append(report_by_product) + + else: + report_main_lines = False + + return report_main_lines + + def _get_report_values(self, data): + docs = data['model'] + date_from = data.get('date_from') + date_to = data.get('date_to') + if data['report_type'] == 'report_by_order_detail': + report = ['Report By Order Detail'] + elif data['report_type'] == 'report_by_product': + report = ['Report By Product'] + elif data['report_type'] == 'report_by_categories': + report = ['Report By Categories'] + elif data['report_type'] == 'report_by_salesperson': + report = ['Report By Sales Person'] + elif data['report_type'] == 'report_by_state': + report = ['Report By State'] + else: + report = ['Report By Order'] + # + report_res_total = self._get_report_total_value(data, report) + if data.get('report_type'): + report_res = \ + self._get_report_sub_lines(data, report, date_from, date_to)[0] + else: + report_res = self._get_report_sub_lines(data, report, date_from, + date_to) + # + if data.get('report_type') == 'report_by_order': + report_res_total = self._get_report_total_value(data, report)[0] + + return { + 'doc_ids': self.ids, + 'docs': docs, + 'SALE': report_res, + 'sale_main': report_res_total, + + } + + def get_sale_xlsx_report(self, data, response, report_data, dfr_data): + report_data_main = json.loads(report_data) + output = io.BytesIO() + filters = json.loads(data) + + workbook = xlsxwriter.Workbook(output, {'in_memory': True}) + sheet = workbook.add_worksheet() + head = workbook.add_format({'align': 'center', 'bold': True, + 'font_size': '20px'}) + sub_heading = workbook.add_format( + {'align': 'center', 'bold': True, 'font_size': '10px', + 'border': 1, + 'border_color': 'black'}) + heading = workbook.add_format( + {'align': 'center', 'bold': True, 'font_size': '10px', + 'border': 2, + 'border_color': 'black'}) + txt = workbook.add_format({'font_size': '10px', 'border': 1}) + txt_l = workbook.add_format( + {'font_size': '10px', 'border': 1, 'bold': True}) + txt_v = workbook.add_format( + {'align': 'right', 'font_size': '10px', 'border': 1}) + sheet.merge_range('A2:H3', + 'Sales Report', + head) + date_head = workbook.add_format({'align': 'center', 'bold': True, + 'font_size': '10px'}) + date_style = workbook.add_format({'align': 'center', + 'font_size': '10px'}) + + if filters.get('report_type') == 'report_by_order': + + sheet.merge_range('B5:D5', 'Report Type: ' + + filters.get('report_type'), txt_l) + + sheet.write('A7', 'Sale', heading) + sheet.write('B7', 'Date Order', heading) + sheet.write('C7', 'Customer', heading) + sheet.write('D7', 'Sales Person', heading) + sheet.write('E7', 'Total Qty', heading) + sheet.write('F7', 'Amount Total', heading) + + lst = [] + for rec in report_data_main[0]: + lst.append(rec) + row = 6 + col = 0 + sheet.set_column(3, 0, 15) + sheet.set_column(4, 1, 15) + sheet.set_column(5, 2, 15) + sheet.set_column(6, 3, 15) + sheet.set_column(7, 4, 15) + sheet.set_column(8, 5, 15) + + for rec_data in report_data_main: + one_lst = [] + two_lst = [] + row += 1 + sheet.write(row, col, rec_data['number'], txt_l) + sheet.write(row, col + 1, rec_data['date_order'], txt_l) + sheet.write(row, col + 2, rec_data['customer'], txt_l) + sheet.write(row, col + 3, rec_data['sales_man'], txt_l) + sheet.write(row, col + 4, rec_data['sum'], txt_l) + sheet.write(row, col + 5, rec_data['amount_total'], txt_l) + + if filters.get('report_type') == 'report_by_order_detail': + + sheet.merge_range('B5:D5', 'Report Type: ' + + filters.get('report_type'), txt_l) + + sheet.write('A7', 'Sale', heading) + sheet.write('B7', 'Date Order', heading) + sheet.write('C7', 'Customer', heading) + sheet.write('D7', 'Company', heading) + sheet.write('E7', 'Sales Person', heading) + sheet.write('F7', 'Product Name', heading) + sheet.write('G7', 'Product Code', heading) + sheet.write('H7', 'Quantity', heading) + sheet.write('I7', 'Price Subtotal', heading) + sheet.write('J7', 'Amount Total', heading) + + lst = [] + for rec in report_data_main[0]: + lst.append(rec) + row = 6 + col = 0 + sheet.set_column(3, 0, 15) + sheet.set_column(4, 1, 15) + sheet.set_column(5, 2, 15) + sheet.set_column(6, 3, 15) + sheet.set_column(7, 4, 15) + sheet.set_column(8, 5, 15) + sheet.set_column(9, 6, 15) + sheet.set_column(10, 7, 15) + sheet.set_column(11, 8, 15) + sheet.set_column(12, 9, 15) + + for rec_data in report_data_main: + one_lst = [] + two_lst = [] + row += 1 + sheet.write(row, col, rec_data['number'], txt_l) + sheet.write(row, col + 1, rec_data['date_order'], txt_l) + sheet.write(row, col + 2, rec_data['customer'], txt_l) + sheet.write(row, col + 3, rec_data['company'], txt_l) + sheet.write(row, col + 4, rec_data['salesman'], txt_l) + sheet.write(row, col + 5, rec_data['product'], txt_l) + sheet.write(row, col + 6, rec_data['default_code'], txt_l) + sheet.write(row, col + 7, rec_data['product_uom_qty'], txt_l) + sheet.write(row, col + 8, rec_data['price_subtotal'], txt_l) + sheet.write(row, col + 9, rec_data['amount_total'], txt_l) + + if filters.get('report_type') == 'report_by_product': + + sheet.merge_range('B5:D5', 'Report Type: ' + + filters.get('report_type'), txt_l) + + sheet.write('A7', 'Product', heading) + sheet.write('B7', 'Category', heading) + sheet.write('C7', 'Product Code', heading) + sheet.write('D7', 'Quantity', heading) + sheet.write('E7', 'Amount Total', heading) + + lst = [] + for rec in report_data_main[0]: + lst.append(rec) + row = 6 + col = 0 + sheet.set_column(3, 0, 15) + sheet.set_column(4, 1, 15) + sheet.set_column(5, 2, 15) + sheet.set_column(6, 3, 15) + sheet.set_column(7, 4, 15) + + for rec_data in report_data_main: + one_lst = [] + two_lst = [] + row += 1 + sheet.write(row, col, rec_data['product'], txt_l) + sheet.write(row, col + 1, rec_data['category'], txt_l) + sheet.write(row, col + 2, rec_data['default_code'], txt_l) + sheet.write(row, col + 3, rec_data['product_uom_qty'], txt_l) + sheet.write(row, col + 4, rec_data['amount_total'], txt_l) + + if filters.get('report_type') == 'report_by_categories': + + sheet.merge_range('B5:D5', 'Report Type: ' + + filters.get('report_type'), txt_l) + + sheet.write('B7', 'Category', heading) + sheet.write('C7', 'Qty', heading) + sheet.write('D7', 'Amount Total', heading) + + lst = [] + for rec in report_data_main[0]: + lst.append(rec) + row = 6 + col = 1 + sheet.set_column(3, 1, 15) + sheet.set_column(4, 2, 15) + sheet.set_column(5, 3, 15) + + for rec_data in report_data_main: + one_lst = [] + two_lst = [] + row += 1 + sheet.write(row, col, rec_data['name'], txt_l) + sheet.write(row, col + 1, rec_data['qty'], txt_l) + sheet.write(row, col + 2, rec_data['amount_total'], txt_l) + + if filters.get('report_type') == 'report_by_salesperson': + + sheet.merge_range('B5:D5', 'Report Type: ' + + filters.get('report_type'), txt_l) + + sheet.write('A7', 'Sales Person', heading) + sheet.write('B7', 'Total Order', heading) + sheet.write('C7', 'Total Qty', heading) + sheet.write('D7', 'Total Amount', heading) + + lst = [] + for rec in report_data_main[0]: + lst.append(rec) + row = 6 + col = 0 + sheet.set_column(3, 0, 15) + sheet.set_column(4, 1, 15) + sheet.set_column(5, 2, 15) + sheet.set_column(6, 3, 15) + + for rec_data in report_data_main: + one_lst = [] + two_lst = [] + row += 1 + sheet.write(row, col, rec_data['name'], txt_l) + sheet.write(row, col + 1, rec_data['order'], txt_l) + sheet.write(row, col + 2, rec_data['qty'], txt_l) + sheet.write(row, col + 3, rec_data['amount'], txt_l) + + if filters.get('report_type') == 'report_by_state': + + sheet.merge_range('B5:D5', 'Report Type: ' + + filters.get('report_type'), txt_l) + + sheet.write('A7', 'State', heading) + sheet.write('B7', 'Total Count', heading) + sheet.write('C7', 'Quantity', heading) + sheet.write('D7', 'Amount', heading) + + lst = [] + for rec in report_data_main[0]: + lst.append(rec) + row = 6 + col = 0 + sheet.set_column(3, 0, 15) + sheet.set_column(4, 1, 15) + sheet.set_column(5, 2, 15) + sheet.set_column(6, 3, 15) + + for rec_data in report_data_main: + one_lst = [] + two_lst = [] + row += 1 + if rec_data['state'] == 'draft': + sheet.write(row, col, 'Quotation', txt_l) + elif rec_data['state'] == 'sent': + sheet.write(row, col, 'Quotation Sent', txt_l) + elif rec_data['state'] == 'sale': + sheet.write(row, col, 'Sale Order', txt_l) + sheet.write(row, col + 1, rec_data['count'], txt_l) + sheet.write(row, col + 2, rec_data['qty'], txt_l) + sheet.write(row, col + 3, rec_data['amount'], txt_l) + + workbook.close() + output.seek(0) + response.stream.write(output.read()) + output.close() diff --git a/sale_report_generator/report/__init__.py b/sale_report_generator/report/__init__.py new file mode 100644 index 000000000..f6da36362 --- /dev/null +++ b/sale_report_generator/report/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +############################################################################# +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2022-TODAY Cybrosys Technologies(). +# +# You can modify it under the terms of the GNU AFFERO +# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +# (AGPL v3) along with this program. +# If not, see . +# +############################################################################# + +from . import sale_order_report diff --git a/sale_report_generator/report/sale_order_report.py b/sale_report_generator/report/sale_order_report.py new file mode 100644 index 000000000..6ce763aee --- /dev/null +++ b/sale_report_generator/report/sale_order_report.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +############################################################################# +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2022-TODAY Cybrosys Technologies(). +# +# You can modify it under the terms of the GNU AFFERO +# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +# (AGPL v3) along with this program. +# If not, see . +# +############################################################################# + +from odoo import api, models, _ + + +class SaleOrder(models.AbstractModel): + _name = 'report.sale_report_generator.sale_order_report' + + @api.model + def _get_report_values(self, docids, data=None): + if self.env.context.get('sale_order_report'): + + if data.get('report_data'): + data.update({'report_main_line_data': data.get('report_data')['report_lines'], + 'Filters': data.get('report_data')['filters'], + 'company': self.env.company, + }) + return data diff --git a/sale_report_generator/report/sale_order_report.xml b/sale_report_generator/report/sale_order_report.xml new file mode 100644 index 000000000..36c13d240 --- /dev/null +++ b/sale_report_generator/report/sale_order_report.xml @@ -0,0 +1,468 @@ + + + + + + + + + + + + + + + + + + Sales All In One Report + sales.report + qweb-pdf + sale_report_generator.sale_order_report + sale_report_generator.sale_order_report + + + \ No newline at end of file diff --git a/sale_report_generator/security/ir.model.access.csv b/sale_report_generator/security/ir.model.access.csv new file mode 100644 index 000000000..e6ba9cae7 --- /dev/null +++ b/sale_report_generator/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_sales_report,access_sales_report,model_sales_report,base.group_user,1,1,1,1 diff --git a/sale_report_generator/static/description/assets/icons/check.png b/sale_report_generator/static/description/assets/icons/check.png new file mode 100644 index 000000000..c8e85f51d Binary files /dev/null and b/sale_report_generator/static/description/assets/icons/check.png differ diff --git a/sale_report_generator/static/description/assets/icons/chevron.png b/sale_report_generator/static/description/assets/icons/chevron.png new file mode 100644 index 000000000..2089293d6 Binary files /dev/null and b/sale_report_generator/static/description/assets/icons/chevron.png differ diff --git a/sale_report_generator/static/description/assets/icons/cogs.png b/sale_report_generator/static/description/assets/icons/cogs.png new file mode 100644 index 000000000..95d0bad62 Binary files /dev/null and b/sale_report_generator/static/description/assets/icons/cogs.png differ diff --git a/sale_report_generator/static/description/assets/icons/consultation.png b/sale_report_generator/static/description/assets/icons/consultation.png new file mode 100644 index 000000000..8319d4baa Binary files /dev/null and b/sale_report_generator/static/description/assets/icons/consultation.png differ diff --git a/sale_report_generator/static/description/assets/icons/ecom-black.png b/sale_report_generator/static/description/assets/icons/ecom-black.png new file mode 100644 index 000000000..a9385ff13 Binary files /dev/null and b/sale_report_generator/static/description/assets/icons/ecom-black.png differ diff --git a/sale_report_generator/static/description/assets/icons/education-black.png b/sale_report_generator/static/description/assets/icons/education-black.png new file mode 100644 index 000000000..3eb09b27b Binary files /dev/null and b/sale_report_generator/static/description/assets/icons/education-black.png differ diff --git a/sale_report_generator/static/description/assets/icons/hotel-black.png b/sale_report_generator/static/description/assets/icons/hotel-black.png new file mode 100644 index 000000000..130f613be Binary files /dev/null and b/sale_report_generator/static/description/assets/icons/hotel-black.png differ diff --git a/sale_report_generator/static/description/assets/icons/license.png b/sale_report_generator/static/description/assets/icons/license.png new file mode 100644 index 000000000..a5869797e Binary files /dev/null and b/sale_report_generator/static/description/assets/icons/license.png differ diff --git a/sale_report_generator/static/description/assets/icons/lifebuoy.png b/sale_report_generator/static/description/assets/icons/lifebuoy.png new file mode 100644 index 000000000..658d56ccc Binary files /dev/null and b/sale_report_generator/static/description/assets/icons/lifebuoy.png differ diff --git a/sale_report_generator/static/description/assets/icons/logo.png b/sale_report_generator/static/description/assets/icons/logo.png new file mode 100644 index 000000000..478462d3e Binary files /dev/null and b/sale_report_generator/static/description/assets/icons/logo.png differ diff --git a/sale_report_generator/static/description/assets/icons/manufacturing-black.png b/sale_report_generator/static/description/assets/icons/manufacturing-black.png new file mode 100644 index 000000000..697eb0e9f Binary files /dev/null and b/sale_report_generator/static/description/assets/icons/manufacturing-black.png differ diff --git a/sale_report_generator/static/description/assets/icons/pos-black.png b/sale_report_generator/static/description/assets/icons/pos-black.png new file mode 100644 index 000000000..97c0f90c1 Binary files /dev/null and b/sale_report_generator/static/description/assets/icons/pos-black.png differ diff --git a/sale_report_generator/static/description/assets/icons/puzzle.png b/sale_report_generator/static/description/assets/icons/puzzle.png new file mode 100644 index 000000000..65cf854e7 Binary files /dev/null and b/sale_report_generator/static/description/assets/icons/puzzle.png differ diff --git a/sale_report_generator/static/description/assets/icons/restaurant-black.png b/sale_report_generator/static/description/assets/icons/restaurant-black.png new file mode 100644 index 000000000..4a35eb939 Binary files /dev/null and b/sale_report_generator/static/description/assets/icons/restaurant-black.png differ diff --git a/sale_report_generator/static/description/assets/icons/service-black.png b/sale_report_generator/static/description/assets/icons/service-black.png new file mode 100644 index 000000000..301ab51cb Binary files /dev/null and b/sale_report_generator/static/description/assets/icons/service-black.png differ diff --git a/sale_report_generator/static/description/assets/icons/trading-black.png b/sale_report_generator/static/description/assets/icons/trading-black.png new file mode 100644 index 000000000..9398ba2f1 Binary files /dev/null and b/sale_report_generator/static/description/assets/icons/trading-black.png differ diff --git a/sale_report_generator/static/description/assets/icons/training.png b/sale_report_generator/static/description/assets/icons/training.png new file mode 100644 index 000000000..884ca024d Binary files /dev/null and b/sale_report_generator/static/description/assets/icons/training.png differ diff --git a/sale_report_generator/static/description/assets/icons/update.png b/sale_report_generator/static/description/assets/icons/update.png new file mode 100644 index 000000000..ecbc5a01a Binary files /dev/null and b/sale_report_generator/static/description/assets/icons/update.png differ diff --git a/sale_report_generator/static/description/assets/icons/user.png b/sale_report_generator/static/description/assets/icons/user.png new file mode 100644 index 000000000..6ffb23d9f Binary files /dev/null and b/sale_report_generator/static/description/assets/icons/user.png differ diff --git a/sale_report_generator/static/description/assets/icons/wrench.png b/sale_report_generator/static/description/assets/icons/wrench.png new file mode 100644 index 000000000..6c04dea0f Binary files /dev/null and b/sale_report_generator/static/description/assets/icons/wrench.png differ diff --git a/sale_report_generator/static/description/assets/modules/customer_so_history.png b/sale_report_generator/static/description/assets/modules/customer_so_history.png new file mode 100644 index 000000000..a49d2394c Binary files /dev/null and b/sale_report_generator/static/description/assets/modules/customer_so_history.png differ diff --git a/sale_report_generator/static/description/assets/modules/individual_product_report.png b/sale_report_generator/static/description/assets/modules/individual_product_report.png new file mode 100644 index 000000000..cd5d80e40 Binary files /dev/null and b/sale_report_generator/static/description/assets/modules/individual_product_report.png differ diff --git a/sale_report_generator/static/description/assets/modules/sale_discount_total.png b/sale_report_generator/static/description/assets/modules/sale_discount_total.png new file mode 100644 index 000000000..924a65196 Binary files /dev/null and b/sale_report_generator/static/description/assets/modules/sale_discount_total.png differ diff --git a/sale_report_generator/static/description/assets/modules/sale_report_advanced.png b/sale_report_generator/static/description/assets/modules/sale_report_advanced.png new file mode 100644 index 000000000..1c019bdd8 Binary files /dev/null and b/sale_report_generator/static/description/assets/modules/sale_report_advanced.png differ diff --git a/sale_report_generator/static/description/assets/modules/sale_report_format_editor.png b/sale_report_generator/static/description/assets/modules/sale_report_format_editor.png new file mode 100644 index 000000000..c58491994 Binary files /dev/null and b/sale_report_generator/static/description/assets/modules/sale_report_format_editor.png differ diff --git a/sale_report_generator/static/description/assets/modules/sales_order_delivery_status.png b/sale_report_generator/static/description/assets/modules/sales_order_delivery_status.png new file mode 100644 index 000000000..94c023fe1 Binary files /dev/null and b/sale_report_generator/static/description/assets/modules/sales_order_delivery_status.png differ diff --git a/sale_report_generator/static/description/assets/screenshots/sale.gif b/sale_report_generator/static/description/assets/screenshots/sale.gif new file mode 100644 index 000000000..1670491ef Binary files /dev/null and b/sale_report_generator/static/description/assets/screenshots/sale.gif differ diff --git a/sale_report_generator/static/description/assets/screenshots/sale_report1.png b/sale_report_generator/static/description/assets/screenshots/sale_report1.png new file mode 100644 index 000000000..ced1d1219 Binary files /dev/null and b/sale_report_generator/static/description/assets/screenshots/sale_report1.png differ diff --git a/sale_report_generator/static/description/assets/screenshots/sale_report2.png b/sale_report_generator/static/description/assets/screenshots/sale_report2.png new file mode 100644 index 000000000..6febaf007 Binary files /dev/null and b/sale_report_generator/static/description/assets/screenshots/sale_report2.png differ diff --git a/sale_report_generator/static/description/assets/screenshots/sale_report3.png b/sale_report_generator/static/description/assets/screenshots/sale_report3.png new file mode 100644 index 000000000..76fb26ff8 Binary files /dev/null and b/sale_report_generator/static/description/assets/screenshots/sale_report3.png differ diff --git a/sale_report_generator/static/description/assets/screenshots/sale_report4.png b/sale_report_generator/static/description/assets/screenshots/sale_report4.png new file mode 100644 index 000000000..ee0829a43 Binary files /dev/null and b/sale_report_generator/static/description/assets/screenshots/sale_report4.png differ diff --git a/sale_report_generator/static/description/assets/screenshots/sale_report5.png b/sale_report_generator/static/description/assets/screenshots/sale_report5.png new file mode 100644 index 000000000..db91cb11a Binary files /dev/null and b/sale_report_generator/static/description/assets/screenshots/sale_report5.png differ diff --git a/sale_report_generator/static/description/assets/screenshots/sale_report6.png b/sale_report_generator/static/description/assets/screenshots/sale_report6.png new file mode 100644 index 000000000..58e8a14b7 Binary files /dev/null and b/sale_report_generator/static/description/assets/screenshots/sale_report6.png differ diff --git a/sale_report_generator/static/description/assets/screenshots/sale_report7.png b/sale_report_generator/static/description/assets/screenshots/sale_report7.png new file mode 100644 index 000000000..e68cd0ed4 Binary files /dev/null and b/sale_report_generator/static/description/assets/screenshots/sale_report7.png differ diff --git a/sale_report_generator/static/description/banner.png b/sale_report_generator/static/description/banner.png new file mode 100644 index 000000000..915005b21 Binary files /dev/null and b/sale_report_generator/static/description/banner.png differ diff --git a/sale_report_generator/static/description/icon.png b/sale_report_generator/static/description/icon.png new file mode 100644 index 000000000..b65fb14b5 Binary files /dev/null and b/sale_report_generator/static/description/icon.png differ diff --git a/sale_report_generator/static/description/index.html b/sale_report_generator/static/description/index.html new file mode 100644 index 000000000..1fb09296f --- /dev/null +++ b/sale_report_generator/static/description/index.html @@ -0,0 +1,620 @@ +
+ +
+
+
+ +
+
+
+ Community +
+
+ Enterprise +
+ +
+
+
+
+ +
+
+
+

+ Sales All In One Report Generator

+

+ Dynamic Sales Report Maker +

+ +
+
+ + + + +
+
+

+ Overview +

+
+ +
+

+ This app useful to provide different Sales Reports to do analysis. It shows the sales analysis of a company in many aspects such as by order,order details,salesman and so on. It can be filtered out based on different date ranges too.

+ +
+
+ + +
+
+

+ Features +

+
+ +
+
+ +
+
+

+ Community & Enterprise Support

+

+ Available in Odoo 15.0 Community and Enterprise.

+
+
+
+
+ +
+
+

+ Generates Report for a specific date range.

+
+
+ +
+
+ +
+
+

+ Filtering based on different aspects

+
+
+ +
+
+ +
+
+

+ Print Reports in both PDF and XLSX format.

+
+
+ +
+
+ +
+
+

+ Drilled on approach

+
+
+ +
+ +
+
+

+ Screenshots +

+
+
+

+ All In One Sales Report Menu

+ +
+ +
+

+ Sales Report Based On Orders

+ +
+ +
+

+ Sales Report Based On Order Details

+ + +
+ +
+

+ Sale Report Based On Product

+ +
+
+

+ Sales Report Based On Categories

+ +
+
+

+ Sales Report Based On Sales Person

+ +
+
+

+ Sales Report Based On State

+ +
+ +
+ + +
+
+

Suggested Products

+
+ + +
+
+ + + +
+
+
+

Our Services

+
+
+ +
+
+ +
+
+ Odoo + Customization
+
+ +
+
+ +
+
+ Odoo + Implementation
+
+ +
+
+ +
+
+ Odoo + Support
+
+ + +
+
+ +
+
+ Hire + Odoo + Developer
+
+ +
+
+ +
+
+ Odoo + Integration
+
+ +
+
+ +
+
+ Odoo + Migration
+
+ + +
+
+ +
+
+ Odoo + Consultancy
+
+ +
+
+ +
+
+ Odoo + Implementation
+
+ +
+
+ +
+
+ Odoo + Licensing Consultancy
+
+
+
+ + + +
+
+
+

Our Industries

+
+
+ +
+
+ +
+ Trading +
+

+ Easily procure + and + sell your products

+
+
+ +
+
+ +
+ POS +
+

+ Easy + configuration + and convivial experience

+
+
+ +
+
+ +
+ Education +
+

+ A platform for + educational management

+
+
+ +
+
+ +
+ Manufacturing +
+

+ Plan, track and + schedule your operations

+
+
+ +
+
+ +
+ E-commerce & Website +
+

+ Mobile + friendly, + awe-inspiring product pages

+
+
+ +
+
+ +
+ Service Management +
+

+ Keep track of + services and invoice

+
+
+ +
+
+ +
+ Restaurant +
+

+ Run your bar or + restaurant methodically

+
+
+ +
+
+ +
+ Hotel Management +
+

+ An + all-inclusive + hotel management application

+
+
+ +
+
+ + + + + +
+
+
+

Need Help?

+
+
+
+ + +
+ +
+ +
+ +
+ WhatsApp +
+
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+
+
+ + +
diff --git a/sale_report_generator/static/src/css/sale_report.css b/sale_report_generator/static/src/css/sale_report.css new file mode 100644 index 000000000..375093a35 --- /dev/null +++ b/sale_report_generator/static/src/css/sale_report.css @@ -0,0 +1,56 @@ +.time_range_sale { + width: 125px; + border: 2px solid #ccc; + border-radius: 5px; + padding: 10px; +} +.apply_sale{ + +} + +a.dropdown-toggle.report-type { + margin: 10px; + +} +.search-Result-Selection { + border: 2px solid #ccc; + margin-right: 30px; + margin-left: 10px; + border-radius: 10px; +} +.table_sale_head { + background-color: #7c7bad; + color: #fff; + padding: 20px; + margin: 20px; + height: 57px; + width: 100%; + border: 1px solid #000; +} +element.style { + top: 0px; + height: 42px; + color: white; + background-color: #7c7bad; + border-color: #7c7bad; + width: 100px; +} +tr.so-line { + height: 48px; +} +tr.table_sale_head th { + font-size: 18px; + text-align: center; +} +ul.dropdown-menu.show { + height: 40px; + background-color: #eeeeee; + width: 200px; +} +ul.dropdown-menu.show li { + margin-left: 10px; +} + +ul.dropdown-menu.show a{ + color: #221c1c; +} \ No newline at end of file diff --git a/sale_report_generator/static/src/js/sale_report.js b/sale_report_generator/static/src/js/sale_report.js new file mode 100644 index 000000000..0317ab18f --- /dev/null +++ b/sale_report_generator/static/src/js/sale_report.js @@ -0,0 +1,236 @@ +odoo.define('sale_report_generator.sale_report', function(require) { + 'use strict'; + var AbstractAction = require('web.AbstractAction'); + var core = require('web.core'); + var rpc = require('web.rpc'); + var QWeb = core.qweb; + var _t = core._t; + var datepicker = require('web.datepicker'); + var time = require('web.time'); + var framework = require('web.framework'); + var session = require('web.session'); + + var SaleReport = AbstractAction.extend({ + template: 'SaleReport', + events: { + 'click #apply_filter': 'apply_filter', + 'click #pdf': 'print_pdf', + 'click #xlsx': 'print_xlsx', + 'click .view_sale_order': 'button_view_order', + 'mousedown div.input-group.date[data-target-input="nearest"]': '_onCalendarIconClick', + + + }, + + + init: function(parent, action) { + this._super(parent, action); + this.report_lines = action.report_lines; + this.wizard_id = action.context.wizard | null; + + }, + start: function() { + var self = this; + self.initial_render = true; + + rpc.query({ + model: 'sales.report', + method: 'create', + args: [{ + + }] + }).then(function(res) { + self.wizard_id = res; + self.load_data(self.initial_render); + self.apply_filter(); + }) + }, + + _onCalendarIconClick: function(ev) { + var $calendarInputGroup = $(ev.currentTarget); + + var calendarOptions = { + + minDate: moment({ + y: 1000 + }), + maxDate: moment().add(200, 'y'), + calendarWeeks: true, + defaultDate: moment().format(), + sideBySide: true, + buttons: { + showClear: true, + showClose: true, + showToday: true, + }, + + icons: { + date: 'fa fa-calendar', + + }, + locale: moment.locale(), + format: time.getLangDateFormat(), + widgetParent: 'body', + allowInputToggle: true, + }; + + $calendarInputGroup.datetimepicker(calendarOptions); + }, + + + load_data: function(initial_render = true) { + var self = this; + self._rpc({ + model: 'sales.report', + method: 'sale_report', + args: [ + [this.wizard_id] + ], + }).then(function(datas) { + if (initial_render) { + self.$('.filter_view_sr').html(QWeb.render('saleFilterView', { + filter_data: datas['filters'], + + })); + self.$el.find('.report_type').select2({ + placeholder: ' Report Type...', + }); + + } + + if (datas['orders']) + self.$('.table_view_sr').html(QWeb.render('SaleOrderTable', { + filter: datas['filters'], + order: datas['orders'], + report_lines: datas['report_lines'], + main_lines: datas['report_main_line'] + + })); + }) + }, + + print_pdf: function(e) { + e.preventDefault(); + var self = this; + var action_title = self._title; + self._rpc({ + model: 'sales.report', + method: 'sale_report', + args: [ + [self.wizard_id] + ], + }).then(function(data) { + var action = { + 'type': 'ir.actions.report', + 'report_type': 'qweb-pdf', + 'report_name': 'sale_report_generator.sale_order_report', + 'report_file': 'sale_report_generator.sale_order_report', + 'data': { + 'report_data': data + }, + 'context': { + 'active_model': 'sales.report', + 'landscape': 1, + 'sale_order_report': true + + }, + 'display_name': 'Sale Order', + }; + return self.do_action(action); + }); + + }, + print_xlsx: function() { + var self = this; + self._rpc({ + model: 'sales.report', + method: 'sale_report', + args: [ + [self.wizard_id] + ], + }).then(function(data) { + + var action = { + 'data': { + 'model': 'sales.report', + 'options': JSON.stringify(data['orders']), + 'output_format': 'xlsx', + 'report_data': JSON.stringify(data['report_lines']), + 'report_name': 'Sale Report', + 'dfr_data': JSON.stringify(data), + }, + }; + self.downloadXlsx(action); + + }); + }, + + downloadXlsx: function (action){ + framework.blockUI(); + session.get_file({ + url: '/sale_dynamic_xlsx_reports', + data: action.data, + complete: framework.unblockUI, + error: (error) => this.call('crash_manager', 'rpc_error', error), + }); + }, +// + button_view_order: function(event) { + event.preventDefault(); + var self = this; + var context = {}; + this.do_action({ + name: _t("Sale Order"), + type: 'ir.actions.act_window', + res_model: 'sale.order', + view_type: 'form', + domain: [ + ['id', '=', $(event.target).closest('.view_sale_order').attr('id')] + ], + views: [ + [false, 'list'], + [false, 'form'] + ], + target: 'current' + }); + }, + // + apply_filter: function() { + var self = this; + self.initial_render = false; + + var filter_data_selected = {}; + + if (this.$el.find('.datetimepicker-input[name="date_from"]').val()) { + filter_data_selected.date_from = moment(this.$el.find('.datetimepicker-input[name="date_from"]').val(), time.getLangDateFormat()).locale('en').format('YYYY-MM-DD'); + } + + if (this.$el.find('.datetimepicker-input[name="date_to"]').val()) { + filter_data_selected.date_to = moment(this.$el.find('.datetimepicker-input[name="date_to"]').val(), time.getLangDateFormat()).locale('en').format('YYYY-MM-DD'); + } + if ($(".report_type").length) { + var report_res = document.getElementById("report_res") + filter_data_selected.report_type = $(".report_type")[1].value + report_res.value = $(".report_type")[1].value + report_res.innerHTML = report_res.value; + if ($(".report_type")[1].value == "") { + report_res.innerHTML = "report_by_order"; + + } + } + rpc.query({ + model: 'sales.report', + method: 'write', + args: [ + self.wizard_id, filter_data_selected + ], + }).then(function(res) { + self.initial_render = false; + self.load_data(self.initial_render); + }); + }, + + }); + core.action_registry.add("s_r", SaleReport); + return SaleReport; +}); \ No newline at end of file diff --git a/sale_report_generator/static/src/xml/sale_report_view.xml b/sale_report_generator/static/src/xml/sale_report_view.xml new file mode 100644 index 000000000..9591f013d --- /dev/null +++ b/sale_report_generator/static/src/xml/sale_report_view.xml @@ -0,0 +1,486 @@ + + +
+
+
+

Sales Dynamic Report

+
+
+
+
+
+
+
+
+
+ + + +
+
+
+ + +
+
+

+
+
+ + + Date Range + + +
+
+ + + Report Type: + + + +
+
+ +
+
+
+
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
SaleDate OrderCustomerSales PersonTotal QtyAmount Total
+ + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
SaleDate OrderCustomerCompanySales PersonProduct NameProduct CodeQuantityPrice SubtotalAmount Total
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
ProductCategoryProduct CodeQuantityAmount Total
+ + + + + + + + + + + + + + + + + + + + +
+
+
+ + +
+
+ + + + + + + + + + + + + + + + + + +
CategoryQtyAmount Total
+ + + + + + + + + + + + +
+
+
+ + +
+
+ + + + + + + + + + + + + + + + + + + + +
Sales PersonTotal OrderTotal QtyTotal Amount
+ + + + + + + + + + + + + + + + +
+
+
+ + + +
+
+ + + + + + + + + + + + + + + + + + + +
StateTotal CountQuantityAmount
+ + + + + + + + + + + + + + + + +
+
+
+
+ diff --git a/sale_report_generator/views/sale_report.xml b/sale_report_generator/views/sale_report.xml new file mode 100644 index 000000000..bab1a3239 --- /dev/null +++ b/sale_report_generator/views/sale_report.xml @@ -0,0 +1,12 @@ + + + + Sales Report + s_r + + + + + \ No newline at end of file