1
##############################################################################
3
# Copyright (c) 2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
5
# WARNING: This program as such is intended to be used by professional
6
# programmers who take the whole responsability of assessing all potential
7
# consequences resulting from its eventual inadequacies and bugs
8
# End users who are looking for a ready-to-use solution with commercial
9
# garantees and support are strongly adviced to contract a Free Software
12
# This program is Free Software; you can redistribute it and/or
13
# modify it under the terms of the GNU General Public License
14
# as published by the Free Software Foundation; either version 2
15
# of the License, or (at your option) any later version.
17
# This program is distributed in the hope that it will be useful,
18
# but WITHOUT ANY WARRANTY; without even the implied warranty of
19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
# GNU General Public License for more details.
22
# You should have received a copy of the GNU General Public License
23
# along with this program; if not, write to the Free Software
24
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
##############################################################################
39
_export_done_form = '''<?xml version="1.0"?>
40
<form string="Initial import">
41
<separator string="Products exported" colspan="4" />
42
<field name="prod_new"/>
44
<field name="prod_update"/>
47
_export_done_fields = {
48
'prod_new': {'string':'New products', 'type':'float', 'readonly': True},
49
'prod_update': {'string':'Updated products', 'type':'float', 'readonly': True},
52
def _do_export(self, cr, uid, data, context):
53
self.pool = pooler.get_pool(cr.dbname)
54
ids = self.pool.get('esale_joomla.web').search(cr, uid, [])
55
for website in self.pool.get('esale_joomla.web').browse(cr, uid, ids):
56
pricelist = website.shop_id.pricelist_id.id
58
raise wizard.except_wizard('UserError', 'You must define a pricelist in your shop !')
59
server = xmlrpclib.ServerProxy("%s/tinyerp-synchro.php" % website.url)
60
print 'SERVER', "%s/tinyerp-synchro.php" % website.url
65
for categ in website.category_ids:
66
if not categ.category_id:
67
print 'Skipping Category', categ.name, categ.id
69
cat_ids = [categ.category_id.id]
70
if categ.include_childs:
73
# Use cat_ids and compute for childs
75
prod_ids = self.pool.get('product.product').search(cr, uid, [('categ_id','=',categ.category_id.id)])
76
for product in self.pool.get('product.product').browse(cr, uid, prod_ids):
80
esale_joomla_id2 = self.pool.get('esale_joomla.product').search(cr, uid, [('web_id','=',website.id),('product_id','=',product.id)])
83
esale_joomla_id = self.pool.get('esale_joomla.product').browse(cr, uid, esale_joomla_id2[0]).esale_joomla_id
86
print [pricelist], product.id, 1, 'list'
88
'esale_joomla_id' : esale_joomla_id or 0,
89
'quantity' : self.pool.get('product.product')._product_virtual_available(cr, uid, [product.id], '', False, {'shop':website.shop_id.id})[product.id],
90
'model' : product.code or '',
91
'price' : 10.0, #self.pool.get('product.pricelist').price_get(cr, uid, [pricelist], product.id, 1, 'list')[pricelist],
92
'weight' : float(product.weight),
93
'tax_class_id' : tax_class_id,
94
'category_id' : category_id,
97
attach_ids = self.pool.get('ir.attachment').search(cr, uid, [('res_model','=','product.product'), ('res_id', '=',product.id)])
98
data = self.pool.get('ir.attachment').read(cr, uid, attach_ids)
100
webproduct['haspic'] = 1
101
webproduct['picture'] = data[0]['datas']
102
webproduct['fname'] = data[0]['datas_fname']
104
webproduct['haspic'] =0
107
products_pool=pooler.get_pool(cr.dbname).get('product.product')
108
for lang in website.language_ids:
109
if lang.language_id and lang.language_id.translatable:
110
langs[str(lang.esale_joomla_id)] = {
111
'name': products_pool.read(cr, uid, [osc_product.product_id.id], ['name'], {'lang': lang.language_id.code})[0]['name'] or '',
112
'description': products_pool.read(cr, uid, [osc_product.product_id.id], ['description_sale'], {'lang': lang.language_id.code})[0]['description_sale'] or ''
115
webproduct['langs'] = langs
116
webproduct['name'] = str(product.name or '')
117
webproduct['description'] = str(product.description_sale or '')
121
osc_id=server.set_product(webproduct)
124
if osc_id!=webproduct['esale_joomla_id']:
126
self.pool.get('esale_joomla.product').write(cr, uid, [esale_joomla_id2[0]], {'esale_joomla_id': osc_id})
127
print 'Changing', webproduct['esale_joomla_id'], 'to', osc_id
130
self.pool.get('esale_joomla.product').create(cr, uid, {
131
'product_id': product.id,
132
'web_id': website.id,
133
'esale_joomla_id': osc_id,
139
return {'prod_new':prod_new, 'prod_update':prod_update}
141
class wiz_esale_joomla_products(wizard.interface):
144
'actions': [_do_export],
145
'result': {'type': 'form', 'arch': _export_done_form, 'fields': _export_done_fields, 'state': [('end', 'End')] }
148
wiz_esale_joomla_products('esale_joomla.products');