1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU Affero General Public License as
9
# published by the Free Software Foundation, either version 3 of the
10
# License, or (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU Affero General Public License for more details.
17
# You should have received a copy of the GNU Affero General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
##############################################################################
22
from osv import osv, fields
23
from tools.translate import _
26
from ftplib import FTP
29
class product_icecat(osv.osv):
30
_name = "product.icecat"
34
class product_icecat_mapline(osv.osv):
35
_name = "product.icecat.mapline"
36
_description = "Icecat Mapline Configuration"
39
'name': fields.char('XML Field', size=32, required=True, help='Insert ID Category from Icecat'),
40
'model_id': fields.many2one('ir.model','OpenERP Model'),
41
'field_id': fields.many2one('ir.model.fields','OpenERP Field', required=True),
42
'icecat_id': fields.many2one('product.icecat','Icecat'),
46
'model_id': lambda self, cr, uid, c: self.pool.get('ir.model').search(cr, uid, [('model', '=', 'product.product')])[0],
49
product_icecat_mapline()
51
class product_icecat(osv.osv):
52
_name = "product.icecat"
53
_description = "Icecat Configuration"
55
def check_ftp(self, cr, uid, ids, context):
60
icecat = self.browse(cr, uid, id)
62
try: ftp = FTP(icecat.ftpip)
64
raise osv.except_osv(_('Error !'), _("IP FTP connection was not successfully!"))
66
try: ftp.login(icecat.ftpusername, icecat.ftppassword)
68
raise osv.except_osv(_('Error !'), _("Username/password FTP connection was not successfully!"))
71
raise osv.except_osv(_('Ok !'), _("FTP connection was successfully!"))
74
'name': fields.char('Name', size=32, required=True),
75
'username': fields.char('User Name', size=32, required=True),
76
'password': fields.char('Password', size=32, required=True),
77
'active': fields.boolean('Active'),
78
'mapline_ids': fields.one2many('product.icecat.mapline','icecat_id','Mapline'),
79
'ftp': fields.boolean('Active'),
80
'ftpip': fields.char('IP', size=256),
81
'ftpdirectory': fields.char('Directory', size=256, help='If not use directory, insert . (point). If use directory, path FTP dir'),
82
'ftpusername': fields.char('Username', size=32),
83
'ftppassword': fields.char('Password', size=32),
84
'ftpurl': fields.char('URL', size=256, help='URL FTP Dir: http://domain/directory/'),
88
'active': lambda *a: 1,
91
def create(self, cr, uid, vals, context={}):
92
if vals.get('active',False):
93
actv_ids = self.search(cr, uid, [('active','=',True)])
95
raise osv.except_osv(_('Error!'), _('They are other icecat configuration with "Active" field checked. Only one configuration is avaible for active field.'))
96
return super(product_icecat, self).create(cr, uid, vals, context)