Skip to Content
Odoo Menu
  • Prijavi
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Knjigovodstvo
  • Zaloga
  • PoS
  • Projekt
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
Pomoč

File downloading as .doc instead of .xls

Naroči se

Get notified when there's activity on this post

This question has been flagged
xls_reportsv15
2494 Prikazi
Avatar
Vault Odoo

I have customized a new report in excel. In a wizard, after selecting the required fields, one button is given to print. That time one new file will be created and shows in a field. From there we can download it.

But after downloading the extension seems like .doc instead of .xls. In the linux system it's opening in the Excel but in the windows system it's showing error. Following is my code.

import xlwt
import base64
from io import BytesIO
from odoo import models, fields, api, _
from odoo.exceptions import UserError, ValidationError, Warning
from datetime import date

class ZambiaSalePurchaseReport(models.TransientModel):
_name = "zambia.sale.purchase.report"
_description = "Zambia Sale Purchase Report"

start_date = fields.Date(required=True)
end_date = fields.Date(required=True)
report_type = fields.Selection([('sale', 'Sale'), ('purchase', 'Purchase')], required=True)
tax_id = fields.Many2one('account.tax')
company_id = fields.Many2one('res.company', string='Company', required=True,
default=lambda self: self.env.company)
state = fields.Selection([('choose', 'choose'), ('get', 'get')],
default='choose')
file_name = fields.Binary('Tax Report', readonly=True)
summary_data = fields.Char('Name', size=256)

def print_xls_report(self):
report_type = {'sale':'Sale Report','purchase':'Purchase Report'}
if self.start_date > self.end_date:
raise UserError(_("Can not select start date greater than end date"))
file_name = report_type.get(self.report_type) +str(self.start_date)+'TO'+str(self.end_date)+'.xls'

workbook = xlwt.Workbook(encoding="UTF-8")
format0 = xlwt.easyxf(
'font:height 500,bold True;pattern: pattern solid, fore_colour gray25;align: horiz center; borders: top_color black, bottom_color black, right_color black, left_color black,\
left thin, right thin, top thin, bottom thin;')
formathead2 = xlwt.easyxf(
'font:height 250,bold True;pattern: pattern solid, fore_colour gray25;align: horiz center; borders: top_color black, bottom_color black, right_color black, left_color black,\
left thin, right thin, top thin, bottom thin;')
format1 = xlwt.easyxf('font:bold True;pattern: pattern solid, fore_colour gray25;align: horiz left; borders: top_color black, bottom_color black, right_color black, left_color black,\
left thin, right thin, top thin, bottom thin;')
format2 = xlwt.easyxf('font:bold True;align: horiz left')
format3 = xlwt.easyxf('align: horiz left; borders: top_color black, bottom_color black, right_color black, left_color black,\
left thin, right thin, top thin, bottom thin;')

row, col = 8, 0
report_type = {'sale': 'Sale Report', 'purchase': 'Purchase Report'}
sheet = workbook.add_sheet(report_type.get(self.report_type))

sheet.col(0).width = int(30 * 260)
sheet.col(1).width = int(30 * 260)
sheet.col(2).width = int(30 * 260)
sheet.col(3).width = int(30 * 260)
sheet.col(4).width = int(50 * 260)
sheet.col(5).width = int(30 * 260)
sheet.col(6).width = int(30 * 260)
sheet.col(7).width = int(30 * 260)
sheet.col(8).width = int(30 * 260)

sheet.row(0).height_mismatch = True
sheet.row(0).height = 150 * 4

sheet.row(1).height_mismatch = True
sheet.row(1).height = 150 * 4

sheet.write_merge(0, 0, 0, 4, report_type.get(self.report_type), format0)
sheet.write_merge(1, 1, 0, 4, 'Start Date:' + str(self.start_date) + 'End Date:' + str(self.end_date), formathead2)

sheet.row(2).height_mismatch = True
sheet.row(2).height = 150 * 3

report_type = {'sale': 'Sale Report', 'purchase': 'Purchase Report'}

if self.report_type == 'sale':
order_ids = self.env['account.move'].search([
('invoice_date', '>=', self.start_date),
('invoice_date', '<=', self.end_date),
('company_id', '=', self.company_id.id),
('move_type', 'in', ['out_invoice', 'out_refund']),
('state', '=', 'posted')], order="id asc")

date = str(self.start_date) + ' - ' + str(self.end_date)
sheet.write(2, 0, 'TPIN of Purchaser', formathead2)
sheet.write(2, 1, 'Name Of Purchaser', formathead2)
sheet.write(2, 2, 'Invoice Number', formathead2)
sheet.write(2, 3, 'Invoice Date', formathead2)
sheet.write(2, 4, "Description Of Goods & Services", formathead2)
sheet.write(2, 5, "Amount Before Tax", formathead2)
sheet.write(2, 6, "Local Excise Duty", formathead2)
sheet.write(2, 7, "Total", formathead2)
sheet.write(2, 8, "Vat Charged", formathead2)

