İçereği Atla
Odoo Menü
  • Portal
  • Ücretsiz deneyin
  • Uygulamalar
    Finans
    • Muhasebe
    • Faturalama
    • Masraf Yönetimi
    • Elektronik Çizelge (BI)
    • Belgeler
    • İmza
    Satış
    • Müşteri İlişkileri Yönetimi (CRM)
    • Satış
    • Satış Noktası Mağaza
    • Satış Noktası Restoran
    • Abonelikler
    • Kiralama
    Web Sitesi
    • Web Sitesi Oluşturucu
    • eTicaret
    • Blog
    • Forum
    • Canlı Sohbet
    • eÖğrenme
    Tedarik Zinciri
    • Envanter
    • Üretim
    • Ürün Yaşam Döngüsü Yönetimi
    • Satın Alma
    • Bakım
    • Kalite
    İnsan Kaynakları
    • Çalışanlar
    • İşe Alım
    • İzin
    • Değerlendirme
    • Referans
    • Filo Yönetimi
    Pazarlama
    • Sosyal Medyada Pazarlama
    • E-posta ile Pazarlama
    • SMS ile Pazarlama
    • Etkinlikler
    • Pazarlama Otomasyonu
    • Anket
    Hizmetler
    • Proje Yönetimi
    • Çalışma Çizelgeleri
    • Saha Hizmeti
    • Yardım Masası
    • Planlama
    • Randevular
    Verimlilik
    • Sohbet
    • Onay
    • Nesnelerin İnterneti
    • VoIP
    • Bilgi Bankası
    • WhatsApp
    Üçüncü taraf uygulamalar Odoo Stüdyo Odoo Bulut Platformu
  • Sektörler
    Perakende satış
    • Kitapçı
    • Giyim Mağazası
    • Mobilya Mağazası
    • Gıda Marketi
    • Hırdavat Dükkanı
    • Oyuncak Dükkanı
    Gıda ve Konaklama
    • Bar ve Pub
    • Restoran
    • Fast Food Restoranı
    • Konuk Evi
    • İçecek Distribütörü
    • Otel
    Gayrimenkul
    • Emlak Acentesi
    • Mimarlık Firması
    • İnşaat
    • Emlak Yönetimi
    • Bahçe Tasarımı
    • Mülk Sahipleri Derneği
    Uzmanlık
    • Muhasebe Firması
    • Odoo Partner
    • Pazarlama Ajansı
    • Hukuk Firması
    • Yetenek Kazanımı
    • Denetim ve Belgelendirme
    Üretim
    • Tekstil
    • Metal
    • Mobilyalar
    • Gıda
    • Bira fabrikası
    • Kurumsal Hediye
    Sağlık ve Spor
    • Spor Kulübü
    • Optik Mağazası
    • Fitness Merkezi
    • Sağlıklı Yaşam Merkezi
    • Eczane
    • Kuaför Salonu
    Ticaret
    • Tamirci
    • BT Donanım & Destek
    • Güneş Enerjisi Sistemleri
    • Ayakkabı İmalatçısı
    • Temizlik Hizmetleri
    • HVAC Hizmetleri
    Diğerleri
    • Kar Amacı Gütmeyen Kuruluş
    • Çevre Ajansı
    • Reklam Panosu Kiralama
    • Fotoğrafçılık
    • Bisiklet Kiralama
    • Yazılım Bayisi
    Tüm Sektörlere Göz Atın
  • Topluluk
    Öğrenim
    • Eğitim Araçları
    • Dokümantasyon
    • Sertifikasyonlar
    • Eğitim Etkinlikleri
    • Blog
    • Podcast
    Eğitim ve Gelişim
    • Eğitim Programı
    • Scale Up! İşletme Oyunu
    • Odoo'yu Ziyaret Edin
    Yazılım
    • İndirin
    • Sürümleri Kıyaslayın
    • Sürümler
    İş Birliği
    • Github
    • Forum
    • Etkinlikler
    • Çeviriler
    • Partner Olun
    • Partnerler için Hizmetler
    • Muhasebe Firmanızı Kaydettirin
    Hizmetler
    • Partner Bulun
    • Muhasebeci Bulun
    • Bir danışmanla görüşün
    • Kurulum Hizmetleri
    • Müşteri Referansları
    • Destek
    • Sürüm Yükseltme
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Demo randevusu alın
  • Fiyatlandırma
  • Yardım

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

  • Müşteri İlişkileri Yönetimi
  • e-Commerce
  • Muhasebe
  • Envanter
  • PoS
  • Proje Yönetimi
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiketler (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiketler (View all)
odoo accounting v14 pos v15
About this forum
Yardım

File downloading as .doc instead of .xls

Abone Ol

Get notified when there's activity on this post

Bu soru işaretlendi
xls_reportsv15
2504 Görünümler
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
Vazgeç
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!

Üye Ol
İlgili Gönderiler Cevaplar Görünümler Aktivite
Prevent navigation if records are not save
v15
Avatar
Avatar
Avatar
2
Eki 25
3103
Creating user creates duplicated partner_id
v15
Avatar
Avatar
1
Eyl 25
3030
Sales order line comment to Purchase order line comment Çözüldü
v15
Avatar
Avatar
3
Tem 25
4333
attribute is not applied when dynamically rendering
v15
Avatar
1
May 25
2450
Odoo Custome Module Language Creation
v15
Avatar
Avatar
Avatar
Avatar
4
May 25
3862
Topluluk
  • Eğitim Araçları
  • Dokümantasyon
  • Forum
Açık Kaynak
  • İndirin
  • Github
  • Runbot
  • Çeviriler
Hizmetler
  • Odoo.sh Hosting
  • Destek
  • Sürüm Yükseltme
  • Özel Geliştirmeler
  • Eğitim
  • Muhasebeci Bulun
  • Partner Bulun
  • Partner Olun
Hakkında
  • Şirketimiz
  • Pazarlama Gereçleri
  • İletişim
  • Kariyer
  • Etkinlikler
  • Podcast
  • Blog
  • Müşteriler
  • Hukuki • Gizlilik
  • Güvenlik
الْعَرَبيّة 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, müşteri ilişkileri yönetimi, eTicaret, muhasebe, envanter, satış noktası, proje yönetimi gibi şirketinizin tüm ihtiyaçlarını karşılayan bir açık kaynak işletme uygulamaları paketidir.

Odoo’nun eşsiz değer önermesi, aynı anda hem kullanımının çok kolay olup hem de tamamen entegre olmasıdır.

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