@ -0,0 +1,44 @@ |
|||
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.svg |
|||
:target: https://www.gnu.org/licenses/agpl-3.0-standalone.html |
|||
:alt: License: AGPL-3 |
|||
|
|||
Low Sales Report |
|||
================ |
|||
* The tool to control poorly performing product |
|||
|
|||
Configuration |
|||
============= |
|||
* No additional configurations needed |
|||
|
|||
Company |
|||
------- |
|||
* `Cybrosys Techno Solutions <https://cybrosys.com/>`__ |
|||
|
|||
License |
|||
------- |
|||
Affero General Public License v3.0 (AGPL v3) |
|||
(https://www.gnu.org/licenses/agpl-3.0-standalone.html) |
|||
|
|||
Credits |
|||
------- |
|||
* Developer: (V17) Junaidul Ansar M , Contact: odoo@cybrosys.com |
|||
(V18) Raveena Vijayan V , 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 |
|||
========== |
|||
This module is maintained by Cybrosys Technologies. |
|||
|
|||
For support and more information, please visit https://www.cybrosys.com |
|||
|
|||
Further information |
|||
=================== |
|||
HTML Description: `<static/description/index.html>`__ |
@ -0,0 +1,25 @@ |
|||
# -*- coding: utf-8 -*- |
|||
################################################################################ |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>). |
|||
# Author: Raveena V (odoo@cybrosys.com) |
|||
# |
|||
# 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 <http://www.gnu.org/licenses/>. |
|||
# |
|||
################################################################################ |
|||
from . import controllers |
|||
from . import models |
|||
from . import report |
|||
from . import wizard |
@ -0,0 +1,56 @@ |
|||
# -*- coding: utf-8 -*- |
|||
################################################################################ |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>). |
|||
# Author: Raveena V (odoo@cybrosys.com) |
|||
# |
|||
# 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 <http://www.gnu.org/licenses/>. |
|||
# |
|||
################################################################################ |
|||
{ |
|||
'name': "Low Sales Report", |
|||
'version': '18.0.1.0.0', |
|||
'category': 'Sale', |
|||
'summary': 'The tool to control poorly performing product', |
|||
'description': 'Efficiently manage and analyze low sales with this module,' |
|||
'offering customizable criteria, flexible reporting ' |
|||
'periods, and versatile presentation options in Odoo or ' |
|||
'Excel. Tailor your analysis by filtering specific product' |
|||
'categories or sales teams, and choose between ' |
|||
'template-wide insights or focus on individual product ' |
|||
'variants for a comprehensive understanding of ' |
|||
'under performing products.', |
|||
'author': 'Cybrosys Techno Solutions', |
|||
'company': 'Cybrosys Techno Solutions', |
|||
'maintainer': 'Cybrosys Techno Solutions', |
|||
'website': 'https://www.cybrosys.com', |
|||
'depends': ['sale_management', 'crm', 'product', 'mail'], |
|||
'data': [ |
|||
'security/ir.model.access.csv', |
|||
'views/res_config_settings_view.xml', |
|||
'report/low_sale_pivot_view_report_view.xml', |
|||
'wizard/low_sale_report_views.xml' |
|||
], |
|||
'assets': { |
|||
'web.assets_backend': [ |
|||
'low_sale_report/static/src/js/low_sale_xlsx_report.js', |
|||
], |
|||
}, |
|||
'images': ['static/description/banner.jpg'], |
|||
'license': 'AGPL-3', |
|||
'installable': True, |
|||
'auto_install': False, |
|||
'application': False, |
|||
} |
@ -0,0 +1,22 @@ |
|||
# -*- coding: utf-8 -*- |
|||
################################################################################ |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>). |
|||
# Author: Raveena V (odoo@cybrosys.com) |
|||
# |
|||
# 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 <http://www.gnu.org/licenses/>. |
|||
# |
|||
################################################################################ |
|||
from . import low_sale_report |
@ -0,0 +1,62 @@ |
|||
# -*- coding: utf-8 -*- |
|||
################################################################################ |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>). |
|||
# Author: Raveena V (odoo@cybrosys.com) |
|||
# |
|||
# 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 <http://www.gnu.org/licenses/>. |
|||
# |
|||
################################################################################ |
|||
import json |
|||
from odoo import http |
|||
from odoo.http import content_disposition, request |
|||
from odoo.http import serialize_exception as _serialize_exception |
|||
from odoo.tools import html_escape |
|||
|
|||
|
|||
class XLSXReportController(http.Controller): |
|||
"""This controller defines a route for generating and serving XLSX reports. |
|||
The route '/sale_low_xlsx_reports' accepts POST requests and returns an |
|||
XLSX report based on the provided model, options, output format, and report |
|||
name.""" |
|||
@http.route('/sale_low_xlsx_reports', type='http', |
|||
auth='user', methods=['POST'], csrf=False) |
|||
def get_report_xlsx(self, model, options, output_format, report_name): |
|||
"""Generate and serve an 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': |
|||
response = request.make_response( |
|||
None, |
|||
headers=[ |
|||
('Content-Type', 'application/vnd.ms-excel'), |
|||
('Content-Disposition', |
|||
content_disposition(report_name + '.xlsx')) |
|||
] |
|||
) |
|||
report_obj.get_low_sale_xlsx_report(options, response) |
|||
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))) |
@ -0,0 +1,7 @@ |
|||
## Module <low_sale_report> |
|||
|
|||
#### 02.11.2024 |
|||
#### Version 18.0.1.0.0 |
|||
##### ADD |
|||
|
|||
- Initial Commit for Low Sales Report |
@ -0,0 +1,22 @@ |
|||
# -*- coding: utf-8 -*- |
|||
################################################################################ |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>). |
|||
# Author: Raveena V (odoo@cybrosys.com) |
|||
# |
|||
# 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 <http://www.gnu.org/licenses/>. |
|||
# |
|||
################################################################################ |
|||
from . import res_config_settings |
@ -0,0 +1,45 @@ |
|||
# -*- coding: utf-8 -*- |
|||
################################################################################ |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>). |
|||
# Author: Raveena V (odoo@cybrosys.com) |
|||
# |
|||
# 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 <http://www.gnu.org/licenses/>. |
|||
# |
|||
################################################################################ |
|||
from odoo import fields, models |
|||
|
|||
|
|||
class ResConfigSettings(models.TransientModel): |
|||
"""Adding a new fields to res_config_settings model for filtering the |
|||
low sales report""" |
|||
_inherit = "res.config.settings" |
|||
|
|||
product_type = fields.Selection( |
|||
[('variant', 'By product variant'), |
|||
('template', 'By product templates')], string="Report Type", |
|||
help='Which sale to take into account: Product templates in general' |
|||
' or variants?', |
|||
config_parameter='low_sale_report.product_type') |
|||
analysed_period = fields.Selection( |
|||
[('last_month', 'Last Month'), |
|||
('last_3', 'Last 3 Month'), ('last_6', 'Last 6 Month'), |
|||
('last_12', 'Last 12 Month')], string='Analysed Period', |
|||
help='Define the which period should be analysed by default.', |
|||
config_parameter='low_sale_report.analysed_period') |
|||
absolute_qty = fields.Float(string='Absolute Quantity', |
|||
help='Define a default critical level for ' |
|||
'sales.', |
|||
config_parameter='low_sale_report.absolute_qty') |
@ -0,0 +1,22 @@ |
|||
# -*- coding: utf-8 -*- |
|||
################################################################################ |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>). |
|||
# Author: Raveena V (odoo@cybrosys.com) |
|||
# |
|||
# 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 <http://www.gnu.org/licenses/>. |
|||
# |
|||
################################################################################ |
|||
from . import low_sale_pivot_view_report |
@ -0,0 +1,130 @@ |
|||
# -*- coding: utf-8 -*- |
|||
################################################################################ |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>). |
|||
# Author: Raveena V (odoo@cybrosys.com) |
|||
# |
|||
# 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 <http://www.gnu.org/licenses/>. |
|||
# |
|||
################################################################################ |
|||
from odoo import fields, models |
|||
|
|||
|
|||
class LowSalePivotViewReport(models.Model): |
|||
"""Pivot view report""" |
|||
_name = 'low.sale.pivot.view.report' |
|||
_description = 'LowSale Pivot View Report' |
|||
|
|||
categ_id = fields.Many2one( |
|||
comodel_name='product.category', string="Product Category", |
|||
readonly=True, help='Category id of the product') |
|||
product_id = fields.Many2one( |
|||
comodel_name='product.product', string="Product Variant", readonly=True, |
|||
help='Product_product model id') |
|||
product_tmpl_id = fields.Many2one( |
|||
comodel_name='product.template', string="Product", readonly=True, |
|||
help='Product_template model id') |
|||
product_uom_qty = fields.Float(string="Sold quantity", readonly=True, |
|||
help='Total count of the quantity to sold') |
|||
company_id = fields.Many2one('res.company', store=True, |
|||
copy=False, string="Company", |
|||
default=lambda |
|||
self: self.env.user.company_id.id, |
|||
help='Company id for the reference of the' |
|||
' monetary field') |
|||
currency_id = fields.Many2one('res.currency', string="Currency", |
|||
related='company_id.currency_id', |
|||
default=lambda |
|||
self: self.env.user.company_id.currency_id.id, |
|||
help='Currency id for the reference of the ' |
|||
'monetary field') |
|||
price_total = fields.Monetary(string="Total", readonly=True, |
|||
help='Total price of the product sold') |
|||
|
|||
def get_data(self, low_sale_report): |
|||
"""Fetching the data for the pivot view and the Excel report using |
|||
the sql query""" |
|||
conditions = [] |
|||
filters = [] |
|||
if low_sale_report['analysed_period_start'] and low_sale_report[ |
|||
'analysed_period_end']: |
|||
filters.append(f"o.date_order BETWEEN '" |
|||
f"{low_sale_report['analysed_period_start']}" |
|||
f"' AND '" |
|||
f"{low_sale_report['analysed_period_end']}'") |
|||
if low_sale_report['absolute_qty'] > 0: |
|||
conditions.append( |
|||
f"COALESCE(SUM(CASE WHEN o.state = 'sale' THEN " |
|||
f"l.product_uom_qty ELSE 0 END), 0) <= " |
|||
f"{low_sale_report['absolute_qty']}") |
|||
if low_sale_report['category']: |
|||
filters.append( |
|||
"t.categ_id = %s" % int(low_sale_report['category'][0])) |
|||
if low_sale_report['sale_team']: |
|||
filters.append( |
|||
"o.team_id = %s" % int(low_sale_report['sale_team'][0])) |
|||
if low_sale_report['product_type'] == 'variant': |
|||
query = """ |
|||
SELECT |
|||
p.id AS product_id, |
|||
COALESCE(SUM(CASE WHEN o.state = 'sale' THEN |
|||
l.product_uom_qty ELSE 0 END), 0) AS |
|||
total_sold_quantity, |
|||
COALESCE(SUM(CASE WHEN o.state = 'sale' THEN |
|||
l.price_total ELSE 0 END), 0) AS price_total, |
|||
t.name->>'en_US' AS product_name |
|||
FROM |
|||
product_product p |
|||
LEFT JOIN |
|||
product_template t ON p.product_tmpl_id = t.id |
|||
LEFT JOIN |
|||
sale_order_line l ON p.id = l.product_id |
|||
LEFT JOIN |
|||
sale_order o ON l.order_id = o.id |
|||
""" + ('WHERE ' + ' AND '.join(filters) if |
|||
filters else '') + """ |
|||
GROUP BY |
|||
p.id, t.name |
|||
""" + ('HAVING ' + ' AND '.join(conditions) if |
|||
conditions else '') + """ |
|||
""" |
|||
else: |
|||
query = """ |
|||
SELECT |
|||
t.id AS product_tmpl_id, |
|||
COALESCE(SUM(CASE WHEN o.state = 'sale' THEN |
|||
l.product_uom_qty ELSE 0 END), 0) AS |
|||
total_sold_quantity, |
|||
COALESCE(SUM(CASE WHEN o.state = 'sale' THEN |
|||
l.price_total ELSE 0 END), 0) AS price_total, |
|||
t.name->>'en_US' AS product_name |
|||
FROM |
|||
product_template t |
|||
LEFT JOIN |
|||
product_product p ON t.id = p.product_tmpl_id |
|||
LEFT JOIN |
|||
sale_order_line l ON p.id = l.product_id |
|||
LEFT JOIN |
|||
sale_order o ON l.order_id = o.id |
|||
""" + ('WHERE ' + ' AND '.join(filters) if |
|||
filters else '') + """ |
|||
GROUP BY |
|||
t.id, t.name |
|||
""" + ('HAVING ' + ' AND '.join(conditions) if |
|||
conditions else '') + """ |
|||
""" |
|||
self.env.cr.execute(query) |
|||
test = self.env.cr.fetchall() |
|||
return test |
@ -0,0 +1,30 @@ |
|||
<?xml version="1.0" encoding="UTF-8" ?> |
|||
<odoo> |
|||
<!-- View for variant --> |
|||
<record id="low_sale_pivot_view_report_view_pivot_variant" |
|||
model="ir.ui.view"> |
|||
<field name="name">low.sale.pivot.view.report.view.pivot.variant</field> |
|||
<field name="model">low.sale.pivot.view.report</field> |
|||
<field name="arch" type="xml"> |
|||
<pivot string="Low Sale Report"> |
|||
<field name="product_id" type="row"/> |
|||
<field name="price_total" type="measure"/> |
|||
<field name="product_uom_qty" type="measure"/> |
|||
</pivot> |
|||
</field> |
|||
</record> |
|||
<!-- View for template --> |
|||
<record id="low_sale_pivot_view_report_view_pivot_template" |
|||
model="ir.ui.view"> |
|||
<field name="name">low.sale.pivot.view.report.view.pivot.template |
|||
</field> |
|||
<field name="model">low.sale.pivot.view.report</field> |
|||
<field name="arch" type="xml"> |
|||
<pivot string="Low Sale Report"> |
|||
<field name="product_tmpl_id" type="row"/> |
|||
<field name="price_total" type="measure"/> |
|||
<field name="product_uom_qty" type="measure"/> |
|||
</pivot> |
|||
</field> |
|||
</record> |
|||
</odoo> |
|
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 28 KiB |
After Width: | Height: | Size: 628 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 210 KiB |
After Width: | Height: | Size: 209 KiB |
After Width: | Height: | Size: 109 KiB |
After Width: | Height: | Size: 495 B |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 624 B |
After Width: | Height: | Size: 136 KiB |
After Width: | Height: | Size: 214 KiB |
After Width: | Height: | Size: 36 KiB |
After Width: | Height: | Size: 3.6 KiB |
After Width: | Height: | Size: 310 B |
After Width: | Height: | Size: 929 B |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 3.3 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 17 KiB |
After Width: | Height: | Size: 542 B |
After Width: | Height: | Size: 576 B |
After Width: | Height: | Size: 733 B |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 4.0 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 175 KiB |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 911 B |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 600 B |
After Width: | Height: | Size: 673 B |
After Width: | Height: | Size: 2.0 KiB |
After Width: | Height: | Size: 462 B |
After Width: | Height: | Size: 2.1 KiB |
After Width: | Height: | Size: 926 B |
After Width: | Height: | Size: 9.0 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 7.0 KiB |
After Width: | Height: | Size: 878 B |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 653 B |
After Width: | Height: | Size: 800 B |
After Width: | Height: | Size: 905 B |
After Width: | Height: | Size: 189 KiB |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 839 B |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 5.9 KiB |
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 34 KiB |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 3.8 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 427 B |
After Width: | Height: | Size: 627 B |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 988 B |
After Width: | Height: | Size: 3.7 KiB |
After Width: | Height: | Size: 5.0 KiB |
After Width: | Height: | Size: 875 B |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 90 KiB |
After Width: | Height: | Size: 138 KiB |
After Width: | Height: | Size: 710 KiB |
After Width: | Height: | Size: 92 KiB |
After Width: | Height: | Size: 738 KiB |
After Width: | Height: | Size: 697 KiB |
After Width: | Height: | Size: 113 KiB |
After Width: | Height: | Size: 122 KiB |
After Width: | Height: | Size: 120 KiB |
After Width: | Height: | Size: 49 KiB |
After Width: | Height: | Size: 68 KiB |
After Width: | Height: | Size: 62 KiB |
After Width: | Height: | Size: 880 KiB |
After Width: | Height: | Size: 123 KiB |
After Width: | Height: | Size: 9.7 KiB |
@ -0,0 +1,15 @@ |
|||
/** @odoo-module **/ |
|||
/** Xlsx report action manager */ |
|||
import { registry } from "@web/core/registry"; |
|||
import { BlockUI } from "@web/core/ui/block_ui"; |
|||
import { download } from "@web/core/network/download"; |
|||
registry.category("ir.actions.report handlers").add("xlsx", async function (action) { |
|||
if (action.report_type === 'low_sale_xlsx_download') { |
|||
BlockUI; |
|||
await download({ |
|||
url: '/sale_low_xlsx_reports', |
|||
data: action.data, |
|||
complete: () => unblockUI, |
|||
error: (error) => self.call('crash_manager', 'rpc_error', error), |
|||
}); |
|||
}}); |
@ -0,0 +1,25 @@ |
|||
<?xml version="1.0" encoding="UTF-8" ?> |
|||
<odoo> |
|||
<!-- Creating a session to the sale settings for creating the low sales report--> |
|||
<record id="res_config_settings_view_form" model="ir.ui.view"> |
|||
<field name="name">res.config.settings.view.form.inherit.low.sale.report</field> |
|||
<field name="model">res.config.settings</field> |
|||
<field name="inherit_id" ref="sale.res_config_settings_view_form"/> |
|||
<field name="arch" type="xml"> |
|||
<xpath expr="//app[@name='sale_management']" position="inside"> |
|||
<block title="Low Sales Report"> |
|||
<setting string="Default Report Type" help="Define the default type for the low sales report. |
|||
Should analysis be made for product templates in general or for product variants?"> |
|||
<field name="product_type"/> |
|||
</setting> |
|||
<setting string="Default critical level (absolute quantity)" help="Define the default critical level for sales (default unit of measure),under which products are considered poorly performing"> |
|||
<field name="absolute_qty"/> |
|||
</setting> |
|||
<setting string="Default analyzed period" help="Define which period should be analyzed by default"> |
|||
<field name="analysed_period"/> |
|||
</setting> |
|||
</block> |
|||
</xpath> |
|||
</field> |
|||
</record> |
|||
</odoo> |
@ -0,0 +1,22 @@ |
|||
# -*- coding: utf-8 -*- |
|||
################################################################################ |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>). |
|||
# Author: Raveena V (odoo@cybrosys.com) |
|||
# |
|||
# 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 <http://www.gnu.org/licenses/>. |
|||
# |
|||
################################################################################ |
|||
from . import low_sale_report |
@ -0,0 +1,211 @@ |
|||
# -*- coding: utf-8 -*- |
|||
################################################################################ |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>). |
|||
# Author: Raveena V (odoo@cybrosys.com) |
|||
# |
|||
# 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 <http://www.gnu.org/licenses/>. |
|||
# |
|||
################################################################################ |
|||
import io |
|||
import json |
|||
from odoo import api, fields, models, _ |
|||
from odoo.exceptions import ValidationError |
|||
from odoo.tools import json_default |
|||
from dateutil.relativedelta import relativedelta |
|||
try: |
|||
from odoo.tools.misc import xlsxwriter |
|||
except ImportError: |
|||
import xlsxwriter |
|||
|
|||
|
|||
class LowSaleReport(models.TransientModel): |
|||
"""Its define as the sale low performance product details in pivot view and |
|||
the Excel report.""" |
|||
_name = 'low.sale.report' |
|||
_description = 'Low Sale Report' |
|||
|
|||
product_type = fields.Selection( |
|||
[('variant', 'By product variant'), |
|||
('template', 'By product templates')], string="Report Type", |
|||
help='Which sale to take into account: Product templates in general' |
|||
' or variants?', required=True) |
|||
analysed_period_start = fields.Date(string='Period under analysis', |
|||
help='If not chosen, all product sale' |
|||
' will be analysed') |
|||
analysed_period_end = fields.Date(string='Period under analysis', |
|||
help='If not chosen, all product sale' |
|||
' will be analysed', |
|||
default=fields.Date.today()) |
|||
absolute_qty = fields.Float(string='Critical Level(Absolute Quantity)', |
|||
help='Which sale level are considered to be' |
|||
' low(in default unit of measurement) ', |
|||
required=True) |
|||
category = fields.Many2one('product.category', |
|||
string='Product Categories', |
|||
help='If not chosen, all product categories ' |
|||
'wil be analysed') |
|||
sale_team = fields.Many2one('crm.team', |
|||
help='If not chosen, all the sale team will' |
|||
' be analysed', string='Sales Teams') |
|||
|
|||
def action_pivot_low_sale_report(self): |
|||
"""Exporting the low sale report as the pivot view format in odoo""" |
|||
low_sale_report = { |
|||
'product_type': self.product_type, |
|||
'analysed_period_start': self.analysed_period_start, |
|||
'analysed_period_end': self.analysed_period_end, |
|||
'absolute_qty': self.absolute_qty, |
|||
'category': self.category, |
|||
'sale_team': self.sale_team |
|||
} |
|||
pivot_data = self.env['low.sale.pivot.view.report'].get_data( |
|||
low_sale_report) |
|||
if not pivot_data: |
|||
raise ValidationError( |
|||
_("No data was found for the specified criteria")) |
|||
pivot_records = [] |
|||
for data in pivot_data: |
|||
values = { |
|||
'price_total': data[2], |
|||
'product_uom_qty': data[1] |
|||
} |
|||
if self.product_type == 'variant': |
|||
values['product_id'] = data[0] |
|||
view_id = self.env.ref( |
|||
'low_sale_report.' |
|||
'low_sale_pivot_view_report_view_pivot_variant').id |
|||
else: |
|||
values['product_tmpl_id'] = data[0] |
|||
view_id = self.env.ref( |
|||
'low_sale_report.' |
|||
'low_sale_pivot_view_report_view_pivot_template').id |
|||
pivot_data_records = self.env['low.sale.pivot.view.report'].create( |
|||
values) |
|||
pivot_records.append(pivot_data_records.id) |
|||
return { |
|||
'name': 'Low Sale Pivot View Report', |
|||
'type': 'ir.actions.act_window', |
|||
'res_model': 'low.sale.pivot.view.report', |
|||
'view_mode': 'pivot', |
|||
'view_id': view_id, |
|||
'domain': [('id', 'in', pivot_records)], |
|||
} |
|||
|
|||
def action_excel_low_sale_report(self): |
|||
"""Exporting the low sale report as the Excel view format in odoo""" |
|||
self.ensure_one() |
|||
data = {'ids': self.env.context.get('active_ids', []), |
|||
'model': self.env.context.get('active_model', 'ir.ui.menu'), |
|||
'form': self.read( |
|||
['product_type', 'analysed_period_start', |
|||
'analysed_period_end', 'absolute_qty', |
|||
'category', 'sale_team'])[0]} |
|||
return { |
|||
'type': 'ir.actions.report', |
|||
'data': {'model': 'low.sale.report', |
|||
'options': json.dumps(data, default=json_default), |
|||
'output_format': 'xlsx', |
|||
'report_name': 'Low Sale Report', |
|||
}, |
|||
'report_type': 'low_sale_xlsx_download' |
|||
} |
|||
|
|||
def get_low_sale_xlsx_report(self, options, response): |
|||
"""Generate the Excel report based on the provided options and write it |
|||
to the response.""" |
|||
output = io.BytesIO() |
|||
workbook = xlsxwriter.Workbook(output, {'in_memory': True}) |
|||
data = {'form': options['form'], 'model': 'ir.ui.menu', 'ids': []} |
|||
data['form']['used_context'] = { |
|||
'product_type': options['form']['product_type'], |
|||
'analysed_period_start': options['form']['analysed_period_start'], |
|||
'analysed_period_end': options['form']['analysed_period_end'], |
|||
'absolute_qty': options['form']['absolute_qty'], |
|||
'active_model': None, |
|||
'active_ids': None, |
|||
'active_id': None, |
|||
'category': options['form']['category'], |
|||
'sale_team': options['form']['sale_team'], |
|||
} |
|||
form_data = data['form'] |
|||
fetch_datas = self.env['low.sale.pivot.view.report'].get_data(form_data) |
|||
if not fetch_datas: |
|||
raise ValidationError( |
|||
_("No data was found for the specified criteria.")) |
|||
worksheet = workbook.add_worksheet() |
|||
name_formate = workbook.add_format( |
|||
{'bold': True, 'align': 'center', 'valign': 'vcenter', 'border': 1, |
|||
'bg_color': '#D3D3D3', 'font_size': 16}) |
|||
format2 = workbook.add_format( |
|||
{'font_size': 12, 'bold': True, 'bg_color': '#D3D3D3'}) |
|||
rows = 0 |
|||
cols = 0 |
|||
worksheet.merge_range(rows, cols, rows + 1, cols + 3, |
|||
'Low Sale Report', name_formate) |
|||
worksheet.set_column('B:B', 35) |
|||
worksheet.set_column('C:C', 15) |
|||
worksheet.set_column('D:D', 15) |
|||
worksheet.write('A4', "ID", format2) |
|||
worksheet.write('B4', "Product", format2) |
|||
worksheet.write('C4', "Sold Quantity", format2) |
|||
worksheet.write('D4', "Revenue", format2) |
|||
# Write data to the worksheet |
|||
row_num = 5 |
|||
cols_num = 0 |
|||
for rec in fetch_datas: |
|||
worksheet.write(row_num, cols_num, rec[0]) |
|||
worksheet.write(row_num, cols_num + 1, rec[3]) |
|||
worksheet.write(row_num, cols_num + 2, rec[1]) |
|||
worksheet.write(row_num, cols_num + 3, rec[2]) |
|||
row_num += 1 |
|||
# Close the workbook |
|||
workbook.close() |
|||
# Seek to the beginning of the BytesIO buffer |
|||
output.seek(0) |
|||
# Stream the Excel file to the response |
|||
response.stream.write(output.read()) |
|||
output.close() |
|||
|
|||
@api.model |
|||
def default_get(self, fields): |
|||
"""Prefilling the wizard data into the settings field values""" |
|||
res = super().default_get(fields) |
|||
# Fetch configuration parameters from ResConfigSettings |
|||
config_params = self.env['ir.config_parameter'].sudo() |
|||
# Prefill the values based on the configuration parameters |
|||
res['product_type'] = config_params.get_param( |
|||
'low_sale_report.product_type', default='variant') |
|||
res['absolute_qty'] = config_params.get_param( |
|||
'low_sale_report.absolute_qty', default=0.0) |
|||
end_date = res.get('analysed_period_end') |
|||
if end_date: |
|||
if (config_params.get_param('low_sale_report.analysed_period') == |
|||
'last_month'): |
|||
start_date = end_date - relativedelta(days=30) |
|||
elif (config_params.get_param('low_sale_report.analysed_period') == |
|||
'last_3'): |
|||
start_date = end_date - relativedelta(months=3) |
|||
elif (config_params.get_param('low_sale_report.analysed_period') == |
|||
'last_6'): |
|||
start_date = end_date - relativedelta(months=6) |
|||
elif (config_params.get_param('low_sale_report.analysed_period') == |
|||
'last_12'): |
|||
start_date = end_date - relativedelta(months=12) |
|||
else: |
|||
# Default to last_month if no valid option is selected |
|||
start_date = end_date - relativedelta(months=12) |
|||
res['analysed_period_start'] = start_date |
|||
return res |