diff --git a/sale_purchase_mixed_report/README.rst b/sale_purchase_mixed_report/README.rst new file mode 100644 index 000000000..76b894e97 --- /dev/null +++ b/sale_purchase_mixed_report/README.rst @@ -0,0 +1,42 @@ +.. image:: https://img.shields.io/badge/license-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +Sale Purchase mixed Report V15 +============================== +Provides mixed reports related to Sales and Purchase in both Sales and Purchase. +Reports are provided in Pivot view and Graph view. Pdf and Excel reports can be printed. + +Configuration +============= +The users should be in any of the Administration security groups to view the Reporting menu from Sales and Purchase. + +Company +------- +* `Cybrosys Techno Solutions `__ + +Credits +------- +Developer: Mohammed Ajmal P @cybrosys, Contact: odoo@cybrosys.com + version 15: Mohammed Ajmal P @cybrosys, Contact: odoo@cybrosys.com + +Contacts +-------- +* Mail Contact : odoo@cybrosys.com +* Website : https://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 +========== +.. image:: https://cybrosys.com/images/logo.png + :target: https://cybrosys.com +This module is maintained by Cyborsys Technologies. + +For support and more information, please visit https://www.cybrosys.com + +Further information +=================== +HTML Description: ``__ diff --git a/sale_purchase_mixed_report/__init__.py b/sale_purchase_mixed_report/__init__.py new file mode 100644 index 000000000..71ef5e4f9 --- /dev/null +++ b/sale_purchase_mixed_report/__init__.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +################################################################################ +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2022-TODAY Cybrosys Technologies(). +# Author: Mohammed Ajmal P (odoo@cybrosys.com) +# +# You can modify it under the terms of the GNU AFFERO +# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. +# +# This program is distributes 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 this program. +# If not, see . +# +################################################################################ + +from . import models +from . import reports +from . import wizards +from . import controllers diff --git a/sale_purchase_mixed_report/__manifest__.py b/sale_purchase_mixed_report/__manifest__.py new file mode 100644 index 000000000..b29428f9b --- /dev/null +++ b/sale_purchase_mixed_report/__manifest__.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +################################################################################ +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2022-TODAY Cybrosys Technologies(). +# Author: Mohammed Ajmal P (odoo@cybrosys.com) +# +# You can modify it under the terms of the GNU AFFERO +# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. +# +# This program is distributes 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 this program. +# If not, see . +# +################################################################################ +{ + 'name': "Sale Purchase mixed Report", + 'summary': """Mixed reports of Sale and Purchase data""", + 'description': """Mixed reports of Sale and Purchase data""", + 'category': 'Technical', + 'version': '15.0.1.0.0', + 'author': 'Cybrosys Techno Solutions', + 'company': 'Cybrosys Techno Solutions', + 'maintainer': 'Cybrosys Techno Solutions', + 'website': 'https://www.cybrosys.com', + 'images': ['static/description/banner.png'], + 'depends': ['base', 'sale', 'purchase', 'stock'], + 'data': [ + 'security/ir.model.access.csv', + 'reports/sale_purchase_report_views.xml', + 'reports/sale_purchase_pdf_template.xml', + 'wizards/wizard_views.xml', + ], + 'assets': { + 'web.assets_backend': [ + '/sale_purchase_mixed_report/static/src/js/action_manager.js', + ], + }, + 'license': 'AGPL-3', + 'installable': True, + 'auto_install': False, + 'application': False, +} diff --git a/sale_purchase_mixed_report/controllers/__init__.py b/sale_purchase_mixed_report/controllers/__init__.py new file mode 100644 index 000000000..763deba03 --- /dev/null +++ b/sale_purchase_mixed_report/controllers/__init__.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +################################################################################ +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2022-TODAY Cybrosys Technologies(). +# Author: Mohammed Ajmal P (odoo@cybrosys.com) +# +# You can modify it under the terms of the GNU AFFERO +# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. +# +# This program is distributes 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 this program. +# If not, see . +# +################################################################################ + +from . import main diff --git a/sale_purchase_mixed_report/controllers/main.py b/sale_purchase_mixed_report/controllers/main.py new file mode 100644 index 000000000..b5af27968 --- /dev/null +++ b/sale_purchase_mixed_report/controllers/main.py @@ -0,0 +1,58 @@ +# -*- coding: utf-8 -*- +################################################################################ +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2022-TODAY Cybrosys Technologies(). +# Author: Mohammed Ajmal P (odoo@cybrosys.com) +# +# You can modify it under the terms of the GNU AFFERO +# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. +# +# This program is distributes 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 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 XLSXReportController(http.Controller): + """Controller Class for xlsx report""" + + @http.route('/xlsx_reports', type='http', auth='user', methods=['POST'], + csrf=False) + def get_report_xlsx(self, model, options, output_format, report_name, **kw): + """Method for passing data to xlsx report""" + uid = request.session.uid + report_obj = request.env[model].with_user(uid) + options = json.loads(options) + token = 'dummy-because-api-expects-one' + try: + if output_format == 'xlsx_controller': + response = request.make_response( + None, + headers=[('Content-Type', 'application/vnd.ms-excel'), ( + 'Content-Disposition', + content_disposition(report_name + '.xlsx'))]) + report_obj.get_xlsx_report(options, response) + response.set_cookie('fileToken', token) + return response + except Exception as err: + exception = _serialize_exception(err) + error = { + 'code': 200, + 'message': 'Odoo Server Error', + 'data': exception + } + return request.make_response(html_escape(json.dumps(error))) diff --git a/sale_purchase_mixed_report/doc/RELEASE_NOTES.md b/sale_purchase_mixed_report/doc/RELEASE_NOTES.md new file mode 100644 index 000000000..c649cd557 --- /dev/null +++ b/sale_purchase_mixed_report/doc/RELEASE_NOTES.md @@ -0,0 +1,6 @@ +## Module + +#### 14.05.2022 +#### Version 15.0.1.0.0 +##### ADD +- Initial commit for Sale Purchase mixed Report diff --git a/sale_purchase_mixed_report/models/__init__.py b/sale_purchase_mixed_report/models/__init__.py new file mode 100644 index 000000000..dbbdf2eb7 --- /dev/null +++ b/sale_purchase_mixed_report/models/__init__.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +################################################################################ +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2022-TODAY Cybrosys Technologies(). +# Author: Mohammed Ajmal P (odoo@cybrosys.com) +# +# You can modify it under the terms of the GNU AFFERO +# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. +# +# This program is distributes 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 this program. +# If not, see . +# +################################################################################ +from . import sale +from . import purchase diff --git a/sale_purchase_mixed_report/models/purchase.py b/sale_purchase_mixed_report/models/purchase.py new file mode 100644 index 000000000..b0dd08b33 --- /dev/null +++ b/sale_purchase_mixed_report/models/purchase.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +################################################################################ +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2022-TODAY Cybrosys Technologies(). +# Author: Mohammed Ajmal P (odoo@cybrosys.com) +# +# You can modify it under the terms of the GNU AFFERO +# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. +# +# This program is distributes 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 this program. +# If not, see . +# +################################################################################ + +from odoo import fields, models + + +class PurchaseOrder(models.Model): + """Field to identify the type of Order in to Sale Purchase Report""" + _inherit = 'purchase.order' + + is_purchase_order = fields.Boolean(default=True) diff --git a/sale_purchase_mixed_report/models/sale.py b/sale_purchase_mixed_report/models/sale.py new file mode 100644 index 000000000..44b90dd17 --- /dev/null +++ b/sale_purchase_mixed_report/models/sale.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +################################################################################ +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2022-TODAY Cybrosys Technologies(). +# Author: Mohammed Ajmal P (odoo@cybrosys.com) +# +# You can modify it under the terms of the GNU AFFERO +# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. +# +# This program is distributes 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 this program. +# If not, see . +# +################################################################################ + +from odoo import fields, models + + +class SaleOrder(models.Model): + """Field to identify the type of Order in to Sale Purchase Report""" + _inherit = 'sale.order' + + is_sale_order = fields.Boolean(default=True) diff --git a/sale_purchase_mixed_report/reports/__init__.py b/sale_purchase_mixed_report/reports/__init__.py new file mode 100644 index 000000000..598a5fbc6 --- /dev/null +++ b/sale_purchase_mixed_report/reports/__init__.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +################################################################################ +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2022-TODAY Cybrosys Technologies(). +# Author: Mohammed Ajmal P (odoo@cybrosys.com) +# +# You can modify it under the terms of the GNU AFFERO +# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. +# +# This program is distributes 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 this program. +# If not, see . +# +################################################################################ +from . import sale_purchase_report +from . import sale_purchase_pdf_report diff --git a/sale_purchase_mixed_report/reports/sale_purchase_pdf_report.py b/sale_purchase_mixed_report/reports/sale_purchase_pdf_report.py new file mode 100644 index 000000000..a08320bb2 --- /dev/null +++ b/sale_purchase_mixed_report/reports/sale_purchase_pdf_report.py @@ -0,0 +1,272 @@ +# -*- coding: utf-8 -*- +################################################################################ +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2022-TODAY Cybrosys Technologies(). +# Author: Mohammed Ajmal P (odoo@cybrosys.com) +# +# You can modify it under the terms of the GNU AFFERO +# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. +# +# This program is distributes 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 this program. +# If not, see . +# +################################################################################ + +from odoo import fields, models, api + + +class SalePurchasePdfReport(models.AbstractModel): + """Class for PDF Report""" + _name = 'report.sale_purchase_mixed_report.report_sale_purchase' + _description = 'Sale Purchase mixed Pdf Report' + + @api.model + def _get_report_values(self, docids, data=None): + """Returns PDF Report Values to template""" + company_id = self.env.company + where_sale = """so.company_id = %s""" % ( + company_id.id) + where_purchase = """po.company_id = %s""" % ( + company_id.id) + if data['form']['date_from']: + where_sale += """AND so.date_order >= '%s'""" % ( + data['form']['date_from']) + where_purchase += """AND po.date_order >= '%s'""" % ( + data['form']['date_from']) + if data['form']['date_to']: + where_sale += """AND so.date_order <= '%s'""" % ( + data['form']['date_to']) + where_purchase += """AND po.date_order <= '%s'""" % ( + data['form']['date_to']) + if data['form']['partner_ids']: + if len(data['form']['partner_ids']) == 1: + where_sale += """AND so.partner_id = %s""" % ( + data['form']['partner_ids'][0]) + where_purchase += """AND po.partner_id = %s""" % ( + data['form']['partner_ids'][0]) + else: + where_sale += """AND so.partner_id in %s""" % ( + str(tuple(data['form']['partner_ids']))) + where_purchase += """AND po.partner_id in %s""" % ( + str(tuple(data['form']['partner_ids']))) + if data['form']['sale_order_ids']: + if len(data['form']['sale_order_ids']) == 1: + where_sale += """AND so.id = %s""" % ( + data['form']['sale_order_ids'][0]) + else: + where_sale += """AND so.id in %s""" % ( + str(tuple(data['form']['sale_order_ids']))) + if data['form']['purchase_order_ids']: + if len(data['form']['purchase_order_ids']) == 1: + where_purchase += """AND po.id = %s""" % ( + data['form']['purchase_order_ids'][0]) + else: + where_purchase += """AND po.id in %s""" % ( + str(tuple(data['form']['purchase_order_ids']))) + self.env.cr.execute(""" + select macro.id as id, + macro.order_type as order_type, + macro.order_state as order_state, + macro.order_date as order_date, + macro.partner_id as partner_id, + macro.product_id as product_id, + macro.order_ref as order_ref, + macro.unit_price_sale as unit_price_sale, + macro.unit_price_purchase as unit_price_purchase, + macro.price_total_sale as price_total_sale, + macro.price_total_purchase as price_total_purchase, + macro.price_subtotal_sale as price_subtotal_sale, + macro.price_subtotal_purchase as price_subtotal_purchase, + macro.product_type as product_type, + macro.qty_invoiced as qty_invoiced, + macro.qty_billed as qty_billed, + macro.qty_ordered_to as qty_ordered_to, + macro.qty_ordered_by as qty_ordered_by, + macro.qty_delivered as qty_delivered, + macro.qty_received as qty_received, + macro.company_id as company_id, + macro.product_uom as product_uom + from(( + with currency_rate as (%s)""" % self.env[ + 'res.currency']._select_companies_rates() + + """ + select + po.id as id, + po.date_order as order_date, + po.partner_id as partner_id, + po.company_id as company_id, + po.currency_id, + t.uom_id as product_uom, + case + when po.state='draft' then 'draft_rfq' + when po.state='sent' then 'rfq_sent' + when po.state='to_approve' then 'to_approve' + when po.state='purchase' then 'purchase' + when po.state='done' then 'done' else + 'cancel' end as order_state, + case when po.is_purchase_order=True then + 'Purchase' else '' end as order_type, + l.product_id as product_id, + t.detailed_type as product_type, + po.name as order_ref, + 0 as unit_price_sale, + case when l.product_id is not null then + sum(l.price_unit) + else 0 end as unit_price_purchase, + 0 as price_total_sale, + sum(l.price_total / coalesce(po.currency_rate, 1.0))::decimal(16,2) * currency_table.rate as price_total_purchase, + 0 as price_subtotal_sale, + sum(l.price_subtotal / coalesce(po.currency_rate, 1.0))::decimal(16, 2) * currency_table.rate as price_subtotal_purchase, + case when l.product_id is not null then + sum(l.product_qty/ u.factor * u2.factor) else 0 + end as qty_ordered_to, + case when l.product_id is not null then + sum(l.qty_received / u.factor * u2.factor) + else 0 end as qty_received, + case when l.product_id is not null then + sum(l.qty_invoiced / u.factor * u2.factor) + else 0 end as qty_billed, + 0 as qty_ordered_by, + 0 as qty_delivered, + 0 as qty_invoiced + from + (purchase_order_line l + join purchase_order po on (l.order_id=po.id) + join res_partner partner on (po.partner_id=partner.id) + left join product_product p on (l.product_id=p.id) + left join product_template t on (p.product_tmpl_id=t.id) + left join uom_uom u on (l.product_uom=u.id) + left join uom_uom u2 on (t.uom_id=u2.id)) + left join currency_rate cr on + (cr.currency_id = po.currency_id + and cr.company_id = po.company_id and + cr.date_start <= coalesce(po.date_order, now()) + and (cr.date_end is null or cr.date_end > coalesce(po.date_order, now()))) + left join {currency_table} on + currency_table.company_id = po.company_id + """.format( + currency_table=self.env[ + 'res.currency']._get_query_currency_table( + {'multi_company': True, + 'date': { + 'date_to': fields.Date.today()}}), ) + + """ + where %s + group by + po.partner_id, + po.date_order, + l.product_id, + t.uom_id, + t.detailed_type, + po.id, + currency_table.rate + order by l.product_id) + UNION ALL + (select + so.id as id, + so.date_order as order_date, + so.partner_id as partner_id, + so.company_id as company_id, + so.currency_id, + t.uom_id as product_uom, + case + when so.state='draft' then 'draft_sale' + when so.state='sent' then 'sent_sale' + when so.state='sale' then 'sale' + when so.state='done' then 'done' else + 'cancel' end as order_state, + case when so.is_sale_order=True then + 'Sale' else '' end as order_type, + s.product_id as product_id, + t.detailed_type as product_type, + so.name as order_ref, + case when s.product_id is not null + then sum(s.price_unit) + else 0 end as unit_price_sale, + 0 as unit_price_purchase, + case when s.product_id is not null then + sum(s.price_total / case coalesce(so.currency_rate, 0) + when 0 then 1.0 else so.currency_rate end) else + 0 end as price_total_sale, + 0 as price_total_purchase, + case when s.product_id is not null then + sum(s.price_subtotal / case coalesce(so.currency_rate, 0) + when 0 then 1.0 else so.currency_rate end) else + 0 end as price_subtotal_sale, + 0 as price_subtotal_purchase, + 0 as qty_ordered_to, + 0 as qty_received, + 0 as qty_billed, + case when s.product_id is not null + then sum(s.product_uom_qty / u.factor * u2.factor) else 0 end as + qty_ordered_by, + case when s.product_id is not null + then sum(s.qty_delivered / u.factor * u2.factor) else 0 end as + qty_delivered, + case when s.product_id is not null + then sum(s.qty_invoiced / u.factor * u2.factor) else 0 end as + qty_invoiced + from + (sale_order_line s + join sale_order so on + (s.order_id=so.id) + join res_partner partner on + (so.partner_id=partner.id) + left join product_product p on + (s.product_id=p.id) + left join product_template t on + (p.product_tmpl_id=t.id) + left join uom_uom u on + (s.product_uom=u.id) + left join uom_uom u2 on + (t.uom_id=u2.id)) + where %s + group by + so.partner_id, + so.date_order, + s.product_id, + t.uom_id, + t.detailed_type, + so.id + order by s.product_id)) + macro + group by + macro.partner_id, + macro.order_date, + macro.order_state, + macro.product_id, + macro.id, + macro.order_ref, + macro.order_type, + macro.unit_price_sale, + macro.unit_price_purchase, + macro.product_type, + macro.qty_invoiced, + macro.qty_billed, + macro.qty_delivered, + macro.qty_received, + macro.qty_ordered_to, + macro.qty_ordered_by, + macro.price_total_sale, + macro.price_total_purchase, + macro.price_subtotal_sale, + macro.price_subtotal_purchase, + macro.company_id, + macro.currency_id, + macro.product_uom + order by macro.product_id""" % ( + where_purchase, where_sale)) + rec = self.env.cr.fetchall() + return { + 'docs': rec, + 'date_from': data['form']['date_from'], + 'date_to': data['form']['date_to'], + } diff --git a/sale_purchase_mixed_report/reports/sale_purchase_pdf_template.xml b/sale_purchase_mixed_report/reports/sale_purchase_pdf_template.xml new file mode 100644 index 000000000..c0df88799 --- /dev/null +++ b/sale_purchase_mixed_report/reports/sale_purchase_pdf_template.xml @@ -0,0 +1,151 @@ + + + + \ No newline at end of file diff --git a/sale_purchase_mixed_report/reports/sale_purchase_report.py b/sale_purchase_mixed_report/reports/sale_purchase_report.py new file mode 100644 index 000000000..82086388f --- /dev/null +++ b/sale_purchase_mixed_report/reports/sale_purchase_report.py @@ -0,0 +1,334 @@ +# -*- coding: utf-8 -*- +################################################################################ +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2022-TODAY Cybrosys Technologies(). +# Author: Mohammed Ajmal P (odoo@cybrosys.com) +# +# You can modify it under the terms of the GNU AFFERO +# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. +# +# This program is distributes 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 this program. +# If not, see . +# +################################################################################ + +from odoo import fields, models, tools + + +class SalePurchaseReport(models.Model): + """Fields and Functions for graph and pivot view""" + _name = 'sale.purchase.report' + _description = 'Sale Purchase Report' + _order = 'order_date desc' + _auto = False + + product_tmpl_id = fields.Many2one('product.template', string='Product', + readonly=True) + product_id = fields.Many2one('product.product', string='Variant', + readonly=True) + partner_id = fields.Many2one('res.partner', string='Partner', readonly=True) + product_type = fields.Selection( + [('cosnsu', 'Consumable'), ('service', 'Service'), + ('product', 'Product')]) + category_id = fields.Many2one('product.category', 'Product Category', + readonly=True) + qty_invoiced = fields.Float(string='Qty Invoiced', readonly=True) + qty_billed = fields.Float(string='Qty Billed', readonly=True) + qty_delivered = fields.Float(string='Qty Delivered', readonly=True) + qty_received = fields.Float(string='Qty Received', readonly=True) + qty_ordered_by = fields.Float('Qty Ordered by Customer', readonly=True) + qty_ordered_to = fields.Float('Qty Ordered to Vendor', readonly=True) + qty_to_deliver = fields.Float('Qty to Deliver', readonly=True) + qty_to_receive = fields.Float('Qty to Receive', readonly=True) + qty_to_invoice = fields.Float('Qty to Invoice', readonly=True) + qty_to_bill = fields.Float('Qty to Bill', readonly=True) + unit_price_sale = fields.Float(string='Unit Price Sale', readonly=True) + unit_price_purchase = fields.Float(string='Unit Price Purchase', + readonly=True) + order_type = fields.Char('Order Type', readonly=True) + order_date = fields.Datetime('Order Date', readonly=True) + order_ref = fields.Char('Order Reference', readonly=True) + order_state = fields.Selection( + [('draft_sale', 'Quotation'), ('draft_rfq', 'RFQ'), + ('sent_sale', 'Quotation Sent'), ('rfq_sent', 'RFQ Sent'), + ('to_approve', 'To Approve'), + ('sale', 'Sale Order'), ('purchase', 'Purchase Order'), + ('done', 'Done'), + ('cancel', 'Cancelled')], string='Order Status') + company_id = fields.Many2one('res.company', 'Company', readonly=True) + price_total_sale = fields.Float('Total Sale', readonly=True) + price_total_purchase = fields.Float('Total Purchase', readonly=True) + price_subtotal_sale = fields.Float('Untaxed Total Sale', readonly=True) + price_subtotal_purchase = fields.Float('Untaxed Total Purchase', + readonly=True) + user_id = fields.Many2one('res.users', 'Representative', readonly=True) + currency_id = fields.Many2one('res.currency', 'Currency', readonly=True) + weight_sale = fields.Float('Gross Weight Sale', readonly=True) + weight_purchase = fields.Float('Gross Weight Purchase', readonly=True) + volume_sale = fields.Float('Volume Sale', readonly=True) + volume_purchase = fields.Float('Volume Purchase', readonly=True) + product_uom = fields.Many2one('uom.uom', 'Unit of Measure', required=True) + + def init(self): + tools.drop_view_if_exists(self._cr, 'sale_purchase_report') + self._cr.execute(""" + CREATE or REPLACE VIEW sale_purchase_report as( + select macro.id as id, + macro.order_type as order_type, + macro.order_state as order_state, + macro.order_date as order_date, + macro.partner_id as partner_id, + macro.product_id as product_id, + macro.product_tmpl_id as product_tmpl_id, + macro.order_ref as order_ref, + macro.unit_price_sale as unit_price_sale, + macro.unit_price_purchase as unit_price_purchase, + macro.price_total_sale as price_total_sale, + macro.price_total_purchase as price_total_purchase, + macro.price_subtotal_sale as price_subtotal_sale, + macro.price_subtotal_purchase as price_subtotal_purchase, + macro.product_type as product_type, + macro.qty_invoiced as qty_invoiced, + macro.qty_billed as qty_billed, + macro.qty_ordered_to as qty_ordered_to, + macro.qty_ordered_by as qty_ordered_by, + macro.qty_delivered as qty_delivered, + macro.qty_received as qty_received, + macro.qty_to_invoice as qty_to_invoice, + macro.qty_to_bill as qty_to_bill, + macro.qty_to_deliver as qty_to_deliver, + macro.qty_to_receive as qty_to_receive, + macro.company_id as company_id, + macro.currency_id as currency_id, + macro.product_uom as product_uom, + macro.category_id as category_id, + macro.user_id as user_id, + macro.weight_sale as weight_sale, + macro.weight_purchase as weight_purchase, + macro.volume_sale as volume_sale, + macro.volume_purchase as volume_purchase + from(( + with currency_rate as (%s)""" % self.env[ + 'res.currency']._select_companies_rates() + + """ + select + po.id as id, + po.date_order as order_date, + po.partner_id as partner_id, + po.company_id as company_id, + po.currency_id, + t.categ_id as category_id, + t.uom_id as product_uom, + po.user_id as user_id, + case + when po.state='draft' then 'draft_rfq' + when po.state='sent' then 'rfq_sent' + when po.state='to_approve' then 'to_approve' + when po.state='purchase' then 'purchase' + when po.state='done' then 'done' else + 'cancel' end as order_state, + case when po.is_purchase_order=True then + 'Purchase' else '' end as order_type, + l.product_id as product_id, + p.product_tmpl_id as product_tmpl_id, + t.detailed_type as product_type, + po.name as order_ref, + 0 as unit_price_sale, + case when l.product_id is not null then + sum(l.price_unit) else 0 end as unit_price_purchase, + 0 as price_total_sale, + sum(l.price_total / coalesce(po.currency_rate, 1.0))::decimal(16,2) * currency_table.rate as price_total_purchase, + 0 as price_subtotal_sale, + sum(l.price_subtotal / coalesce(po.currency_rate, 1.0))::decimal(16, 2) * currency_table.rate as price_subtotal_purchase, + case when l.product_id is not null then + sum(l.product_qty/ u.factor * u2.factor) else 0 + end as qty_ordered_to, + case when l.product_id is not null then + sum(l.qty_received / u.factor * u2.factor) else 0 + end as qty_received, + case when l.product_id is not null then + sum(l.qty_invoiced / u.factor * u2.factor) + else 0 end as qty_billed, + case when t.purchase_method = 'purchase' then + sum(l.product_qty / u.factor * u2.factor) - sum(l.qty_invoiced / u.factor * u2.factor) + else sum(l.qty_received / u.factor * u2.factor) - sum(l.qty_invoiced / u.factor * u2.factor) + end as qty_to_bill, + case when l.product_id is not null then + sum((l.product_qty - l.qty_received) / u.factor * u2.factor) + else 0 end as qty_to_receive, + 0 as weight_sale, + sum(p.weight * l.product_qty / u.factor * u2.factor) as weight_purchase, + 0 as volume_sale, + sum(p.volume * l.product_qty / u.factor * u2.factor) as volume_purchase, + 0 as qty_ordered_by, + 0 as qty_delivered, + 0 as qty_invoiced, + 0 as qty_to_invoice, + 0 as qty_to_deliver + from + (purchase_order_line l + join purchase_order po on (l.order_id=po.id) + join res_partner partner on + (po.partner_id=partner.id) + left join product_product p on (l.product_id=p.id) + left join product_template t on + (p.product_tmpl_id=t.id) + left join uom_uom u on (l.product_uom=u.id) + left join uom_uom u2 on (t.uom_id=u2.id)) + left join currency_rate cr on + (cr.currency_id = po.currency_id + and cr.company_id = po.company_id and cr.date_start <= coalesce(po.date_order, now()) and + (cr.date_end is null or cr.date_end > coalesce(po.date_order, now()))) + left join {currency_table} on + currency_table.company_id = po.company_id + """.format( + currency_table=self.env[ + 'res.currency']._get_query_currency_table( + {'multi_company': True, + 'date': { + 'date_to': fields.Date.today()}}), ) + + """ + group by + po.partner_id, + p.product_tmpl_id, + po.date_order, + l.product_id, + t.uom_id, + t.detailed_type, + po.id, + currency_table.rate, + t.purchase_method, + t.categ_id + order by l.product_id) + UNION ALL + (select + so.id as id, + so.date_order as order_date, + so.partner_id as partner_id, + so.company_id as company_id, + so.currency_id, + t.categ_id as category_id, + t.uom_id as product_uom, + so.user_id as user_id, + case + when so.state='draft' then 'draft_sale' + when so.state='sent' then 'sent_sale' + when so.state='sale' then 'sale' + when so.state='done' then 'done' else + 'cancel' end as order_state, + case when so.is_sale_order=True then + 'Sale' else '' end as order_type, + s.product_id as product_id, + p.product_tmpl_id as product_tmpl_id, + t.detailed_type as product_type, + so.name as order_ref, + case when s.product_id is not null then + sum(s.price_unit) else 0 end + as unit_price_sale, + 0 as unit_price_purchase, + case when s.product_id is not null then + sum(s.price_total / case coalesce(so.currency_rate, 0) + when 0 then 1.0 else so.currency_rate end) else + 0 end as price_total_sale, + 0 as price_total_purchase, + case when s.product_id is not null then + sum(s.price_subtotal / case coalesce(so.currency_rate, 0) + when 0 then 1.0 else so.currency_rate end) else + 0 end as price_subtotal_sale, + 0 as price_subtotal_purchase, + 0 as qty_ordered_to, + 0 as qty_received, + 0 as qty_billed, + 0 as qty_to_bill, + 0 as qty_to_receive, + case when s.product_id is not null then + sum(p.weight * s.product_uom_qty / u.factor * u2.factor) else 0 end as weight_sale, + 0 as weight_purchase, + case when s.product_id is not null then + sum(p.volume * s.product_uom_qty / u.factor * u2.factor) else 0 end as volume_sale, + 0 as volume_purchase, + case when s.product_id is not null then + sum(s.product_uom_qty / u.factor * u2.factor) else 0 end as + qty_ordered_by, + case when s.product_id is not null then + sum(s.qty_delivered / u.factor * u2.factor) else 0 end as + qty_delivered, + case when s.product_id is not null then + sum(s.qty_invoiced / u.factor * u2.factor) else 0 end as + qty_invoiced, + case when s.product_id is not null then + sum(s.qty_to_invoice / u.factor * u2.factor) else 0 end as + qty_to_invoice, + case when s.product_id is not null then + sum((s.product_uom_qty - s.qty_delivered) / u.factor * u2.factor) + else 0 end as qty_to_deliver + from + (sale_order_line s + join sale_order so on (s.order_id=so.id) + join res_partner partner on + (so.partner_id=partner.id) + left join product_product p on + (s.product_id=p.id) + left join product_template t on + (p.product_tmpl_id=t.id) + left join uom_uom u on + (s.product_uom=u.id) + left join uom_uom u2 on + (t.uom_id=u2.id)) + group by + so.partner_id, + p.product_tmpl_id, + so.date_order, + s.product_id, + t.uom_id, + t.detailed_type, + so.id, + t.categ_id + order by s.product_id)) + macro + group by + macro.partner_id, + macro.product_tmpl_id, + macro.order_date, + macro.order_state, + macro.product_id, + macro.id, + macro.order_ref, + macro.order_type, + macro.unit_price_sale, + macro.unit_price_purchase, + macro.product_type, + macro.qty_invoiced, + macro.qty_billed, + macro.qty_delivered, + macro.qty_received, + macro.qty_ordered_to, + macro.qty_ordered_by, + macro.qty_to_deliver, + macro.qty_to_receive, + macro.qty_to_invoice, + macro.qty_to_bill, + macro.price_total_sale, + macro.price_total_purchase, + macro.price_subtotal_sale, + macro.price_subtotal_purchase, + macro.company_id, + macro.currency_id, + macro.product_uom, + macro.user_id, + macro.weight_sale, + macro.weight_purchase, + macro.volume_sale, + macro.volume_purchase, + macro.category_id + order by macro.product_id + ); + """) diff --git a/sale_purchase_mixed_report/reports/sale_purchase_report_views.xml b/sale_purchase_mixed_report/reports/sale_purchase_report_views.xml new file mode 100644 index 000000000..ccf056fba --- /dev/null +++ b/sale_purchase_mixed_report/reports/sale_purchase_report_views.xml @@ -0,0 +1,85 @@ + + + + sale.purchase.report.view.pivot + sale.purchase.report + + + + + + + + + + sale.purchase.report.view.graph + sale.purchase.report + + + + + + + + + sale.purchase.report.view.search + sale.purchase.report + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Sale Purchase Report + sale.purchase.report + graph,pivot + current + + + + + + + + \ No newline at end of file diff --git a/sale_purchase_mixed_report/security/ir.model.access.csv b/sale_purchase_mixed_report/security/ir.model.access.csv new file mode 100644 index 000000000..384b06393 --- /dev/null +++ b/sale_purchase_mixed_report/security/ir.model.access.csv @@ -0,0 +1,7 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_sale_purchase_report_user,sale.purchase.report.user,model_sale_purchase_report,base.group_user,1,0,0,0 +access_sale_purchase_report_sale_manger,sale.purchase.report.sale.manager,model_sale_purchase_report,sales_team.group_sale_manager,1,1,1,1 +access_sale_purchase_report_purchase_manger,sale.purchase.report.purchase.manager,model_sale_purchase_report,purchase.group_purchase_manager,1,1,1,1 +access_wizard_sale_purchase_report_user,wizard.sale.purchase.report.user,model_wizard_sale_purchase_report,base.group_user,1,0,0,0 +access_wizard_sale_purchase_report_sale_manager,wizard.sale.purchase.report.sale.manager,model_wizard_sale_purchase_report,sales_team.group_sale_manager,1,1,1,1 +access_wizard_sale_purchase_report_purchase_manager,wizard.sale.purchase.report.purchase.manager,model_wizard_sale_purchase_report,purchase.group_purchase_manager,1,1,1,1 \ No newline at end of file diff --git a/sale_purchase_mixed_report/static/description/assets/icons/check.png b/sale_purchase_mixed_report/static/description/assets/icons/check.png new file mode 100644 index 000000000..c8e85f51d Binary files /dev/null and b/sale_purchase_mixed_report/static/description/assets/icons/check.png differ diff --git a/sale_purchase_mixed_report/static/description/assets/icons/chevron.png b/sale_purchase_mixed_report/static/description/assets/icons/chevron.png new file mode 100644 index 000000000..2089293d6 Binary files /dev/null and b/sale_purchase_mixed_report/static/description/assets/icons/chevron.png differ diff --git a/sale_purchase_mixed_report/static/description/assets/icons/cogs.png b/sale_purchase_mixed_report/static/description/assets/icons/cogs.png new file mode 100644 index 000000000..95d0bad62 Binary files /dev/null and b/sale_purchase_mixed_report/static/description/assets/icons/cogs.png differ diff --git a/sale_purchase_mixed_report/static/description/assets/icons/consultation.png b/sale_purchase_mixed_report/static/description/assets/icons/consultation.png new file mode 100644 index 000000000..8319d4baa Binary files /dev/null and b/sale_purchase_mixed_report/static/description/assets/icons/consultation.png differ diff --git a/sale_purchase_mixed_report/static/description/assets/icons/ecom-black.png b/sale_purchase_mixed_report/static/description/assets/icons/ecom-black.png new file mode 100644 index 000000000..a9385ff13 Binary files /dev/null and b/sale_purchase_mixed_report/static/description/assets/icons/ecom-black.png differ diff --git a/sale_purchase_mixed_report/static/description/assets/icons/education-black.png b/sale_purchase_mixed_report/static/description/assets/icons/education-black.png new file mode 100644 index 000000000..3eb09b27b Binary files /dev/null and b/sale_purchase_mixed_report/static/description/assets/icons/education-black.png differ diff --git a/sale_purchase_mixed_report/static/description/assets/icons/hotel-black.png b/sale_purchase_mixed_report/static/description/assets/icons/hotel-black.png new file mode 100644 index 000000000..130f613be Binary files /dev/null and b/sale_purchase_mixed_report/static/description/assets/icons/hotel-black.png differ diff --git a/sale_purchase_mixed_report/static/description/assets/icons/license.png b/sale_purchase_mixed_report/static/description/assets/icons/license.png new file mode 100644 index 000000000..a5869797e Binary files /dev/null and b/sale_purchase_mixed_report/static/description/assets/icons/license.png differ diff --git a/sale_purchase_mixed_report/static/description/assets/icons/lifebuoy.png b/sale_purchase_mixed_report/static/description/assets/icons/lifebuoy.png new file mode 100644 index 000000000..658d56ccc Binary files /dev/null and b/sale_purchase_mixed_report/static/description/assets/icons/lifebuoy.png differ diff --git a/sale_purchase_mixed_report/static/description/assets/icons/logo.png b/sale_purchase_mixed_report/static/description/assets/icons/logo.png new file mode 100644 index 000000000..478462d3e Binary files /dev/null and b/sale_purchase_mixed_report/static/description/assets/icons/logo.png differ diff --git a/sale_purchase_mixed_report/static/description/assets/icons/manufacturing-black.png b/sale_purchase_mixed_report/static/description/assets/icons/manufacturing-black.png new file mode 100644 index 000000000..697eb0e9f Binary files /dev/null and b/sale_purchase_mixed_report/static/description/assets/icons/manufacturing-black.png differ diff --git a/sale_purchase_mixed_report/static/description/assets/icons/pos-black.png b/sale_purchase_mixed_report/static/description/assets/icons/pos-black.png new file mode 100644 index 000000000..97c0f90c1 Binary files /dev/null and b/sale_purchase_mixed_report/static/description/assets/icons/pos-black.png differ diff --git a/sale_purchase_mixed_report/static/description/assets/icons/puzzle.png b/sale_purchase_mixed_report/static/description/assets/icons/puzzle.png new file mode 100644 index 000000000..65cf854e7 Binary files /dev/null and b/sale_purchase_mixed_report/static/description/assets/icons/puzzle.png differ diff --git a/sale_purchase_mixed_report/static/description/assets/icons/restaurant-black.png b/sale_purchase_mixed_report/static/description/assets/icons/restaurant-black.png new file mode 100644 index 000000000..4a35eb939 Binary files /dev/null and b/sale_purchase_mixed_report/static/description/assets/icons/restaurant-black.png differ diff --git a/sale_purchase_mixed_report/static/description/assets/icons/service-black.png b/sale_purchase_mixed_report/static/description/assets/icons/service-black.png new file mode 100644 index 000000000..301ab51cb Binary files /dev/null and b/sale_purchase_mixed_report/static/description/assets/icons/service-black.png differ diff --git a/sale_purchase_mixed_report/static/description/assets/icons/trading-black.png b/sale_purchase_mixed_report/static/description/assets/icons/trading-black.png new file mode 100644 index 000000000..9398ba2f1 Binary files /dev/null and b/sale_purchase_mixed_report/static/description/assets/icons/trading-black.png differ diff --git a/sale_purchase_mixed_report/static/description/assets/icons/training.png b/sale_purchase_mixed_report/static/description/assets/icons/training.png new file mode 100644 index 000000000..884ca024d Binary files /dev/null and b/sale_purchase_mixed_report/static/description/assets/icons/training.png differ diff --git a/sale_purchase_mixed_report/static/description/assets/icons/update.png b/sale_purchase_mixed_report/static/description/assets/icons/update.png new file mode 100644 index 000000000..ecbc5a01a Binary files /dev/null and b/sale_purchase_mixed_report/static/description/assets/icons/update.png differ diff --git a/sale_purchase_mixed_report/static/description/assets/icons/user.png b/sale_purchase_mixed_report/static/description/assets/icons/user.png new file mode 100644 index 000000000..6ffb23d9f Binary files /dev/null and b/sale_purchase_mixed_report/static/description/assets/icons/user.png differ diff --git a/sale_purchase_mixed_report/static/description/assets/icons/wrench.png b/sale_purchase_mixed_report/static/description/assets/icons/wrench.png new file mode 100644 index 000000000..6c04dea0f Binary files /dev/null and b/sale_purchase_mixed_report/static/description/assets/icons/wrench.png differ diff --git a/sale_purchase_mixed_report/static/description/assets/modules/budget_image.png b/sale_purchase_mixed_report/static/description/assets/modules/budget_image.png new file mode 100644 index 000000000..b50130c7d Binary files /dev/null and b/sale_purchase_mixed_report/static/description/assets/modules/budget_image.png differ diff --git a/sale_purchase_mixed_report/static/description/assets/modules/credit_image.png b/sale_purchase_mixed_report/static/description/assets/modules/credit_image.png new file mode 100644 index 000000000..3ad04ecfd Binary files /dev/null and b/sale_purchase_mixed_report/static/description/assets/modules/credit_image.png differ diff --git a/sale_purchase_mixed_report/static/description/assets/modules/employee_image.png b/sale_purchase_mixed_report/static/description/assets/modules/employee_image.png new file mode 100644 index 000000000..30ad58232 Binary files /dev/null and b/sale_purchase_mixed_report/static/description/assets/modules/employee_image.png differ diff --git a/sale_purchase_mixed_report/static/description/assets/modules/export_image.png b/sale_purchase_mixed_report/static/description/assets/modules/export_image.png new file mode 100644 index 000000000..492980ad0 Binary files /dev/null and b/sale_purchase_mixed_report/static/description/assets/modules/export_image.png differ diff --git a/sale_purchase_mixed_report/static/description/assets/modules/gantt_image.png b/sale_purchase_mixed_report/static/description/assets/modules/gantt_image.png new file mode 100644 index 000000000..1ae7cfe3b Binary files /dev/null and b/sale_purchase_mixed_report/static/description/assets/modules/gantt_image.png differ diff --git a/sale_purchase_mixed_report/static/description/assets/modules/quotation_image.png b/sale_purchase_mixed_report/static/description/assets/modules/quotation_image.png new file mode 100644 index 000000000..499b1a72f Binary files /dev/null and b/sale_purchase_mixed_report/static/description/assets/modules/quotation_image.png differ diff --git a/sale_purchase_mixed_report/static/description/assets/screenshots/graph_view.png b/sale_purchase_mixed_report/static/description/assets/screenshots/graph_view.png new file mode 100644 index 000000000..9b3abfae4 Binary files /dev/null and b/sale_purchase_mixed_report/static/description/assets/screenshots/graph_view.png differ diff --git a/sale_purchase_mixed_report/static/description/assets/screenshots/hero.png b/sale_purchase_mixed_report/static/description/assets/screenshots/hero.png new file mode 100644 index 000000000..fb645a18e Binary files /dev/null and b/sale_purchase_mixed_report/static/description/assets/screenshots/hero.png differ diff --git a/sale_purchase_mixed_report/static/description/assets/screenshots/menu_purchase.png b/sale_purchase_mixed_report/static/description/assets/screenshots/menu_purchase.png new file mode 100644 index 000000000..5a86d8233 Binary files /dev/null and b/sale_purchase_mixed_report/static/description/assets/screenshots/menu_purchase.png differ diff --git a/sale_purchase_mixed_report/static/description/assets/screenshots/menu_sale.png b/sale_purchase_mixed_report/static/description/assets/screenshots/menu_sale.png new file mode 100644 index 000000000..794b29def Binary files /dev/null and b/sale_purchase_mixed_report/static/description/assets/screenshots/menu_sale.png differ diff --git a/sale_purchase_mixed_report/static/description/assets/screenshots/pdf_report.png b/sale_purchase_mixed_report/static/description/assets/screenshots/pdf_report.png new file mode 100644 index 000000000..bb238d1e1 Binary files /dev/null and b/sale_purchase_mixed_report/static/description/assets/screenshots/pdf_report.png differ diff --git a/sale_purchase_mixed_report/static/description/assets/screenshots/pivot_view.png b/sale_purchase_mixed_report/static/description/assets/screenshots/pivot_view.png new file mode 100644 index 000000000..46a1e1e1e Binary files /dev/null and b/sale_purchase_mixed_report/static/description/assets/screenshots/pivot_view.png differ diff --git a/sale_purchase_mixed_report/static/description/assets/screenshots/print_wizard.png b/sale_purchase_mixed_report/static/description/assets/screenshots/print_wizard.png new file mode 100644 index 000000000..c05489e1e Binary files /dev/null and b/sale_purchase_mixed_report/static/description/assets/screenshots/print_wizard.png differ diff --git a/sale_purchase_mixed_report/static/description/assets/screenshots/xlsx_report.png b/sale_purchase_mixed_report/static/description/assets/screenshots/xlsx_report.png new file mode 100644 index 000000000..e6948836c Binary files /dev/null and b/sale_purchase_mixed_report/static/description/assets/screenshots/xlsx_report.png differ diff --git a/sale_purchase_mixed_report/static/description/banner.png b/sale_purchase_mixed_report/static/description/banner.png new file mode 100644 index 000000000..c8ca8e8fb Binary files /dev/null and b/sale_purchase_mixed_report/static/description/banner.png differ diff --git a/sale_purchase_mixed_report/static/description/icon.png b/sale_purchase_mixed_report/static/description/icon.png new file mode 100644 index 000000000..13610a6b0 Binary files /dev/null and b/sale_purchase_mixed_report/static/description/icon.png differ diff --git a/sale_purchase_mixed_report/static/description/index.html b/sale_purchase_mixed_report/static/description/index.html new file mode 100644 index 000000000..7518eeddd --- /dev/null +++ b/sale_purchase_mixed_report/static/description/index.html @@ -0,0 +1,691 @@ +
+
+
+
+ +
+
+
+ Community +
+
+ Enterprise +
+ +
+
+
+
+ +
+
+
+

