Se rendre au contenu
Odoo Menu
  • Se connecter
  • Essai gratuit
  • Applications
    Finance
    • Comptabilité
    • Facturation
    • Notes de frais
    • Feuilles de calcul (BI)
    • Documents
    • Signature
    Ventes
    • CRM
    • Ventes
    • PdV Boutique
    • PdV Restaurant
    • Abonnements
    • Location
    Sites web
    • Site Web
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Chaîne d'approvisionnement
    • Inventaire
    • Fabrication
    • PLM
    • Achats
    • Maintenance
    • Qualité
    Ressources Humaines
    • Employés
    • Recrutement
    • Congés
    • Évaluations
    • Recommandations
    • Parc automobile
    Marketing
    • Marketing Social
    • E-mail Marketing
    • SMS Marketing
    • Événements
    • Marketing Automation
    • Sondages
    Services
    • Projet
    • Feuilles de temps
    • Services sur Site
    • Assistance
    • Planification
    • Rendez-vous
    Productivité
    • Discussion
    • Validations
    • Internet des Objets
    • VoIP
    • Connaissances
    • WhatsApp
    Applications tierces Odoo Studio Plateforme Cloud d'Odoo
  • Industries
    Commerce de détail
    • Librairie
    • Magasin de vêtements
    • Magasin de meubles
    • Épicerie
    • Quincaillerie
    • Magasin de jouets
    Food & Hospitality
    • Bar et Pub
    • Restaurant
    • Fast-food
    • Maison d’hôtes
    • Distributeur de boissons
    • Hôtel
    Immobilier
    • Agence immobilière
    • Cabinet d'architecture
    • Construction
    • Gestion immobilière
    • Jardinage
    • Association de copropriétaires
    Consultance
    • Cabinet d'expertise comptable
    • Partenaire Odoo
    • Agence Marketing
    • Cabinet d'avocats
    • Aquisition de talents
    • Audit & Certification
    Fabrication
    • Textile
    • Métal
    • Meubles
    • Alimentation
    • Brewery
    • Cadeaux d'entreprise
    Santé & Fitness
    • Club de sports
    • Opticien
    • Salle de fitness
    • Praticiens bien-être
    • Pharmacie
    • Salon de coiffure
    Trades
    • Bricoleur
    • Matériel informatique et support
    • Systèmes photovoltaïques
    • Cordonnier
    • Services de nettoyage
    • Services CVC
    Autres
    • Organisation à but non lucratif
    • Agence environnementale
    • Location de panneaux d'affichage
    • Photographie
    • Leasing de vélos
    • Revendeur de logiciel
    Browse all Industries
  • Communauté
    Apprenez
    • Tutoriels
    • Documentation
    • Certifications
    • Formation
    • Blog
    • Podcast
    Renforcer l'éducation
    • Programme éducatif
    • Business Game Scale-Up!
    • Rendez-nous visite
    Obtenir le logiciel
    • Téléchargement
    • Comparez les éditions
    • Versions
    Collaborer
    • Github
    • Forum
    • Événements
    • Traductions
    • Devenez partenaire
    • Services for Partners
    • Enregistrer votre cabinet comptable
    Nos Services
    • Trouver un partenaire
    • Trouver un comptable
    • Rencontrer un conseiller
    • Services de mise en œuvre
    • Références clients
    • Assistance
    • Mises à niveau
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obtenir une démonstration
  • Tarification
  • Aide

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

  • CRM
  • e-Commerce
  • Comptabilité
  • Inventaire
  • PoS
  • Projet
  • MRP
All apps
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Aide

ODOO 12 how can we generate Excel report

S'inscrire

Recevez une notification lorsqu'il y a de l'activité sur ce poste

Cette question a été signalée
excel
7 Réponses
16559 Vues
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
Ignorer
Avatar
Jignesh Mehta
Meilleure réponse

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
Ignorer
Hoang Quan
Auteur

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)
Meilleure réponse

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
Ignorer
Hoang Quan
Auteur

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

Avatar
Anusha
Meilleure réponse

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
Ignorer
Avatar
Hoang Quan
Auteur Meilleure réponse

[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
Ignorer
Jignesh Mehta

Have you add access rights from csv file?

Hoang Quan
Auteur

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

Vous appréciez la discussion ? Ne vous contentez pas de lire, rejoignez-nous !

Créez un compte dès aujourd'hui pour profiter de fonctionnalités exclusives et échanger avec notre formidable communauté !

S'inscrire
Publications associées Réponses Vues Activité
Cant download excel data from v11 using chrome anymore Résolu
excel
Avatar
Avatar
1
nov. 22
3309
how to write an excel file into a field who is a field.Binary()?
excel
Avatar
0
févr. 17
4188
How to create execel report in openerp7
excel
Avatar
0
mars 15
4740
How to use the module report_xls to generate XLS report in openerp ?
excel
Avatar
0
mars 15
5963
I have hard time getting know of this platform
excel importing
Avatar
Avatar
Avatar
2
sept. 23
2028
Communauté
  • Tutoriels
  • Documentation
  • Forum
Open Source
  • Téléchargement
  • Github
  • Runbot
  • Traductions
Services
  • Hébergement Odoo.sh
  • Assistance
  • Migration
  • Développements personnalisés
  • Éducation
  • Trouver un comptable
  • Trouver un partenaire
  • Devenez partenaire
À propos
  • Notre société
  • Actifs de la marque
  • Contactez-nous
  • Emplois
  • Événements
  • Podcast
  • Blog
  • Clients
  • Informations légales • Confidentialité
  • Sécurité.
الْعَرَبيّة 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 est une suite d'applications open source couvrant tous les besoins de votre entreprise : CRM, eCommerce, Comptabilité, Inventaire, Point de Vente, Gestion de Projet, etc.

Le positionnement unique d'Odoo est d'être à la fois très facile à utiliser et totalement intégré.

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