1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2004-2009 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
##############################################################################
24
from osv import osv, fields
25
from osv.orm import except_orm
30
class document_configuration_wizard(osv.osv_memory):
31
_name='document.configuration.wizard'
32
_rec_name = 'Auto Directory configuration'
34
'host': fields.char('Server Address', size=64, help="Put here the server address or IP. " \
35
"Keep localhost if you don't know what to write.", required=True)
38
def detect_ip_addr(self, cr, uid, context=None):
39
def _detect_ip_addr(self, cr, uid, context=None):
40
from array import array
42
from struct import pack, unpack
49
if not fcntl: # not UNIX:
50
host = socket.gethostname()
51
ip_addr = socket.gethostbyname(host)
55
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
56
names = array('B', '\0' * nbytes)
57
outbytes = unpack('iL', fcntl.ioctl( s.fileno(), 0x8912, pack('iL', nbytes, names.buffer_info()[0])))[0]
58
namestr = names.tostring()
59
ifaces = [namestr[i:i+32].split('\0', 1)[0] for i in range(0, outbytes, 32)]
61
for ifname in [iface for iface in ifaces if iface != 'lo']:
62
ip_addr = socket.inet_ntoa(fcntl.ioctl(s.fileno(), 0x8915, pack('256s', ifname[:15]))[20:24])
67
ip_addr = _detect_ip_addr(self, cr, uid, context)
73
'host': detect_ip_addr,
76
def action_cancel(self,cr,uid,ids,conect=None):
80
'res_model': 'ir.actions.configuration.wizard',
81
'type': 'ir.actions.act_window',
85
def action_config(self, cr, uid, ids, context=None):
86
conf = self.browse(cr, uid, ids[0], context)
87
obj=self.pool.get('document.directory')
88
objid=self.pool.get('ir.model.data')
90
if self.pool.get('sale.order'):
91
id = objid._get_id(cr, uid, 'document', 'dir_sale_order_all')
92
id = objid.browse(cr, uid, id, context=context).res_id
93
mid = self.pool.get('ir.model').search(cr, uid, [('model','=','sale.order')])
94
obj.write(cr, uid, [id], {
96
'ressource_type_id': mid[0],
99
aid = objid._get_id(cr, uid, 'sale', 'report_sale_order')
100
aid = objid.browse(cr, uid, aid, context=context).res_id
102
self.pool.get('document.directory.content').create(cr, uid, {
103
'name': "Print Order",
110
id = objid._get_id(cr, uid, 'document', 'dir_sale_order_quote')
111
id = objid.browse(cr, uid, id, context=context).res_id
112
obj.write(cr, uid, [id], {
114
'ressource_type_id': mid[0],
115
'domain': "[('state','=','draft')]",
118
if self.pool.get('product.product'):
119
id = objid._get_id(cr, uid, 'document', 'dir_product')
120
id = objid.browse(cr, uid, id, context=context).res_id
121
mid = self.pool.get('ir.model').search(cr, uid, [('model','=','product.product')])
122
obj.write(cr, uid, [id], {
124
'ressource_type_id': mid[0],
127
if self.pool.get('stock.location'):
128
aid = objid._get_id(cr, uid, 'stock', 'report_product_history')
129
aid = objid.browse(cr, uid, aid, context=context).res_id
131
self.pool.get('document.directory.content').create(cr, uid, {
132
'name': "Product Stock",
133
'suffix': "_stock_forecast",
140
if self.pool.get('account.analytic.account'):
141
id = objid._get_id(cr, uid, 'document', 'dir_project')
142
id = objid.browse(cr, uid, id, context=context).res_id
143
mid = self.pool.get('ir.model').search(cr, uid, [('model','=','account.analytic.account')])
144
obj.write(cr, uid, [id], {
146
'ressource_type_id': mid[0],
151
# Update the action for FTP browse.
152
aid = objid._get_id(cr, uid, 'document', 'action_document_browse')
153
aid = objid.browse(cr, uid, aid, context=context).res_id
154
self.pool.get('ir.actions.url').write(cr, uid, [aid], {'url': 'ftp://'+(conf.host or 'localhost')+':8021/'})
159
'res_model': 'ir.actions.configuration.wizard',
160
'type': 'ir.actions.act_window',
163
document_configuration_wizard()