Skip to Content
Odoo Menu
  • Zaloguj się
  • Wypróbuj za darmo
  • Aplikacje
    Finanse
    • Księgowość
    • Fakturowanie
    • Wydatki
    • Arkusz kalkulacyjny (BI)
    • Dokumenty
    • Podpisy
    Sprzedaż
    • CRM
    • Sprzedaż
    • PoS Sklep
    • PoS Restauracja
    • Subskrypcje
    • Wypożyczalnia
    Strony Internetowe
    • Kreator Stron Internetowych
    • eCommerce
    • Blog
    • Forum
    • Czat na Żywo
    • eLearning
    Łańcuch dostaw
    • Magazyn
    • Produkcja
    • PLM
    • Zakupy
    • Konserwacja
    • Jakość
    Zasoby Ludzkie
    • Pracownicy
    • Rekrutacja
    • Urlopy
    • Ocena pracy
    • Polecenia Pracownicze
    • Flota
    Marketing
    • Marketing Społecznościowy
    • E-mail Marketing
    • SMS Marketing
    • Wydarzenia
    • Automatyzacja Marketingu
    • Ankiety
    Usługi
    • Projekt
    • Ewidencja czasu pracy
    • Usługi Terenowe
    • Helpdesk
    • Planowanie
    • Spotkania
    Produktywność
    • Dyskusje
    • Zatwierdzenia
    • IoT
    • VoIP
    • Baza wiedzy
    • WhatsApp
    Aplikacje trzecich stron Studio Odoo Odoo Cloud Platform
  • Branże
    Sprzedaż detaliczna
    • Księgarnia
    • Sklep odzieżowy
    • Sklep meblowy
    • Sklep spożywczy
    • Sklep z narzędziami
    • Sklep z zabawkami
    Żywienie i hotelarstwo
    • Bar i Pub
    • Restauracja
    • Fast Food
    • Pensjonat
    • Dystrybutor napojów
    • Hotel
    Agencja nieruchomości
    • Agencja nieruchomości
    • Biuro architektoniczne
    • Budowa
    • Zarządzanie nieruchomościami
    • Ogrodnictwo
    • Stowarzyszenie właścicieli nieruchomości
    Doradztwo
    • Biuro księgowe
    • Partner Odoo
    • Agencja marketingowa
    • Kancelaria prawna
    • Agencja rekrutacyjna
    • Audyt i certyfikacja
    Produkcja
    • Tekstylia
    • Metal
    • Meble
    • Jedzenie
    • Browar
    • Prezenty firmowe
    Zdrowie & Fitness
    • Klub sportowy
    • Salon optyczny
    • Centrum fitness
    • Praktycy Wellness
    • Apteka
    • Salon fryzjerski
    Transakcje
    • Złota rączka
    • Wsparcie Sprzętu IT
    • Systemy energii słonecznej
    • Szewc
    • Firma sprzątająca
    • Usługi HVAC
    Inne
    • Organizacja non-profit
    • Agencja Środowiskowa
    • Wynajem billboardów
    • Fotografia
    • Leasing rowerów
    • Sprzedawca oprogramowania
    Przeglądaj wszystkie branże
  • Community
    Ucz się
    • Samouczki
    • Dokumentacja
    • Certyfikacje
    • Szkolenie
    • Blog
    • Podcast
    Pomóż w nauce innym
    • Program Edukacyjny
    • Scale Up! Gra biznesowa
    • Odwiedź Odoo
    Skorzystaj z oprogramowania
    • Pobierz
    • Porównaj edycje
    • Wydania
    Współpracuj
    • Github
    • Forum
    • Wydarzenia
    • Tłumaczenia
    • Zostań partnerem
    • Usługi dla partnerów
    • Zarejestruj swoją firmę rachunkową
    Skorzystaj z usług
    • Znajdź partnera
    • Znajdź księgowego
    • Spotkaj się z doradcą
    • Usługi wdrożenia
    • Opinie klientów
    • Wsparcie
    • Aktualizacje
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Zaplanuj demo
  • Cennik
  • Pomoc

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

  • CRM
  • e-Commerce
  • Księgowość
  • Zapasy
  • PoS
  • Projekt
  • MRP
All apps
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Pomoc

File downloading as .doc instead of .xls

Zaprenumeruj

Otrzymaj powiadomienie o aktywności w tym poście

To pytanie dostało ostrzeżenie
xls_reportsv15
2516 Widoki
Awatar
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
Awatar
Odrzuć
Milin Prajapati

Consider using xlsxwriter module of python

Podoba Ci się ta dyskusja? Dołącz do niej!

Stwórz konto dzisiaj, aby cieszyć się ekskluzywnymi funkcjami i wchodzić w interakcje z naszą wspaniałą społecznością!

Zarejestruj się
Powiązane posty Odpowiedzi Widoki Czynność
Prevent navigation if records are not save
v15
Awatar
Awatar
Awatar
2
paź 25
3133
Creating user creates duplicated partner_id
v15
Awatar
Awatar
1
wrz 25
3048
Sales order line comment to Purchase order line comment Rozwiązane
v15
Awatar
Awatar
3
lip 25
4357
attribute is not applied when dynamically rendering
v15
Awatar
1
maj 25
2471
Odoo Custome Module Language Creation
v15
Awatar
Awatar
Awatar
Awatar
4
maj 25
3882
Społeczność
  • Samouczki
  • Dokumentacja
  • Forum
Open Source
  • Pobierz
  • Github
  • Runbot
  • Tłumaczenia
Usługi
  • Hosting Odoo.sh
  • Wsparcie
  • Aktualizacja
  • Indywidualne rozwiązania
  • Edukacja
  • Znajdź księgowego
  • Znajdź partnera
  • Zostań partnerem
O nas
  • Nasza firma
  • Zasoby marki
  • Skontaktuj się z nami
  • Oferty pracy
  • Wydarzenia
  • Podcast
  • Blog
  • Klienci
  • Informacje prawne • Prywatność
  • Bezpieczeństwo Odoo
الْعَرَبيّة 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 to pakiet aplikacji biznesowych typu open source, które zaspokoją wszystkie potrzeby Twojej firmy: CRM, eCommerce, księgowość, inwentaryzacja, punkt sprzedaży, zarządzanie projektami itp.

Unikalną wartością Odoo jest to, że jest jednocześnie bardzo łatwe w użyciu i w pełni zintegrowane.

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