@ -0,0 +1,47 @@ |
|||
.. image:: https://img.shields.io/badge/license-LGPL--3-green.svg |
|||
:target: https://www.gnu.org/licenses/lgpl-3.0-standalone.html |
|||
:alt: License: LGPL-3 |
|||
|
|||
Advanced Excel Reports |
|||
====================== |
|||
This module helps to Print the excel report of the sale,invoice,picking of multiple records |
|||
|
|||
Configuration |
|||
============= |
|||
No additional configuration required |
|||
|
|||
License |
|||
------- |
|||
General Public License, Version 3 (LGPL v3). |
|||
(https://www.gnu.org/licenses/lgpl-3.0-standalone.html) |
|||
|
|||
Company |
|||
------- |
|||
* `Cybrosys Techno Solutions <https://cybrosys.com/>`__ |
|||
|
|||
Credits |
|||
------- |
|||
Developer: (v18) Ashwin T @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 Cybrosys Technologies. |
|||
|
|||
For support and more information, please visit `Our Website <https://cybrosys.com/>`__ |
|||
|
|||
Further information |
|||
=================== |
|||
HTML Description: `<static/description/index.html>`__ |
@ -0,0 +1,23 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################# |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
|||
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>) |
|||
# |
|||
# You can modify it under the terms of the GNU LESSER |
|||
# GENERAL PUBLIC LICENSE (LGPL 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 LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. |
|||
# |
|||
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE |
|||
# (LGPL v3) along with this program. |
|||
# If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################# |
|||
from . import controllers |
|||
from . import models |
@ -0,0 +1,49 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################# |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
|||
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>) |
|||
# |
|||
# You can modify it under the terms of the GNU LESSER |
|||
# GENERAL PUBLIC LICENSE (LGPL 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 LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. |
|||
# |
|||
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE |
|||
# (LGPL v3) along with this program. |
|||
# If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################# |
|||
{ |
|||
'name': "Advanced Excel Reports", |
|||
"version": "18.0.1.0.0", |
|||
"category": "Sale,Accounting,Warehouse", |
|||
"summary": """For printing excel reports of multiple records""", |
|||
"description": "Print the excel report of the sale,invoice,picking" |
|||
" of multiple records", |
|||
'author': 'Cybrosys Techno Solutions', |
|||
'company': 'Cybrosys Techno Solutions', |
|||
'maintainer': 'Cybrosys Techno Solutions', |
|||
'website': "https://www.cybrosys.com", |
|||
'depends': ['sale_management', 'account', 'stock'], |
|||
'data': [ |
|||
'data/ir_action_data.xml' |
|||
], |
|||
'assets': |
|||
{ |
|||
'web.assets_backend': [ |
|||
'advanced_excel_reports/static/src/js/excel_report.js' |
|||
], |
|||
}, |
|||
'images': [ |
|||
'static/description/banner.png'], |
|||
'license': 'LGPL-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: Cybrosys Techno Solutions(<https://www.cybrosys.com>) |
|||
# |
|||
# You can modify it under the terms of the GNU LESSER |
|||
# GENERAL PUBLIC LICENSE (LGPL 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 LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. |
|||
# |
|||
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE |
|||
# (LGPL v3) along with this program. |
|||
# If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################# |
|||
from . import advanced_excel_reports |
@ -0,0 +1,54 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################# |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
|||
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>) |
|||
# |
|||
# You can modify it under the terms of the GNU LESSER |
|||
# GENERAL PUBLIC LICENSE (LGPL 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 LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. |
|||
# |
|||
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE |
|||
# (LGPL 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.tools import html_escape |
|||
|
|||
|
|||
class XLSXReportController(http.Controller): |
|||
@http.route('/xlsx_reports', type='http', auth='user', |
|||
csrf=False) |
|||
def get_report_xlsx(self, model, options, output_format, report_name, |
|||
token='ads'): |
|||
""" Return data to python file passed from the javascript""" |
|||
session_unique_id = request.session.uid |
|||
report_object = request.env[model].with_user(session_unique_id) |
|||
options = json.loads(options) |
|||
try: |
|||
if output_format == 'xlsx': |
|||
response = request.make_response( |
|||
None, |
|||
headers=[('Content-Type', 'application/vnd.ms-excel'), ( |
|||
'Content-Disposition', |
|||
content_disposition(f"{report_name}.xlsx")) |
|||
] |
|||
) |
|||
report_object.get_xlsx_report(options, response) |
|||
response.set_cookie('fileToken', token) |
|||
return response |
|||
except Exception: |
|||
error = { |
|||
'code': 200, |
|||
'message': 'Odoo Server Error', |
|||
} |
|||
return request.make_response(html_escape(json.dumps(error))) |
@ -0,0 +1,41 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<odoo> |
|||
<data noupdate="1"> |
|||
<!-- Server action to print sale order excel report--> |
|||
<record id="action_print_sale_order_excel_report" |
|||
model="ir.actions.server"> |
|||
<field name="name">Sale Order Excel Report</field> |
|||
<field name="model_id" ref="model_sale_order"/> |
|||
<field name="binding_model_id" ref="model_sale_order"/> |
|||
<field name="binding_view_types">list</field> |
|||
<field name="state">code</field> |
|||
<field name="code"> |
|||
action = record.print_excel_report() |
|||
</field> |
|||
</record> |
|||
<!-- Server action to print invoice excel report--> |
|||
<record id="action_print_invoice_excel_report" |
|||
model="ir.actions.server"> |
|||
<field name="name">Account Invoice Excel Report</field> |
|||
<field name="model_id" ref="model_account_move"/> |
|||
<field name="binding_model_id" ref="model_account_move"/> |
|||
<field name="binding_view_types">list</field> |
|||
<field name="state">code</field> |
|||
<field name="code"> |
|||
action = record.print_excel_report() |
|||
</field> |
|||
</record> |
|||
<!-- Server action to print transfer excel report--> |
|||
<record id="action_print_picking_excel_report" |
|||
model="ir.actions.server"> |
|||
<field name="name">Picking Excel Report</field> |
|||
<field name="model_id" ref="model_stock_picking"/> |
|||
<field name="binding_model_id" ref="model_stock_picking"/> |
|||
<field name="binding_view_types">list</field> |
|||
<field name="state">code</field> |
|||
<field name="code"> |
|||
action = record.print_excel_report() |
|||
</field> |
|||
</record> |
|||
</data> |
|||
</odoo> |
@ -0,0 +1,6 @@ |
|||
## Module <advanced_excel_reports> |
|||
|
|||
#### 10.10.2024 |
|||
#### Version 18.0.1.0.0 |
|||
#### ADD |
|||
- Initial commit for Advanced Excel Reports |
@ -0,0 +1,24 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################# |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
|||
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>) |
|||
# |
|||
# You can modify it under the terms of the GNU LESSER |
|||
# GENERAL PUBLIC LICENSE (LGPL 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 LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. |
|||
# |
|||
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE |
|||
# (LGPL v3) along with this program. |
|||
# If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################# |
|||
from . import account_move |
|||
from . import sale_order |
|||
from . import stock_picking |
@ -0,0 +1,174 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################# |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
|||
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>) |
|||
# |
|||
# You can modify it under the terms of the GNU LESSER |
|||
# GENERAL PUBLIC LICENSE (LGPL 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 LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. |
|||
# |
|||
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE |
|||
# (LGPL v3) along with this program. |
|||
# If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################# |
|||
import io |
|||
import json |
|||
import xlsxwriter |
|||
from odoo import models |
|||
from odoo.tools import json_default |
|||
|
|||
|
|||
class AccountMove(models.Model): |
|||
""" Added function for printing excel report |
|||
which is coming from a server action """ |
|||
_inherit = "account.move" |
|||
|
|||
def print_excel_report(self): |
|||
""" Function is used to print the Excel report |
|||
It will pass the invoice data through js file to |
|||
print Excel file""" |
|||
# Take the ids of the selected invoices |
|||
data = self._context['active_ids'] |
|||
return { |
|||
'type': 'ir.actions.report', |
|||
'report_type': 'xlsx', |
|||
'data': {'model': 'account.move', |
|||
'output_format': 'xlsx', |
|||
'options': json.dumps(data, |
|||
default=json_default), |
|||
'report_name': 'Invoice Excel Report', }, } |
|||
|
|||
def get_xlsx_report(self, datas, response): |
|||
""" From this function we can create and design the Excel file template |
|||
and the map the values in the corresponding cells |
|||
:param datas: Selected record ids |
|||
:param response: Response after creating excel |
|||
""" |
|||
output = io.BytesIO() |
|||
workbook = xlsxwriter.Workbook(output, {'in_memory': True}) |
|||
# for printing multiple sheet per file, iterate the invoices |
|||
for account_move in self.env['account.move'].browse(datas): |
|||
# Set file title as invoice when it is invoice and set bill |
|||
# if the move_type is out_invoice |
|||
account_name = 'INVOICE - ' + account_move.name if \ |
|||
account_move.move_type == 'out_invoice' else \ |
|||
'VENDOR BILL - ' + account_move.name |
|||
company_name = 'Company Name : ' + account_move.company_id.name |
|||
# Copy the value to a variable set black if it is null |
|||
# instead of printing 'FALSE' in the report |
|||
ref = str( |
|||
account_move.payment_reference) if \ |
|||
account_move.payment_reference is not False else '' |
|||
# Copy the value to a variable set black if it is null |
|||
# instead of printing 'FALSE' in the report |
|||
payment_term = str( |
|||
account_move.invoice_payment_term_id.name) if \ |
|||
account_move.invoice_payment_term_id.name is not False else '' |
|||
# Copy the value to a variable set black if it is null instead |
|||
# of printing 'FALSE' in the report |
|||
fiscal_position = str( |
|||
account_move.fiscal_position_id.name) if \ |
|||
account_move.fiscal_position_id.name is not False else '' |
|||
# Copy the value to a variable set black if it is null |
|||
# instead of printing 'FALSE' in the report |
|||
sale_person = account_move.user_id.name if \ |
|||
account_move.user_id.name is not False else '' |
|||
# Copy the value to a variable set black if it is null |
|||
# instead of printing 'FALSE' in the report |
|||
incoterm = account_move.invoice_incoterm_id.name if \ |
|||
account_move.invoice_incoterm_id.name is not False else '' |
|||
invoice_date = str(account_move.invoice_date) |
|||
currency_symbol = account_move.currency_id.symbol |
|||
sheet = workbook.add_worksheet( |
|||
account_move.name) # Set sheet name as Invoice/Bill name |
|||
sheet.set_column(0, 8, 20) |
|||
head = workbook.add_format( |
|||
{'align': 'center', 'bold': True, 'font_size': '20px'}) |
|||
txt = workbook.add_format( |
|||
{'align': 'center', 'bold': True}) |
|||
txt_border = workbook.add_format( |
|||
{'align': 'center', 'bold': True, 'border': 1}) |
|||
border = workbook.add_format({'border': 1}) |
|||
sheet.merge_range('B2:E3', account_name, head) |
|||
sheet.merge_range('B4:E4', company_name, txt) |
|||
sheet.write('A6', 'Customer/Vendor Name', txt) |
|||
sheet.write('B6', account_move.partner_id.name) |
|||
sheet.write('B7', account_move.partner_id.street) |
|||
sheet.write('B8', account_move.partner_id.state_id.name) |
|||
sheet.write('B9', account_move.partner_id.zip) |
|||
sheet.write('B10', account_move.partner_id.country_id.name) |
|||
sheet.write('B11', account_move.partner_id.phone) |
|||
sheet.write('D6', 'Date', txt) |
|||
sheet.write('D7', 'Payment Term', txt) |
|||
sheet.write('D8', 'Journal', txt) |
|||
sheet.write('D9', 'Currency', txt) |
|||
sheet.write('D10', 'State', txt) |
|||
sheet.write('E6', invoice_date) |
|||
sheet.write('E7', payment_term) |
|||
sheet.write('E8', account_move.journal_id.name) |
|||
sheet.write('E9', account_move.currency_id.name) |
|||
sheet.write('E10', account_move.state) |
|||
sheet.write('A13', 'Sales Persons', txt) |
|||
sheet.write('A14', sale_person) |
|||
sheet.write('B13', 'Source Document', txt) |
|||
sheet.write('B14', ref) |
|||
sheet.write('C13', 'Fiscal Position', txt) |
|||
sheet.write('C14', fiscal_position) |
|||
sheet.write('D13', 'Incoterm', txt) |
|||
sheet.write('D14', incoterm) |
|||
sheet.write('A16', 'Product', txt_border) |
|||
sheet.write('B16', 'Description', txt_border) |
|||
sheet.write('C16', 'Quantity', txt_border) |
|||
sheet.write('D16', 'Account', txt_border) |
|||
sheet.write('E16', 'Discount %', txt_border) |
|||
sheet.write('F16', 'Unit Price', txt_border) |
|||
sheet.write('G16', 'Tax', txt_border) |
|||
sheet.write('H16', 'Subtotal', txt_border) |
|||
row = 17 |
|||
self._add_invoice_line_to_excel(sheet, account_move, row, border, txt_border, |
|||
currency_symbol) |
|||
workbook.close() |
|||
output.seek(0) |
|||
response.stream.write(output.read()) |
|||
output.close() |
|||
|
|||
def _add_invoice_line_to_excel(self, sheet, account_move, row, border, txt_border, |
|||
currency_symbol): |
|||
""" |
|||
Function to add invoice line values to the Excel file |
|||
:param sheet: Current Excel sheet where data to be added |
|||
:param account_move : Object of invoice in which data adding |
|||
:param row:Excel row value of next data to be added |
|||
:param border :Excel styling for adding border for each cell |
|||
:param txt_border : Excel styling for adding data in each cell |
|||
:param currency_symbol : Currency symbol of current record |
|||
""" |
|||
for line in account_move.invoice_line_ids: |
|||
# For adding value of the invoice lines |
|||
tax = str( |
|||
line.tax_ids.name) if line.tax_ids.name \ |
|||
is not False else '' |
|||
sheet.write(row, 0, line.product_id.name, border) |
|||
sheet.write(row, 1, line.name, border) |
|||
sheet.write(row, 2, line.quantity, border) |
|||
sheet.write(row, 3, line.account_id.display_name, border) |
|||
sheet.write(row, 4, line.discount, border) |
|||
sheet.write(row, 5, line.price_unit, border) |
|||
sheet.write(row, 6, tax, border) |
|||
sheet.write(row, 7, |
|||
str(currency_symbol) + str(line.price_subtotal), |
|||
border) |
|||
row += 1 |
|||
row += 1 |
|||
sheet.write(row, 6, 'Total Amount', txt_border) |
|||
sheet.write(row, 7, |
|||
str(currency_symbol) + str(account_move.amount_total), |
|||
border) |
@ -0,0 +1,160 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################# |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
|||
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>) |
|||
# |
|||
# You can modify it under the terms of the GNU LESSER |
|||
# GENERAL PUBLIC LICENSE (LGPL 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 LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. |
|||
# |
|||
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE |
|||
# (LGPL v3) along with this program. |
|||
# If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################# |
|||
import io |
|||
import json |
|||
import xlsxwriter |
|||
from odoo import models |
|||
from odoo.tools import json_default |
|||
|
|||
|
|||
class SaleOrder(models.Model): |
|||
""" Added a function that to print sale order excel report |
|||
which is added through server action """ |
|||
_inherit = "sale.order" |
|||
|
|||
def print_excel_report(self): |
|||
""" Function is used to print the Excel report |
|||
It will pass the sale order data through js file to |
|||
print Excel file""" |
|||
# Take the ids of the selected sale orders |
|||
data = self._context['active_ids'] |
|||
return { |
|||
'type': 'ir.actions.report', |
|||
'report_type': 'xlsx', |
|||
'data': {'model': 'sale.order', |
|||
'output_format': 'xlsx', |
|||
'options': json.dumps(data, |
|||
default=json_default), |
|||
'report_name': 'Sale/Quotation Excel Report', }, } |
|||
|
|||
def get_xlsx_report(self, datas, response): |
|||
""" From this function we can create and design the Excel file template |
|||
and the map the values in the corresponding cells |
|||
:param datas:Selected record ids |
|||
:param response: Response after creating excel |
|||
""" |
|||
output = io.BytesIO() |
|||
workbook = xlsxwriter.Workbook(output, {'in_memory': True}) |
|||
# for printing multiple sheet per file, iterate the sale orders |
|||
for sale in self.env['sale.order'].browse(datas): |
|||
sale_name = 'SALE ORDER - ' + sale.name |
|||
company_name = 'Company Name : ' + sale.company_id.name |
|||
# Copy the value to a variable set black if it is null |
|||
# instead of printing 'FALSE' in the report |
|||
ref = str( |
|||
sale.client_order_ref) if \ |
|||
sale.client_order_ref is not False else '' |
|||
# Copy the value to a variable set black if it is null instead |
|||
# of printing 'FALSE' in the report |
|||
payment_term = str( |
|||
sale.payment_term_id.name) if \ |
|||
sale.payment_term_id.name is not False else '' |
|||
# Copy the value to a variable set black if it is null instead |
|||
# of printing 'FALSE' in the report |
|||
fiscal_position = str( |
|||
sale.fiscal_position_id.name) if \ |
|||
sale.fiscal_position_id.name is not False else '' |
|||
sheet = workbook.add_worksheet( |
|||
sale.name) # set the sheet name as sale order name |
|||
sheet.set_column(0, 8, 20) |
|||
sale_date = str(sale.date_order) |
|||
currency_symbol = sale.currency_id.symbol |
|||
head = workbook.add_format( |
|||
{'align': 'center', 'bold': True, 'font_size': '20px'}) |
|||
txt = workbook.add_format({'align': 'center', 'bold': True}) |
|||
txt_border = workbook.add_format( |
|||
{'align': 'center', 'bold': True, 'border': 1}) |
|||
border = workbook.add_format({'border': 1}) |
|||
sheet.merge_range('B2:E3', sale_name, head) |
|||
sheet.merge_range('B4:E4', company_name, txt) |
|||
sheet.write('A6', 'Customer Name', txt) |
|||
sheet.write('B6', sale.partner_id.name) |
|||
sheet.write('B7', sale.partner_id.street) |
|||
sheet.write('B8', sale.partner_id.state_id.name) |
|||
sheet.write('B9', sale.partner_id.zip) |
|||
sheet.write('B10', sale.partner_id.country_id.name) |
|||
sheet.write('B11', sale.partner_id.phone) |
|||
sheet.write('D6', 'Date', txt) |
|||
sheet.write('D7', 'Payment Term', txt) |
|||
sheet.write('D8', 'Price List', txt) |
|||
sheet.write('D9', 'State', txt) |
|||
sheet.write('E6', sale_date) |
|||
sheet.write('E7', payment_term) |
|||
sheet.write('E8', sale.pricelist_id.name) |
|||
sheet.write('E9', sale.state) |
|||
sheet.write('A13', 'Sales Team', txt) |
|||
sheet.write('A14', sale.team_id.name) |
|||
sheet.write('B13', 'Sales Persons', txt) |
|||
sheet.write('B14', sale.user_id.name) |
|||
sheet.write('C13', 'Source Document', txt) |
|||
sheet.write('C14', ref) |
|||
sheet.write('D13', 'Fiscal Position', txt) |
|||
sheet.write('D14', fiscal_position) |
|||
sheet.write('A16', 'Product', txt_border) |
|||
sheet.write('B16', 'Description', txt_border) |
|||
sheet.write('C16', 'Quantity', txt_border) |
|||
sheet.write('D16', 'Delivered', txt_border) |
|||
sheet.write('E16', 'Invoiced', txt_border) |
|||
sheet.write('F16', 'Unit Price', txt_border) |
|||
sheet.write('G16', 'Tax', txt_border) |
|||
sheet.write('H16', 'Subtotal', txt_border) |
|||
row = 17 |
|||
# calling this function for adding sale order line data to the |
|||
# Excel sheet |
|||
self._add_order_line_to_excel(sheet, sale, row, border, txt_border, |
|||
currency_symbol) |
|||
workbook.close() |
|||
output.seek(0) |
|||
response.stream.write(output.read()) |
|||
output.close() |
|||
|
|||
def _add_order_line_to_excel(self, sheet, sale, row, border, txt_border, |
|||
currency_symbol): |
|||
""" |
|||
Function to add sale order line values to the Excel file |
|||
:param sheet: Current Excel sheet where data to be added |
|||
:param sale : Object of sale order in which data adding |
|||
:param row:Excel row value of next data to be added |
|||
:param border :Excel styling for adding border for each cell |
|||
:param txt_border : Excel styling for adding data in each cell |
|||
:param currency_symbol : Currency symbol of current record |
|||
""" |
|||
for line in sale.order_line: |
|||
# For adding value of the sale order lines |
|||
|
|||
tax = str( |
|||
line.tax_id.name) if line.tax_id.name is not False else '' |
|||
sheet.write(row, 0, line.product_id.name, border) |
|||
sheet.write(row, 1, line.name, border) |
|||
sheet.write(row, 2, line.product_uom_qty, border) |
|||
sheet.write(row, 3, line.qty_delivered, border) |
|||
sheet.write(row, 4, line.qty_invoiced, border) |
|||
sheet.write(row, 5, line.price_unit, border) |
|||
sheet.write(row, 6, tax, border) |
|||
sheet.write(row, 7, |
|||
str(currency_symbol) + str(line.price_subtotal), |
|||
border) |
|||
row += 1 |
|||
row += 1 |
|||
sheet.write(row, 6, 'Total Amount', txt_border) |
|||
sheet.write(row, 7, str(currency_symbol) + str(sale.amount_total), |
|||
border) |
@ -0,0 +1,167 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################# |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
|||
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>) |
|||
# |
|||
# You can modify it under the terms of the GNU LESSER |
|||
# GENERAL PUBLIC LICENSE (LGPL 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 LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. |
|||
# |
|||
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE |
|||
# (LGPL v3) along with this program. |
|||
# If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################# |
|||
import io |
|||
import json |
|||
import xlsxwriter |
|||
from odoo import models |
|||
from odoo.tools import json_default |
|||
|
|||
|
|||
class StockPicking(models.Model): |
|||
""" Added a function that to print sale order Excel report |
|||
which is added using server action """ |
|||
_inherit = "stock.picking" |
|||
|
|||
def print_excel_report(self): |
|||
""" Function is used to print the Excel report |
|||
It will pass the picking data through js file to |
|||
print Excel file""" |
|||
# Take the ids of the selected pickings |
|||
data = self._context['active_ids'] |
|||
return { |
|||
'type': 'ir.actions.report', |
|||
'report_type': 'xlsx', |
|||
'data': {'model': 'stock.picking', |
|||
'output_format': 'xlsx', |
|||
'options': json.dumps(data, |
|||
default=json_default), |
|||
'report_name': 'Picking Order Excel Report', }, } |
|||
|
|||
def get_xlsx_report(self, datas, response): |
|||
""" From this function we can create and design the Excel file template |
|||
and the map the values in the corresponding cells |
|||
:param datas:Selected record ids |
|||
:param response: Response after creating excel |
|||
""" |
|||
output = io.BytesIO() |
|||
workbook = xlsxwriter.Workbook(output, {'in_memory': True}) |
|||
# for printing multiple sheet per file, iterate the pickings |
|||
for picking in self.env['stock.picking'].browse(datas): |
|||
picking_name = 'Delivery - ' + picking.name |
|||
company_name = 'Company Name : ' + picking.company_id.name |
|||
# Copy the value to a variable set black if it is null |
|||
# instead of printing 'FALSE' in the report |
|||
ref = picking.origin if picking.origin is not False else '' |
|||
# Copy the value to a variable set black if it is null |
|||
# instead of printing 'FALSE' in the report |
|||
responsible_person = picking.user_id.name if \ |
|||
picking.user_id.name is not False else '' |
|||
# Copy the value to a variable set black if it is null |
|||
# instead of printing 'FALSE' in the report |
|||
partner_name = picking.partner_id.name if \ |
|||
picking.partner_id.name is not False else '' |
|||
# Copy the value to a variable set black if it is null instead |
|||
# of printing 'FALSE' in the report |
|||
partner_street = picking.partner_id.street if \ |
|||
picking.partner_id.street is not False else '' |
|||
# Copy the value to a variable set black if it is null instead of |
|||
# printing 'FALSE' in the report |
|||
partner_state = picking.partner_id.state_id.name if \ |
|||
picking.partner_id.state_id.name is not False else '' |
|||
# Copy the value to a variable set black if it is null instead |
|||
# of printing 'FALSE' in the report |
|||
partner_zip = picking.partner_id.zip if \ |
|||
picking.partner_id.zip is not False else '' |
|||
# Copy the value to a variable set black if it is null instead |
|||
# of printing 'FALSE' in the report |
|||
partner_county = picking.partner_id.country_id.name if \ |
|||
picking.partner_id.country_id.name is not False else '' |
|||
# Copy the value to a variable set black if it is null |
|||
# instead of printing 'FALSE' in the report |
|||
partner_phone = picking.partner_id.phone if \ |
|||
picking.partner_id.phone is not False else '' |
|||
# Copy the value to a variable set black if it is null instead |
|||
# of printing 'FALSE' in the report |
|||
date_done = str(picking.date_done) if \ |
|||
picking.date_done is not False else '' |
|||
scheduled_date = str(picking.scheduled_date) |
|||
sheet = workbook.add_worksheet( |
|||
picking.name) # set the sheet name as picking name |
|||
sheet.set_column(0, 8, 25) |
|||
head = workbook.add_format( |
|||
{'align': 'center', 'bold': True, 'font_size': '20px'}) |
|||
txt = workbook.add_format({'align': 'center', 'bold': True}) |
|||
txt_border = workbook.add_format( |
|||
{'align': 'center', 'bold': True, 'border': 1}) |
|||
border = workbook.add_format({'border': 1}) |
|||
sheet.merge_range('B2:E3', picking_name, head) |
|||
sheet.merge_range('B4:E4', company_name, txt) |
|||
sheet.write('A6', 'Customer/Vendor Name', txt) |
|||
sheet.write('B6', partner_name) |
|||
sheet.write('B7', partner_street) |
|||
sheet.write('B8', partner_state) |
|||
sheet.write('B9', partner_zip) |
|||
sheet.write('B10', partner_county) |
|||
sheet.write('B11', partner_phone) |
|||
sheet.write('D6', 'Scheduled Date', txt) |
|||
sheet.write('D7', 'Effective Date', txt) |
|||
sheet.write('D8', 'Operation Type', txt) |
|||
sheet.write('D9', 'Source Location', txt) |
|||
sheet.write('D10', 'Destination Location', txt) |
|||
sheet.write('D11', 'State', txt) |
|||
sheet.write('E6', scheduled_date) |
|||
sheet.write('E7', date_done) |
|||
sheet.write('E8', picking.picking_type_id.display_name) |
|||
sheet.write('E9', picking.location_id.complete_name) |
|||
sheet.write('E10', picking.location_dest_id.complete_name) |
|||
sheet.write('E11', picking.state) |
|||
sheet.write('A13', 'Responsible Person', txt) |
|||
sheet.write('A14', responsible_person) |
|||
sheet.write('B13', 'Source Document', txt) |
|||
sheet.write('B14', ref) |
|||
sheet.write('A16', 'Product', txt_border) |
|||
sheet.write('B16', 'Description', txt_border) |
|||
sheet.write('C16', 'Scheduled Date', txt_border) |
|||
sheet.write('D16', 'Deadline', txt_border) |
|||
sheet.write('E16', 'Quantity', txt_border) |
|||
sheet.write('F16', 'Quantity Done', txt_border) |
|||
row = 17 |
|||
# calling this function for adding picking line data to the |
|||
# Excel sheet |
|||
self._add_picking_line_to_excel(sheet, picking, row, border) |
|||
workbook.close() |
|||
output.seek(0) |
|||
response.stream.write(output.read()) |
|||
output.close() |
|||
|
|||
def _add_picking_line_to_excel(self, sheet, picking, row, border): |
|||
""" |
|||
Function to add stock picking line values to the Excel file |
|||
:param sheet: Current Excel sheet where data to be added |
|||
:param picking : Object of transfer in which data adding |
|||
:param row:Excel row value of next data to be added |
|||
:param border :Excel styling for adding border for each cell |
|||
""" |
|||
# For adding value of the sale order line |
|||
for line in picking.move_ids: |
|||
# Copy the value to a variable set black if it is null |
|||
# instead of printing 'FALSE' in the report |
|||
date_deadline = str(line.date_deadline) if \ |
|||
line.date_deadline is not False else '' |
|||
date = str(line.date) |
|||
sheet.write(row, 0, line.product_id.name, border) |
|||
sheet.write(row, 1, line.description_picking, border) |
|||
sheet.write(row, 2, date, border) |
|||
sheet.write(row, 3, date_deadline, border) |
|||
sheet.write(row, 4, line.product_uom_qty, border) |
|||
sheet.write(row, 5, line.quantity, border) |
|||
row += 1 |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 28 KiB |
After Width: | Height: | Size: 628 KiB |
After Width: | Height: | Size: 281 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: 738 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: 912 KiB |
After Width: | Height: | Size: 1.3 MiB |
After Width: | Height: | Size: 46 KiB |
After Width: | Height: | Size: 44 KiB |
After Width: | Height: | Size: 46 KiB |
After Width: | Height: | Size: 85 KiB |
After Width: | Height: | Size: 160 KiB |
After Width: | Height: | Size: 142 KiB |
After Width: | Height: | Size: 92 KiB |
After Width: | Height: | Size: 141 KiB |
After Width: | Height: | Size: 90 KiB |
After Width: | Height: | Size: 138 KiB |
After Width: | Height: | Size: 880 KiB |
After Width: | Height: | Size: 91 KiB |
After Width: | Height: | Size: 9.8 KiB |
@ -0,0 +1,17 @@ |
|||
/** @odoo-module **/ |
|||
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(action)=> { |
|||
//Passing data to the controller to print the excel file
|
|||
if (action.report_type === 'xlsx') { |
|||
BlockUI; |
|||
await download({ |
|||
url: '/xlsx_reports', |
|||
data: action.data, |
|||
complete: () => unblockUI, |
|||
error: (error) => self.call('crash_manager', 'rpc_error', error), |
|||
}); |
|||
return true |
|||
} |
|||
}); |