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
    Restauration & Hôtellerie
    • 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
    • Brasserie
    • Cadeaux d'entreprise
    Santé & Fitness
    • Club de sports
    • Opticien
    • Salle de fitness
    • Praticiens bien-être
    • Pharmacie
    • Salon de coiffure
    Commerce
    • Bricoleur
    • Matériel informatique & 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
    Parcourir toutes les 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
    • Devenir partenaire
    • Services pour partenaires
    • 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

[Odoo12] Store file to folder on HDD

S'inscrire

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

Cette question a été signalée
filestoredocumentsfilefolderodoo12
1 Répondre
7060 Vues
Avatar
Sil

I would like to store all attached file of Project Tasks to the folder on internal disk. The Folderhas the same name as the Project.

Example:

Project name in Odoo = P0001

Folder on disk  = ../HW Projects/P0001

How to save all Attached file from all Tasks in Project P0001 to folder  ../HW Projects/P0001 ?

0
Avatar
Ignorer
Avatar
Sylvain Michel Ratsarafahatra
Meilleure réponse

Hi,

I suggest you to create a method (generate_binary_image) to do this and call it where you want in your code. The following code may help you, adjust it depending your needs.

from odoo import api, models, modules
from odoo.tools.mimetypes import guess_mimetype
import base64
import os
@api.one
def generate_binary_image(self, model, field, record_id):
"""
Allow to generate image from binary field into "files/model"
:param model: model
:param field: field name
:param record_id: ID of selected record
:return:
"""
record_id = self.env[model].sudo().browse(record_id)

# retrieving image binary data
binary_data = record_id.mapped(field)

# decoding image binary data
logo_decoded_data = base64.decodebytes(binary_data[0])

# get MIME type associated with the filename extension
mimetype = guess_mimetype(base64.b64decode(binary_data[0]))

if mimetype == 'image/png':
extension = '.png'
elif mimetype == 'image/jpeg':
extension = '.jpeg'

# get module path
module_path = modules.get_module_path('my_module')
if '\\' in module_path:
src_path = '\\static\\src\\files\\'
src_model_path = "{0}{1}\\".format('\\static\\src\\files\\', model)
else:
src_path = '/static/src/files/'
src_model_path = "{0}{1}/".format('/static/src/files/', model)

# if "model" folder does not exists create it
os.chdir("{0}{1}".format(module_path, src_path))
if not os.path.exists(model):
os.makedirs(model)

# create file if not exists in "model" folder else rewrite it
# the filename must be the record name value
name = record_id.name if record_id.name else '/'
file_path = "{0}{1}".format(module_path + src_model_path + str(name), extension)
if not os.path.exists(str(name)):
current_file = open(file_path, 'w+b')
else:
current_file = open(file_path, 'r+b')
current_file.write(logo_decoded_data)
current_file.close()
return "{0}{1}/{2}{3}".format('/my_module/static/src/files/', model, str(name), extension)

Best regards!

1
Avatar
Ignorer
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é
[12.0] Binary file size upload limit
upload size file odoo12
Avatar
Avatar
1
juil. 21
9373
[odoo12] How to add datetime now to email template attachements? Résolu
email templates file attachements odoo12
Avatar
Avatar
1
juin 22
7883
open a specific folder in file explorer or finder from the project form
file path folder explorer finder
Avatar
Avatar
1
mai 22
4834
is there is anyway to search about documents workspace form attachment view ?
attachment search enterprise documents odoo12
Avatar
0
juin 20
3406
Create a CUSTOM FOLDER in odoo using PYTHON FUNCTION Résolu
security access directory folder odoo12
Avatar
Avatar
1
mars 20
7767
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
  • Devenir 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