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

How to create .DAT file?

Zaprenumeruj

Otrzymaj powiadomienie o aktywności w tym poście

To pytanie dostało ostrzeżenie
1 Odpowiedz
12999 Widoki
Awatar
Anirudh Lou

Hi every one. My question is, somehow, related to my previous question. How can i create .DAT, .csv, .ods, or even .xls , so that user can have a softcopy of the files. For example, user want to have the copy of list of all pupils in a .DAT then he can download it. Any one can help?

----------------------------

EDIT

Thank you sir for your answer, actually i did what you have told me, but i got an error, or perhaps my code is far way from reality. I made a class named 'file.holder' just like this one:


class file_holder(osv.osv):

_name = 'file.holder'

_columns = { 'name' : fields.char('File name'),
                       'file_data' : fields.binary('File Name',filters='*.DAT',)
                     }

def get_file(self, cr, uid, context=None):

       file_path = addons.get_module_resource('mp_seven', 'files', 'studentlist.DAT')

       fo = {} fo = open(file_path,"wb")

      active_id = self.pool.get('student.student').search(cr,uid,[])

      for list in self.browse(cr,uid,active_id,context=context):

            fo.write(list.id+","+list.name) self.create(cr,uid,{ 'name' : '', 'file_data' : file_path })

      return fo.read().encode('base64')

file_holder()

 

where addons is a folder in openerpserver-7, mp_seven is my project name, files is subfolder in my project and where studentlist.DAT resides. Whenever this method is bieng called in other class the browser/terminal says :

             file_path = addons.get_module_resource('mp_seven', 'files', 'studentlist.DAT')

NameError: global name 'addons' is not defined

 

 

 

------------------------------------------------------------------------

RE EDIT:

 

Sir, this is how i implement your pseudo code, but my problem now is that my return view doesn't show anything (on my file.holder class):

 

def file_writer(self, cr, uid, ids, context=None):

        virtual_file = StringIO.StringIO()

        student_object = self.pool.get('student.student')

        active_id = student_object.search(cr,uid,[])

        for obj_list in student_object.browse(cr,uid,active_id,context=context): 

                  virtual_file.write(str(obj_list.last_name)+","+str(obj_list.first_name)+","+str(obj_list.middle_name))

                  self.create(cr,uid,{ 'name' : 'studentList.DAT', 'file_data' : virtual_file })

        return { 'type': 'ir.actions.act_window',

                      'res_model': 'file.holder',

                      'view_mode': 'form',

                     'view_type': 'form',

                     'views': [(False, 'form')],

                     'target': 'new', }

 

this is how i called it in my "student.student" class

 

def call_file_writer(self,cr,uid,ids,context=None):

return self.pool.get('file.holder').file_writer(cr,uid,ids,context=context)

 

 

def loadstudent(self,cr,uid,ids,context=None):

.....

return self.call_file_writer(cr, uid, ids, context=context)

 

When the view is rendered, it shows only the two fields without it's object.

 

 

2
Awatar
Odrzuć
Awatar
Ludo - 21South
Najlepsza odpowiedź

In my previous answer I explained to you how to create files in python:

https://www.odoo.com/forum/help-1/question/how-to-create-a-file-and-save-data-on-it-66983

In addition to this, you can also create a binary field in Odoo. If you create this field, you will allow everyone to attach files to the record the field is on. Make the file readonly for your users in order for them not to upload anything new. When creating the record for example (or when pressing save) create one of the previously mentioned virtual files and use its base64 value as value for this field. This will allow you to generate files and make them available for download by your users.

------------------

EDIT