row = 3
for order_id in order_ids:
line_ids = order_id.invoice_line_ids
line_name = line_ids[0].name if line_ids else "--"
amount_without_tax, vat_charge, total_amount = 0, 0, 0
for line_id in line_ids:
if self.tax_id.id in line_id.tax_ids.ids:
if order_id.move_type == 'out_refund':
amount_without_tax += -(line_id.price_subtotal)
total_amount += -(line_id.price_total)
vat_charge += -(line_id.price_total - line_id.price_subtotal)
else:
amount_without_tax += line_id.price_subtotal
total_amount += line_id.price_total
vat_charge += line_id.price_total - line_id.price_subtotal

sheet.write(row, 0, order_id.partner_id.tpin if order_id.partner_id.tpin else '--')
sheet.write(row, 1, order_id.partner_id.name)
sheet.write(row, 2, order_id.name)
sheet.write(row, 3, str(order_id.invoice_date))
sheet.write(row, 4, line_name)
sheet.write(row, 5, amount_without_tax)
sheet.write(row, 6, 0)
sheet.write(row, 7, total_amount)
sheet.write(row, 8, vat_charge)
row += 1


elif self.report_type == 'purchase':
order_ids = self.env['account.move'].search([
('invoice_date', '>=', self.start_date),
('invoice_date', '<=', self.end_date),
('company_id', '=', self.company_id.id),
('move_type', 'in', ['in_invoice', 'in_refund']),
('state', '=', 'posted')], order="id asc")

date = str(self.start_date) + ' - ' + str(self.end_date)
sheet.write(2, 0, 'TPIN of Supplier', formathead2)
sheet.write(2, 1, 'Name Of Supplier', formathead2)
sheet.write(2, 2, 'Invoice Number', formathead2)
sheet.write(2, 3, 'Invoice Date', formathead2)
sheet.write(2, 4, "Description Of Goods & Services", formathead2)
sheet.write(2, 5, "Amount Before Tax", formathead2)
sheet.write(2, 6, "Vat Charged", formathead2)

row = 3
for order_id in order_ids:
line_ids = order_id.invoice_line_ids
line_name = line_ids[0].name if line_ids else "--"
amount_without_tax, vat_charge, total_amount = 0, 0, 0
for line_id in line_ids:
if self.tax_id.id in line_id.tax_ids.ids:
if order_id.move_type == 'in_refund':
amount_without_tax += -(line_id.price_subtotal)
total_amount += -(line_id.price_total)
vat_charge += -(line_id.price_total - line_id.price_subtotal)
else:
amount_without_tax += line_id.price_subtotal
total_amount += line_id.price_total
vat_charge += line_id.price_total - line_id.price_subtotal
sheet.write(row, 0, order_id.partner_id.tpin if order_id.partner_id.tpin else '--')
sheet.write(row, 1, order_id.partner_id.name)
sheet.write(row, 2, order_id.name)
sheet.write(row, 3, str(order_id.invoice_date))
sheet.write(row, 4, line_name)
sheet.write(row, 5, amount_without_tax)
sheet.write(row, 6, vat_charge)
row += 1
fp = BytesIO()
workbook.save(fp)
self.write(
{'state': 'get', 'file_name': base64.encodestring(fp.getvalue()), 'summary_data': file_name})
fp.close()
return {
'type': 'ir.actions.act_window',
'res_model': 'zambia.sale.purchase.report',
'view_mode': 'form',
'view_type': 'form',
'res_id': self.id,
'target': 'new',
}
# return res

@api.onchange('report_type')
def onchange_basket(self):
for rec in self:
rec.tax_id = False
res = {
'domain' : {
'tax_id' : [('type_tax_use', '=', self.report_type)],
},
}
return res

0
Avatar
Opusti
Milin Prajapati

Consider using xlsxwriter module of python

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Prijavi
Related Posts Odgovori Prikazi Aktivnost
Prevent navigation if records are not save
v15
Avatar
Avatar
Avatar
2
okt. 25
3069
Creating user creates duplicated partner_id
v15
Avatar
Avatar
1
sep. 25
3006
Sales order line comment to Purchase order line comment Solved
v15
Avatar
Avatar
3
jul. 25
4304
attribute is not applied when dynamically rendering
v15
Avatar
1
maj 25
2420
Odoo Custome Module Language Creation
v15
Avatar
Avatar
Avatar
Avatar
4
maj 25
3816
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now