+ Sales Purchase Mixed Report

+

+ A Module For getting the mixed report from Sales and Purchase +

+ +
+
+ + + +
+
+

+ Overview +

+
+ +
+

+ In the Sales Purchase Mixed Report module, we can have mixed + reports from the Sales and Purchase orders. There are Pivot, + Graph views to explore the mixed report. Moreover, we can print + the PDF and XLSX reports. +

+
+

+ +
+ + +
+
+

+ Features +

+
+ +
+
+ +
+
+

+ No additional configuration required.

+
+
+ +
+
+ +
+
+

+ Reports are available from both Sales and Purchase modules under Reporting menu.

+
+
+ +
+
+ +
+
+

+ Graph and Pivot views are available with several Measures and Filters.

+
+
+ +
+
+ +
+
+

+ Extra wizard for filtering and Printing the PDF, XLSX Reports.

+
+
+ + +
+ +
+
+

+ Screenshots +

+
+
+

+ Menu available from Sale

+

+ Menus are available from Sale in order to view and print them in PDF, XLSX formats.

+ +
+ +
+

+ Menu available from Purchase

+

+ Menus are available from Purchase in order to view and print them in PDF, XLSX formats. +

+ +
+ +
+

+ Graph View

+ +
+ + +
+

+ Pivot View