I believe you did not quite understand what I meant. Something in the likes of the following should help you out:

  • import stringio (default python lib)
  • Then create an instance of StringIO (somefile = StringIO())
  • No need for path and such. Just edit as though it was a regular file. (somefile.write("All my contents go here"))
  • When you have that file in memory, write its contents directly to the field in your OpenERP instance. ( self.pool.get(file.holder').create(cr, uid, {'name': 'My super file', 'my_binary_field': somefile)}
  • Mind you, this is PSEUDO CODE, not real interpretation. 
2
Awatar
Odrzuć
Anirudh Lou
Autor

Thank you sir for your answer, actually i did what you have told me, but i got an error, or perhaps my code is far way from reality. I made a class named 'file.holder' just like this one: class file_holder(osv.osv): _name = 'file.holder' _columns = { 'name' : fields.char('File name'), 'file_data' : fields.binary('File Name',filters='*.DAT',) } def get_file(self, cr, uid, context=None): file_path = addons.get_module_resource('mp_seven', 'files', 'studentlist.DAT') fo = {} fo = open(file_path,"wb") active_id = self.pool.get('student.student').search(cr,uid,[]) for list in self.browse(cr,uid,active_id,context=context): fo.write(list.id+","+list.name) self.create(cr,uid,{ 'name' : '', 'file_data' : file_path }) return fo.read().encode('base64') file_holder() where addons is a folder in openerpserver-7, mp_seven is my project name, files is subfolder in my project and where studentlist.DAT resides. Whenever this method is bieng called in other class the browser/terminal says : file_path = addons.get_module_resource('mp_seven', 'files', 'studentlist.DAT') NameError: global name 'addons' is not defined

Ludo - 21South

Hi anirudh. Please update your initial question with the code above. Currently it is unreadable for us.

Anirudh Lou
Autor

sir i have modify the above comment here is the link for the above: https://www.odoo.com/forum/help-1/question/create-files-67330

Ludo - 21South

You Created a new question, which was not the purpose of my answer. I deleted the question and edited this current question. I will update my answer.

Anirudh Lou
Autor

Thank you very much sir for your help, it really works. I have seen the file being created in my database. Since you have helped me, can i ask bonus help? How can i make the file downloadable? I mean, The button w/c is responsible for the file creation is named 'Create .DAT file'. Now at the same time, i want that the download pop up message appears automatically. Is it possible to do it?

Ludo - 21South

You are very welcome. I think your best bet is to provide a certain tag in the XML view. I believe it is class="oe_link". That should create a link out of the file, like you would with the tag in regular HTML.

Anirudh Lou
Autor

Do you mean sir, i'll put class="oe_link" on my button? just like this one: . I did this but nothing popped up, but it persist on the database.

Ludo - 21South

Hehe, no I meant on the binary field in the XML. That way instead of showing the buttons, it will just create a link out of the file. I do not know of a way to present a dialog to the user right after creating the file, so this would be my alternative.

Anirudh Lou
Autor

Hmp? Do you mean sir, i'll put class="oe_link" on file_data in xml view? Sir, i have no view for my file.holder class. Actually, my project would behave like this, In my student list view i created 'Create .DAT file' button that calls file_writer method in my 'file.holder' class. My aim is that when user clicks that butoon, the system will show/allow the user to download the .DAT file. Just like how Print sidebar behave.

Anirudh Lou
Autor

I am not so sure, if it involves javascript manipulation.

Ludo - 21South

I'm sorry but I can't help you with that. I see now that my recommendation does not work in your case. Javascript is not my strong point here. The only thing I can image to try is using the button to open a view itself for the 'file.holder' class. This can be a temporary view and pre filled, but I'm not sure that fits your business needs. Good luck!

Anirudh Lou
Autor

Nope sir, you really help me and it is a big addition on my knowledge in openerp and in python and I must thank you for that. I feel that i am indebited to you. :) Although, i was not able to make it now but hopefully someday i'm gonna make it. Thanks a lot sir.

Ludo - 21South

You are very welcome. If you manage to get the answer to your question, don't hesitate to update the question and show the others on the board what it was.

Anirudh Lou
Autor

Sir, this is how i implement your pseudo code, but my problem now is that my return view doesn't show anything: def file_writer(self, cr, uid, ids, context=None): virtual_file = StringIO.StringIO() student_object = self.pool.get('student.student') active_id = student_object.search(cr,uid,[]) for obj_list in student_object.browse(cr,uid,active_id,context=context): virtual_file.write(str(obj_list.last_name)+","+str(obj_list.first_name)+","+str(obj_list.middle_name)) self.create(cr,uid,{ 'name' : 'studentList.DAT', 'file_data' : virtual_file }) return { 'type': 'ir.actions.act_window', 'res_model': 'file.holder', 'view_mode': 'form', 'view_type': 'form', 'views': [(False, 'form')], 'target': 'new', } this is how i called it in my "student.student" class def call_file_writer(self,cr,uid,ids,context=None): return self.pool.get('file.holder').file_writer(cr,uid,ids,context=context) def loadstudent(self,cr,uid,ids,context=None): ..... return self.call_file_writer(cr, uid, ids, context=context) When the view is rendered, it shows only the two fields without it's object.

Ludo - 21South

I think it is best to create a new question for this. Post the code and we will see whoever can pick it up best.

Anirudh Lou
Autor

I have edited my post question sir.

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ę
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