1
# -*- encoding: utf-8 -*-
2
############################################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2012 Zikzakmedia S.L. (<http://www.zikzakmedia.com>). All Rights Reserved
8
# This program is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU General Public License as published by
10
# the Free Software Foundation, either version 3 of the License, or
11
# (at your option) any later version.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
18
# You should have received a copy of the GNU General Public License
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
############################################################################################
23
from osv import fields,osv
24
from tools.translate import _
29
class magento_sync_product_wizard(osv.osv_memory):
30
_name = 'magento.sync.product.wizard'
32
def _magento_sale_shop(self, cr, uid, context=None):
33
ids = self.pool.get('sale.shop').search(cr, uid, [('magento_shop', '=', True)], order='id')
34
shops = self.pool.get('sale.shop').read(cr, uid, ids, ['id','name'], context=context)
35
return [(a['id'], a['name']) for a in shops]
38
'magento_sale_shop': fields.selection(_magento_sale_shop, 'Sale Shop', required=True),
39
'result': fields.text('Result', readonly=True),
40
'state':fields.selection([
47
'state': lambda *a: 'first',
50
def sync_product(self, cr, uid, ids, data, context={}):
51
"""Export sync products"""
53
if len(data['active_ids']) == 0:
54
raise osv.except_osv(_('Error!'), _('Select products to export'))
56
form = self.browse(cr, uid, ids[0])
57
shop = form.magento_sale_shop
58
shop = self.pool.get('sale.shop').browse(cr, uid, shop)
59
magento_app = shop.magento_website.magento_app_id
62
for prod in self.pool.get('product.product').browse(cr, uid, data['active_ids']):
63
if prod.magento_exportable:
64
product_ids.append(prod.id)
69
if len(product_ids) > 0:
70
values['result'] = '%s' % (', '.join(str(x) for x in product_ids))
72
values['result'] = _('Not available some Magento Products to export')
74
self.write(cr, uid, ids, values)
78
if shop.magento_default_language:
79
context['lang'] = shop.magento_default_language.code
81
if len(product_ids) > 0:
82
thread1 = threading.Thread(target=self.pool.get('sale.shop').magento_export_products_stepbystep, args=(cr.dbname, uid, magento_app.id, [prod.id], context))
86
magento_sync_product_wizard()