Skip to Content
Odoo Menu
  • Prijavi
  • Try it free
  • Aplikacije
    Finance
    • Knjigovodstvo
    • Obračun
    • Stroški
    • Spreadsheet (BI)
    • Dokumenti
    • Podpisovanje
    Prodaja
    • CRM
    • Prodaja
    • POS Shop
    • POS Restaurant
    • Naročnine
    • Najem
    Spletne strani
    • Website Builder
    • Spletna trgovina
    • Blog
    • Forum
    • Pogovor v živo
    • eUčenje
    Dobavna veriga
    • Zaloga
    • Proizvodnja
    • PLM
    • Nabava
    • Vzdrževanje
    • Kakovost
    Kadri
    • Kadri
    • Kadrovanje
    • Odsotnost
    • Ocenjevanja
    • Priporočila
    • Vozni park
    Marketing
    • Družbeno Trženje
    • Email Marketing
    • SMS Marketing
    • Dogodki
    • Avtomatizacija trženja
    • Ankete
    Storitve
    • Projekt
    • Časovnice
    • Storitve na terenu
    • Služba za pomoč
    • Načrtovanje
    • Termini
    Produktivnost
    • Razprave
    • Odobritve
    • IoT
    • Voip
    • Znanje
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industrije
    Trgovina na drobno
    • Book Store
    • Trgovina z oblačili
    • Trgovina s pohištvom
    • Grocery Store
    • Trgovina s strojno opremo računalnikov
    • Trgovina z igračami
    Food & Hospitality
    • Bar and Pub
    • Restavracija
    • Hitra hrana
    • Guest House
    • Beverage Distributor
    • Hotel
    Nepremičnine
    • Real Estate Agency
    • Arhitekturno podjetje
    • Gradbeništvo
    • Estate Management
    • Vrtnarjenje
    • Združenje lastnikov nepremičnin
    Svetovanje
    • Računovodsko podjetje
    • Odoo Partner
    • Marketinška agencija
    • Law firm
    • Pridobivanje talentov
    • Audit & Certification
    Proizvodnja
    • Tekstil
    • Metal
    • Pohištvo
    • Hrana
    • Brewery
    • Poslovna darila
    Health & Fitness
    • Športni klub
    • Trgovina z očali
    • Fitnes center
    • Wellness Practitioners
    • Lekarna
    • Frizerski salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Sistemi sončne energije
    • Izdelovalec čevljev
    • Čistilne storitve
    • HVAC Services
    Ostali
    • Neprofitna organizacija
    • Agencija za okolje
    • Najem oglasnih panojev
    • Fotografija
    • Najem koles
    • Prodajalec programske opreme
    Browse all Industries
  • Skupnost
    Learn
    • Tutorials
    • Dokumentacija
    • Certifikati
    • Šolanje
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Prenesi
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Dogodki
    • Prevodi
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Sklici kupca
    • Podpora
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Določanje cen
  • Pomoč

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č

ODOO 12 how can we generate Excel report

Naroči se

Get notified when there's activity on this post

This question has been flagged
excel
7 Odgovori
16576 Prikazi
Avatar
Hoang Quan


Hello,

I want to generate excel report on button click, can any one help me out how this can be done. I'm using odoo 12

Thanks 


0
Avatar
Opusti
Avatar
Jignesh Mehta
Best Answer

Hello Hoang Quan,


Please find below code for the excel report of particular product. Add button in Product form view with method name "product_template_excel_report".

PY File :-
==========

from odoo import models, fields, api, _
from odoo.exceptions import UserError
from datetime import date, timedelta, datetime
import datetime
from odoo.tools import DEFAULT_SERVER_DATE_FORMAT
import tempfile
from odoo.tools.misc import xlwt
import io
import base64
import time
from dateutil.relativedelta import relativedelta
from pytz import timezone

class ProductTemplate(models.TransientModel):
    _inherit = 'product.template'

    @api.multi
    def product_template_excel_report(self):
        filename= 'Product Report ' + str(self.name) + '.xls'
        workbook= xlwt.Workbook()

        worksheet= workbook.add_sheet('Product Report')
        font = xlwt.Font()
        font.bold = True
        for_left = xlwt.easyxf("font: bold 1, color black; borders: top double, bottom double, left double, right double; align: horiz left")
        for_left_not_bold = xlwt.easyxf("font: color black; align: horiz left")
        for_center_bold = xlwt.easyxf("font: bold 1, color black; align: horiz center")
        GREEN_TABLE_HEADER = xlwt.easyxf(
            'font: bold 1, name Tahoma, height 250;'
            'align: vertical center, horizontal center, wrap on;'
            'borders: top double, bottom double, left double, right double;'
            )
        style = xlwt.easyxf('font:height 400, bold True, name Arial; align: horiz center, vert center;borders: top medium,right medium,bottom medium,left medium')

        alignment = xlwt.Alignment()  # Create Alignment
        alignment.horz = xlwt.Alignment.HORZ_RIGHT
        style = xlwt.easyxf('align: wrap yes')
        style.num_format_str = '0.00'

         worksheet.row(0).height = 320
        worksheet.col(0).width = 4000
        worksheet.col(1).width = 4000
        borders = xlwt.Borders()
        borders.bottom = xlwt.Borders.MEDIUM
        border_style = xlwt.XFStyle()  # Create Style
        border_style.borders = borders

        product_title = 'Product Report ' + str(self.name)
        worksheet.write_merge(0,1,0,2,product_title,GREEN_TABLE_HEADER)

        row = 2

         worksheet.write(row, 0, 'Product Name' or '',for_left)
        worksheet.write(row, 1, 'Sales Price' or '',for_left)

        row = row + 1
        worksheet.write(row, 0, self.name or '',for_left_not_bold)
        worksheet.write(row, 1, self.list_price or '',for_left_not_bold)

        fp = io.BytesIO()
        workbook.save(fp)
        product_id = self.env['product.excel.extended'].create({'excel_file': base64.encodestring(fp.getvalue()), 'file_name': filename})
        fp.close()

        return{
            'view_mode': 'form',
            'res_id': product_id.id,
            'res_model': 'product.excel.extended',
            'view_type': 'form',
            'type': 'ir.actions.act_window',
             'context': self._context,
             'target': 'new',
         }


