You could also implement this as a wizard as follows. This uses the 
product_image extension. Sorry the code's a bit rough, but I suppose you only 
use it once.



import wizard
from osv import osv
import pooler
import base64


def _print_label(self, cr, uid, data, context):

   def open_file (name):
# replace this code with how you get your own filename
      root = '/home/sglass/fh_files/pictures/'
      fname = 'web/sm-%s.jpg' % name
      fd = None
      try:
         fd = open (root + fname, "rb")
      except:
         fname = 'nov07/web/sm-%s.jpg' % name
         try:
            fd = open (root + 
fname, "rb")
         except:
            pass
         pass
      return fd

  
 product_table=pooler.get_pool(cr.dbname).get('product.product')
  
 product_ttable=pooler.get_pool(cr.dbname).get('product.template')
   products = product_table.browse(cr, uid, 
data['ids'])
   for product in products:
      code = _conv_str (product['code'])
      str = product ['picture']
      fd = open_file (product ['variants'])
      str = None
      if fd:
         str = fd.read ()
         fd.close ()
      print "%d %s %d" % (product.id, code, str and len 
(str) or 0)
      product_table.write(cr, uid, 
[product.id], {'default_code' : code})
      if str:
         basestr = 
base64.encodestring(str)
         product_table.write(cr, uid, 
[product.id], {'picture' : basestr})
      # should call the script here
   return {}

class wizard_import_fabric(wizard.interface):
   states = {   'init': {     
 'actions': [_print_label],
                 
          'result': {  
 'type': 'state',
                 
                'state' 
: 'end'
                 
             }
                 
 }
         }

wizard_import_fabric('product.fabric.import')

[/code]

------------------------
--
Simon Glass
Christchurch
New Zealand




_______________________________________________
Tinyerp-users mailing list
http://tiny.be/mailman/listinfo/tinyerp-users

Reply via email to