~openerp-commiter/openobject-addons/trunk-extra-addons

« back to all changes in this revision

Viewing changes to product_icecat/product_icecat.py

  • Committer: Cubic ERP
  • Date: 2012-11-28 00:54:54 UTC
  • mfrom: (5823.1.19 openobject-addons)
  • Revision ID: info@cubicerp.com-20121128005454-bbtsmufafj4hwady
[UPG]

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*-
2
 
##############################################################################
3
 
#
4
 
#    OpenERP, Open Source Management Solution
5
 
#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6
 
#
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.
11
 
#
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.
16
 
#
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/>.
19
 
#
20
 
##############################################################################
21
 
 
22
 
from osv import osv, fields
23
 
from tools.translate import _
24
 
import netsvc
25
 
 
26
 
from ftplib import FTP
27
 
import os
28
 
 
29
 
class product_icecat(osv.osv):
30
 
    _name = "product.icecat"
31
 
 
32
 
product_icecat()
33
 
 
34
 
class product_icecat_mapline(osv.osv):
35
 
    _name = "product.icecat.mapline"
36
 
    _description = "Icecat Mapline Configuration"
37
 
 
38
 
    _columns = {
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'),
43
 
    }
44
 
 
45
 
    _defaults = {
46
 
        'model_id': lambda self, cr, uid, c: self.pool.get('ir.model').search(cr, uid, [('model', '=', 'product.product')])[0],
47
 
    }
48
 
 
49
 
product_icecat_mapline()
50
 
 
51
 
class product_icecat(osv.osv):
52
 
    _name = "product.icecat"
53
 
    _description = "Icecat Configuration"
54
 
 
55
 
    def check_ftp(self, cr, uid, ids, context):
56
 
        if context is None:
57
 
            context = {}
58
 
 
59
 
        for id in ids:
60
 
            icecat = self.browse(cr, uid, id)
61
 
 
62
 
            try: ftp = FTP(icecat.ftpip)
63
 
            except:
64
 
                raise osv.except_osv(_('Error !'), _("IP FTP connection was not successfully!"))
65
 
 
66
 
            try: ftp.login(icecat.ftpusername, icecat.ftppassword)
67
 
            except:
68
 
                raise osv.except_osv(_('Error !'), _("Username/password FTP connection was not successfully!"))
69
 
 
70
 
            ftp.quit()
71
 
            raise osv.except_osv(_('Ok !'), _("FTP connection was successfully!"))
72
 
 
73
 
    _columns = {
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/'),
85
 
    }
86
 
 
87
 
    _defaults = {
88
 
        'active': lambda *a: 1,
89
 
    }
90
 
 
91
 
    def create(self, cr, uid, vals, context={}):
92
 
        if vals.get('active',False):
93
 
            actv_ids =  self.search(cr, uid, [('active','=',True)])
94
 
            if len(actv_ids):
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)
97
 
 
98
 
product_icecat()
99
 
 
100