class ProductExcelExtended(models.Model):
        _name = 'product.excel.extended'
        _description = "Product Excel Extended"

         excel_file = fields.Binary('Download Report :- ')
         file_name = fields.Char('Excel File', size=64)



XML File :-
===========

<?xml version="1.0" encoding="utf-8"?>
<odoo>

     <!-- Excel Report Download Wizard Form View-->
     <record id="view_product_excel_form_extended" model="ir.ui.view">
     <field name="name">product.excel.extended.form</field>
     <field name="model">product.excel.extended</field>
     <field name="arch" type="xml">
     <form string="Excel Report file">
         <group>
             <field name="excel_file" readonly="1" filename="file_name"/>
             <field name="file_name" invisible="1"/>
         </group>
         <footer>
             <button string="Cancel" class="oe_link oe_highlight" special="cancel"/>
        </footer>
         </form>
         </field>
    </record>

     <!-- Excel Report Download Wizard Action View-->
     <record id="action_product_excel_form" model="ir.actions.act_window">
         <field name="name">Reports Excel</field>
         <field name="view_id" ref="view_product_excel_form_extended"/>
         <field name="view_type">form</field>
         <field name="view_mode">form</field>
         <field name="res_model">product.excel.extended</field>
         <field name="target">new</field>
     </record>

</odoo>

CSV File :-
===========

id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_product_excel_extended,access.product.excel.extended,model_product_excel_extended,,1,1,1,1


Hope it will helps for you.

Thanks,

1
Avatar
Opusti
Hoang Quan
Avtor

thank you. i added your code. But in view file excel not display. I can't download it :( how to download ?

Please help me. Thanks

Nikunj Dhameliya

This URL will download a file if it is generated for the record, you have to set filename and record id of product.excel.extended model

localhost:8069/web/content/?model=product.excel.extended&download=true&field=excel_file&id=Enter Recordid&filename=Enterexcelfilename

Avatar
Niyas Raphy (Walnut Software Solutions)
Best Answer

Hi,

If you are looking how to generate excel report in odoo, see this: How To Create Excel/XLS Report in Odoo

Thanks

1
Avatar
Opusti
Hoang Quan
Avtor

it's not for me. I need get xls for tree view. Can u help me ?

Avatar
Anusha
Best Answer

Hi,

   You can just refer the Odoo Apps store for any example modules. here is one .please check it and make necessary changes   XLSX REPORT SAMPLE     

0
Avatar
Opusti
Avatar
Hoang Quan
Avtor Best Answer

[img]https://i.imgur.com/1YFNIwd.png[/img]


Hello Jignesh Mehta
I added your code. But it's nothing. Help me pls. Thanks

0
Avatar
Opusti
Jignesh Mehta

Have you add access rights from csv file?

Hoang Quan
Avtor

yes i do?. All fields already exist in Database. U can see my image https://i.imgur.com/1YFNIwd.png

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
Cant download excel data from v11 using chrome anymore Solved
excel
Avatar
Avatar
1
nov. 22
3316
how to write an excel file into a field who is a field.Binary()?
excel
Avatar
0
feb. 17
4201
How to create execel report in openerp7
excel
Avatar
0
mar. 15
4751
How to use the module report_xls to generate XLS report in openerp ?
excel
Avatar
0
mar. 15
5981
I have hard time getting know of this platform
excel importing
Avatar
Avatar
Avatar
2
sep. 23
2030
Community
  • Tutorials
  • Dokumentacija
  • Forum
Open Source
  • Prenesi
  • Github
  • Runbot
  • Prevodi
Services
  • Odoo.sh Hosting
  • Podpora
  • Nadgradnja
  • Custom Developments
  • Izobraževanje
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Sredstva blagovne znamke
  • Kontakt
  • Zaposlitve
  • Dogodki
  • Podcast
  • Blog
  • Stranke
  • Pravno • Zasebnost
  • Varnost
الْعَرَبيّة 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