In the first post we have managed to create a functioning module wizard to export data from OpenERP in the form of a csv / excel. For further first we did was add button to import the xml code into a display like this: <? Xml version = "1.0" encoding = "utf-8"?> <openerp> <data> <Record model = "ir. ui.view "id =" view_wizard_eksport_import "> import <field name="name"> Import Object </ field> <field name="model"> eksport.import </ field> <field name="type"> form </ field> <field name="arch" type="xml"> <FORM col="4" string="Eksport Import Wizard" version="7.0"> <group> <field name="type"/> import <field name = "table" /> <field name="name" invisible="True"/> <separator colspan="4"/> <field name="data_file" nolabel="1" colspan="4"/> </ group> <footer> <button name = "eksport_excel" string import = "Export" type = "object" class = "oe_highlight" import attrs = "{'invisible': [('type', '=', import 'imp')] } "/> <button name =" import_excel "string =" Import "type =" object "class =" oe_highlight import "attrs =" {'invisible': [('type', '=', 'ex')]} "/> or <button string="Cancel" class="oe_link" special="cancel" /> </ footer> </ form> </ field> </ record> <record model =" ir.actions.act_window " id = "action_export_import"> <field name="name"> Import Object </ field> <field import name="res_model"> eksport.import </ field> <field name="view_type"> form </ field> <field name = "view_mode"> form </ field> <field name="target"> import new </ field> </ record> <menuitem id = "menu_eksport_import" name = "Import Export" action = "action_export_import" parent = "base . menu_config "Sequence =" 103 "/> </ data> import </ OpenERP>
In the code above we simply add this line: <button name = "import_excel" string = "Import" type = "object" class = "oe_highlight" attrs = "{'invisible': [('type', '=', ' ex ')]} "/>
Then we add to the previous python file with a method import_excel () with the following code: def import_excel (self, cr, uid, ids, context = None): val = self.browse (cr, uid, ids) [0] # We make rules to require selecting a file that is ready to be imported if not val.data_file: raise osv.except_osv (_ ('Error'), _ ("Please select a file to import! ')) # Read the csv file is imported filename import = val . FileData name = base64.b64decode (val.data_file) input = cStringIO.StringIO (FileData) input.seek (0) (fileno, fp_name) = tempfile.mkstemp ('. csv', 'openerp_') file = open (fp_name , "w") file.write (FileData) file.close () # Taking the value of the header of the csv file as the name of the column to be imported crd = csv.reader (open (fp_name, "rb")) head = crd.next ( ) [0]. split (';') # processing a csv file that has become import a collection list and ready to be imported import for the row in crd: res = {} for x in range (0, len (row [0]. split (' ; '))): r = row [0]. split ('; ') [x] # Code to mengconversi string false / true if r.upper be type boolean () ==' FALSE ': r = False elif r . upper () == 'TRUE': r = True else: # Code to mengconversi string of numbers into a float type try: r = float (r) except: pass res [head [x]] = r # OpenERP manufacturing process database records the method create () self.pool.get (str (val.tabel.model)). create (cr, uid, res) {return}
For the explanation may be directly diliat the source code above. For example csv file is ready to be imported can be downloaded here (use titikkoma separator). Maybe this is the end result of the module with the import export wizard. May be useful ...
You are commenting using your Facebook account. (Log Out / Change) import
Search Recent Posts Technical Training-Part 1 - Menginherite View Module Object With Many Advanced Excel Report OpenERP OpenERP Import-Export Wizard Part 2 - Recent Comments on Excel Report Juniar OpenERP OpenERP Juniar on Excel Report on Module Advanced Rival Rival on OpenERP Technical Training-Part Module Advanced ... newbieopenerp on OpenERP Archives December 2013 November 2013 Categories Python OpenERP Blog Stats 1,808 hits
% D bloggers like this:
No comments:
Post a Comment