+ +
+ + +
+

+ Wizard to Print Report

+

+ Wizard to print mixed report in PDF and XLSX formats are + available in which we can filter the orders based on Partner, + Order Reference and Order Dates. +

+ +
+ + +
+

+ PDF Report

+ +
+ +
+

+ XLSX Report

+ +
+ +
+ +
+
+

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?

+
+
+
+ + +
+ +
+ + +
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+
+
+ + +
\ No newline at end of file diff --git a/sale_purchase_mixed_report/static/src/js/action_manager.js b/sale_purchase_mixed_report/static/src/js/action_manager.js new file mode 100644 index 000000000..391a125e3 --- /dev/null +++ b/sale_purchase_mixed_report/static/src/js/action_manager.js @@ -0,0 +1,21 @@ +/** @odoo-module */ + +import { registry } from "@web/core/registry"; +import { download } from "@web/core/network/download"; +import framework from 'web.framework'; +import session from 'web.session'; + +registry.category('ir.actions.report handlers').add('xlsx_controller', async (action) => { + if (action.report_type == 'xlsx_controller') { + framework.blockUI(); + var def = $.Deferred(); + session.get_file({ + url: '/xlsx_reports', + data: action.data, + success: def.resolve.bind(def), + error: (error) => this.call('crash_manager', 'rpc_error', error), + complete: framework.unblockUI, + }); + return def; + } +}); \ No newline at end of file diff --git a/sale_purchase_mixed_report/wizards/__init__.py b/sale_purchase_mixed_report/wizards/__init__.py new file mode 100644 index 000000000..0e74e7b36 --- /dev/null +++ b/sale_purchase_mixed_report/wizards/__init__.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +################################################################################ +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2022-TODAY Cybrosys Technologies(). +# Author: Mohammed Ajmal P (odoo@cybrosys.com) +# +# You can modify it under the terms of the GNU AFFERO +# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. +# +# This program is distributes 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 this program. +# If not, see . +# +################################################################################ + +from . import wizard diff --git a/sale_purchase_mixed_report/wizards/wizard.py b/sale_purchase_mixed_report/wizards/wizard.py new file mode 100644 index 000000000..4f1b815ee --- /dev/null +++ b/sale_purchase_mixed_report/wizards/wizard.py @@ -0,0 +1,396 @@ +# -*- coding: utf-8 -*- +################################################################################ +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2022-TODAY Cybrosys Technologies(). +# Author: Mohammed Ajmal P (odoo@cybrosys.com) +# +# You can modify it under the terms of the GNU AFFERO +# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. +# +# This program is distributes 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 this program. +# If not, see . +# +################################################################################ +import io +import json + +import datetime +from odoo import fields, models +from odoo.exceptions import ValidationError +from odoo.tools import date_utils + +try: + from odoo.tools.misc import xlsxwriter +except ImportError: + import xlsxwriter + + +class SalePurchasePrintReport(models.TransientModel): + """Fields and functions for the wizard for filtering""" + _name = 'wizard.sale.purchase.report' + _description = 'Sale Purchase Report Print' + + date_from = fields.Datetime('Date From') + date_to = fields.Datetime('Date To') + partner_ids = fields.Many2many( + 'res.partner', string='Partners', + domain=lambda self: [('company_id', 'in', + [False, self.env.company.id])]) + sale_order_ids = fields.Many2many( + 'sale.order', string='Sale Orders', + domain=lambda self: [('company_id', 'in', + [False, self.env.company.id])] + ) + purchase_order_ids = fields.Many2many( + 'purchase.order', string='Purchase Orders', domain=lambda self: [ + ('company_id', 'in', [False, self.env.company.id])] + ) + + def print_pdf_report(self): + """Button function to print PDF Report""" + if self.date_from and self.date_to and self.date_from > self.date_to: + raise ValidationError('From Date must be less than of To Date!!!') + data = { + 'model': self._name, + 'form': self.read()[0], + } + return self.env.ref( + 'sale_purchase_mixed_report.action_report_sale_purchase' + ).report_action(self, data=data) + + def print_xlsx_report(self): + """Button function to print Xlsx Report""" + if self.date_from and self.date_to and self.date_from > self.date_to: + raise ValidationError('From Date must be less than of To Date!!!') + data = { + 'model': self._name, + 'form': self.read()[0], + } + return { + 'type': 'ir.actions.report', + 'data': {'model': self._name, + 'options': json.dumps(data, + default=date_utils.json_default), + 'output_format': 'xlsx_controller', + 'report_name': 'Sales Purchase Report', + }, + 'report_type': 'xlsx_controller', + } + + def get_xlsx_report(self, data, response): + """Create and add data to the excel sheet""" + company_id = self.env.company + output = io.BytesIO() + workbook = xlsxwriter.Workbook(output, {'in_memory': True}) + sheet = workbook.add_worksheet() + head_format = workbook.add_format({ + 'align': 'center', + 'bold': True, + 'font_size': '10px' + }) + data_format = workbook.add_format({ + 'font_size': '10px' + }) + sheet.write(0, 0, 'Order Date', head_format) + sheet.write(0, 1, 'Order Type', head_format) + sheet.write(0, 2, 'Order Ref', head_format) + sheet.write(0, 3, 'Partner', head_format) + sheet.write(0, 4, 'Product', head_format) + sheet.write(0, 5, 'Product Type', head_format) + sheet.write(0, 6, 'Qty Ordered', head_format) + sheet.write(0, 7, 'Qty Delivered/Received', head_format) + sheet.write(0, 8, 'Qty To Deliver/To Receive', head_format) + sheet.write(0, 9, 'Qty Invoiced/Billed', head_format) + sheet.write(0, 10, 'UOM', head_format) + sheet.write(0, 11, 'Unit Price', head_format) + sheet.write(0, 12, 'Total Price', head_format) + sheet.write(0, 13, 'Currency', head_format) + sheet.write(0, 14, 'Order State', head_format) + where_sale = """so.company_id = %s""" % ( + company_id.id) + where_purchase = """po.company_id = %s""" % ( + company_id.id) + if data['form']['date_from']: + where_sale += """AND so.date_order >= '%s'""" % ( + data['form']['date_from']) + where_purchase += """AND po.date_order >= '%s'""" % ( + data['form']['date_from']) + if data['form']['date_to']: + where_sale += """AND so.date_order <= '%s'""" % ( + data['form']['date_to']) + where_purchase += """AND po.date_order <= '%s'""" % ( + data['form']['date_to']) + if data['form']['partner_ids']: + if len(data['form']['partner_ids']) == 1: + where_sale += """AND so.partner_id = %s""" % ( + data['form']['partner_ids'][0]) + where_purchase += """AND po.partner_id = %s""" % ( + data['form']['partner_ids'][0]) + else: + where_sale += """AND so.partner_id in %s""" % ( + str(tuple(data['form']['partner_ids']))) + where_purchase += """AND po.partner_id in %s""" % ( + str(tuple(data['form']['partner_ids']))) + if data['form']['sale_order_ids']: + if len(data['form']['sale_order_ids']) == 1: + where_sale += """AND so.id = %s""" % ( + data['form']['sale_order_ids'][0]) + else: + where_sale += """AND so.id in %s""" % ( + str(tuple(data['form']['sale_order_ids']))) + if data['form']['purchase_order_ids']: + if len(data['form']['purchase_order_ids']) == 1: + where_purchase += """AND po.id = %s""" % ( + data['form']['purchase_order_ids'][0]) + else: + where_purchase += """AND po.id in %s""" % ( + str(tuple(data['form']['purchase_order_ids']))) + self.env.cr.execute(""" + select macro.id as id, + macro.order_type as order_type, + macro.order_state as order_state, + macro.order_date as order_date, + macro.partner_id as partner_id, + macro.product_id as product_id, + macro.order_ref as order_ref, + macro.unit_price_sale as unit_price_sale, + macro.unit_price_purchase as unit_price_purchase, + macro.price_total_sale as price_total_sale, + macro.price_total_purchase as price_total_purchase, + macro.price_subtotal_sale as price_subtotal_sale, + macro.price_subtotal_purchase as price_subtotal_purchase, + macro.product_type as product_type, + macro.qty_invoiced as qty_invoiced, + macro.qty_billed as qty_billed, + macro.qty_ordered_to as qty_ordered_to, + macro.qty_ordered_by as qty_ordered_by, + macro.qty_delivered as qty_delivered, + macro.qty_received as qty_received, + macro.qty_to_deliver as qty_to_deliver, + macro.qty_to_receive as qty_to_receive, + macro.company_id as company_id, + macro.currency_id as currency_id, + macro.product_uom as product_uom + from(( + with currency_rate as (%s)""" % self.env[ + 'res.currency']._select_companies_rates() + + """ + select + po.id as id, + po.date_order as order_date, + po.partner_id as partner_id, + po.company_id as company_id, + po.currency_id, + t.uom_id as product_uom, + po.state as order_state, + case when po.is_purchase_order=True then + 'Purchase' else '' end as order_type, + l.product_id as product_id, + t.detailed_type as product_type, + po.name as order_ref, + 0 as unit_price_sale, + case when l.product_id is not null then + sum(l.price_unit) + else 0 end as unit_price_purchase, + 0 as price_total_sale, + sum(l.price_total / coalesce(po.currency_rate, 1.0))::decimal(16,2) * currency_table.rate as price_total_purchase, + 0 as price_subtotal_sale, + sum(l.price_subtotal / coalesce(po.currency_rate, 1.0))::decimal(16, 2) * currency_table.rate as price_subtotal_purchase, + case when l.product_id is not null then + sum(l.product_qty/ u.factor * u2.factor) else 0 + end as qty_ordered_to, + case when l.product_id is not null then + sum(l.qty_received / u.factor * u2.factor) else 0 + end as qty_received, + case when l.product_id is not null then + sum(l.qty_invoiced / u.factor * u2.factor) + else 0 end as qty_billed, + case when l.product_id is not null then + sum((l.product_qty - l.qty_received) / u.factor * u2.factor) + else 0 end as qty_to_receive, + 0 as qty_ordered_by, + 0 as qty_delivered, + 0 as qty_invoiced, + 0 as qty_to_deliver + from + (purchase_order_line l + join purchase_order po on (l.order_id=po.id) + join res_partner partner on + (po.partner_id=partner.id) + left join product_product p on + (l.product_id=p.id) + left join product_template t on + (p.product_tmpl_id=t.id) + left join uom_uom u on (l.product_uom=u.id) + left join uom_uom u2 on (t.uom_id=u2.id)) + left join currency_rate cr on + (cr.currency_id = po.currency_id + and cr.company_id = po.company_id and cr.date_start <= coalesce(po.date_order, now()) and + (cr.date_end is null or cr.date_end > coalesce(po.date_order, now()))) + left join {currency_table} on + currency_table.company_id = po.company_id + """.format( + currency_table=self.env[ + 'res.currency']._get_query_currency_table( + {'multi_company': True, + 'date': { + 'date_to': fields.Date.today()}}), ) + + """ + where %s + group by + po.partner_id, + po.date_order, + l.product_id, + t.uom_id, + t.detailed_type, + po.id, + currency_table.rate, + t.purchase_method + order by l.product_id) + UNION ALL + (select + so.id as id, + so.date_order as order_date, + so.partner_id as partner_id, + so.company_id as company_id, + so.currency_id, + t.uom_id as product_uom, + so.state as order_state, + case when so.is_sale_order=True then + 'Sale' else '' end as order_type, + s.product_id as product_id, + t.detailed_type as product_type, + so.name as order_ref, + case when s.product_id is not null + then sum(s.price_unit) + else 0 end as unit_price_sale, + 0 as unit_price_purchase, + case when s.product_id is not null + then sum(s.price_total / case coalesce(so.currency_rate, 0) + when 0 then 1.0 else + so.currency_rate end) else 0 end + as price_total_sale, + 0 as price_total_purchase, + case when s.product_id is not null + then sum(s.price_subtotal / case coalesce(so.currency_rate, 0) + when 0 then 1.0 else + so.currency_rate end) else + 0 end as price_subtotal_sale, + 0 as price_subtotal_purchase, + 0 as qty_ordered_to, + 0 as qty_received, + 0 as qty_billed, + 0 as qty_to_receive, + case when s.product_id is not null + then sum(s.product_uom_qty / u.factor * u2.factor) else 0 end as + qty_ordered_by, + case when s.product_id is not null + then sum(s.qty_delivered / u.factor * u2.factor) else 0 end as + qty_delivered, + case when s.product_id is not null + then sum(s.qty_invoiced / u.factor * u2.factor) else 0 end as + qty_invoiced, + case when s.product_id is not null + then sum((s.product_uom_qty - s.qty_delivered) / u.factor * u2.factor) + else 0 end as qty_to_deliver + from + (sale_order_line s + join sale_order so on (s.order_id=so.id) + join res_partner partner on + (so.partner_id=partner.id) + left join product_product p on + (s.product_id=p.id) + left join product_template t on + (p.product_tmpl_id=t.id) + left join uom_uom u on + (s.product_uom=u.id) + left join uom_uom u2 on + (t.uom_id=u2.id)) + where %s + group by + so.partner_id, + so.date_order, + s.product_id, + t.uom_id, + t.detailed_type, + so.id + order by s.product_id)) + macro + group by + macro.partner_id, + macro.order_date, + macro.order_state, + macro.product_id, + macro.id, + macro.order_ref, + macro.order_type, + macro.unit_price_sale, + macro.unit_price_purchase, + macro.product_type, + macro.qty_invoiced, + macro.qty_billed, + macro.qty_delivered, + macro.qty_received, + macro.qty_ordered_to, + macro.qty_ordered_by, + macro.qty_to_deliver, + macro.qty_to_receive, + macro.price_total_sale, + macro.price_total_purchase, + macro.price_subtotal_sale, + macro.price_subtotal_purchase, + macro.company_id, + macro.currency_id, + macro.product_uom + order by macro.product_id + """ % (where_purchase, where_sale)) + rec = self.env.cr.fetchall() + j = 1 + k = 0 + for i in range(0, len(rec)): + product_id = self.env['product.product'].browse(rec[i][5]) + uom_id = self.env['uom.uom'].browse(rec[i][24]) + # currency_id = self.env['res.currency'].browse(rec[i][23]) + currency_id = company_id.currency_id + partner_id = self.env['res.partner'].browse(rec[i][4]) + sheet.set_column(j, k, 15) + sheet.write(j, 0, datetime.datetime.strftime(rec[i][3], '%m/%d/%Y'), + data_format) + sheet.write(j, 1, rec[i][1], data_format) + sheet.write(j, 2, rec[i][6], data_format) + sheet.write(j, 3, partner_id.name, data_format) + sheet.write(j, 4, product_id.display_name, data_format) + sheet.write(j, 5, rec[i][13], data_format) + sheet.write(j, 6, rec[i][17] if rec[i][1] == 'Sale' else rec[i][16], + data_format) + sheet.write(j, 7, rec[i][18] if rec[i][1] == 'Sale' else rec[i][19], + data_format) + sheet.write(j, 8, rec[i][20] if rec[i][1] == 'Sale' else rec[i][21], + data_format) + sheet.write(j, 9, rec[i][14] if rec[i][1] == 'Sale' else rec[i][15], + data_format) + sheet.write(j, 10, uom_id.name, data_format) + sheet.write(j, 11, rec[i][7] if rec[i][1] == 'Sale' else rec[i][8], + data_format) + sheet.write(j, 12, rec[i][9] if rec[i][1] == 'Sale' else rec[i][10], + data_format) + sheet.write(j, 13, currency_id.name, data_format) + sheet.write(j, 14, dict( + self.env['sale.order']._fields['state'].selection).get( + rec[i][2]) if rec[i][1] == 'Sale' else dict( + self.env['purchase.order']._fields['state'].selection).get( + rec[i][2]), data_format) + j += 1 + k += 1 + workbook.close() + output.seek(0) + response.stream.write(output.read()) + output.close() diff --git a/sale_purchase_mixed_report/wizards/wizard_views.xml b/sale_purchase_mixed_report/wizards/wizard_views.xml new file mode 100644 index 000000000..434d8f013 --- /dev/null +++ b/sale_purchase_mixed_report/wizards/wizard_views.xml @@ -0,0 +1,53 @@ + + + + wizard.sale.purchase.report.view.form + wizard.sale.purchase.report + +
+ + + + + + + + + + + +
+
+
+
+
+ + Sale Purchase Report + ir.actions.act_window + wizard.sale.purchase.report + form + + new + + + Sales Purchase Report + wizard.sale.purchase.report + qweb-pdf + sale_purchase_mixed_report.report_sale_purchase + sale_purchase_mixed_report.report_sale_purchase + + + +
\ No newline at end of file