[IMP] use const SUPERUSER_ID insteand of int 1
[odoo/odoo.git] / addons / document / wizard / document_configuration.py
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
24 class document_configuration(osv.osv_memory):
25     _name='document.configuration'
26     _description = 'Directory Configuration'
27     _inherit = 'res.config'
28
29     def execute(self, cr, uid, ids, context=None):
30         dir_pool = self.pool.get('document.directory')
31         data_pool = self.pool.get('ir.model.data')
32         model_pool = self.pool.get('ir.model')
33         content_pool = self.pool.get('document.directory.content')
34         if self.pool.get('sale.order'):
35             # Sale order
36             dir_data_id = data_pool._get_id(cr, uid, 'document', 'dir_sale_order_all')
37             if dir_data_id:
38                 sale_dir_id = data_pool.browse(cr, uid, dir_data_id, context=context).res_id
39             else:
40                 sale_dir_id = data_pool.create(cr, uid, {'name': 'Sale Orders'})
41             mid = model_pool.search(cr, uid, [('model','=','sale.order')])
42             dir_pool.write(cr, uid, [sale_dir_id], {
43                 'type':'ressource',
44                 'ressource_type_id': mid[0],
45                 'domain': '[]',
46             })
47             # Qutation
48             dir_data_id = data_pool._get_id(cr, uid, 'document', 'dir_sale_order_quote')
49             if dir_data_id:
50                 quta_dir_id = data_pool.browse(cr, uid, dir_data_id, context=context).res_id
51             else:
52                 quta_dir_id = data_pool.create(cr, uid, {'name': 'Sale Quotations'})
53
54             dir_pool.write(cr, uid, [quta_dir_id], {
55                 'type':'ressource',
56                 'ressource_type_id': mid[0],
57                 'domain': "[('state','=','draft')]",
58             })
59             # Sale Order Report
60             order_report_data_id = data_pool._get_id(cr, uid, 'sale', 'report_sale_order')
61             if order_report_data_id:
62                 order_report_id = data_pool.browse(cr, uid, order_report_data_id, context=context).res_id
63
64                 content_pool.create(cr, uid, {
65                     'name': "Print Order",
66                     'suffix': "_print",
67                     'report_id': order_report_id,
68                     'extension': '.pdf',
69                     'include_name': 1,
70                     'directory_id': sale_dir_id,
71                 })
72
73                 content_pool.create(cr, uid, {
74                     'name': "Print Quotation",
75                     'suffix': "_print",
76                     'report_id': order_report_id,
77                     'extension': '.pdf',
78                     'include_name': 1,
79                     'directory_id': quta_dir_id,
80                 })
81
82
83         if self.pool.get('product.product'):
84             # Product
85             dir_data_id = data_pool._get_id(cr, uid, 'document', 'dir_product')
86             if dir_data_id:
87                 product_dir_id = data_pool.browse(cr, uid, dir_data_id, context=context).res_id
88             else:
89                 product_dir_id = data_pool.create(cr, uid, {'name': 'Products'})
90
91             mid = model_pool.search(cr, uid, [('model','=','product.product')])
92             dir_pool.write(cr, uid, [product_dir_id], {
93                 'type':'ressource',
94                 'ressource_type_id': mid[0],
95             })
96
97         if self.pool.get('account.analytic.account'):
98             # Project
99             dir_data_id = data_pool._get_id(cr, uid, 'document', 'dir_project')
100             if dir_data_id:
101                 project_dir_id = data_pool.browse(cr, uid, dir_data_id, context=context).res_id
102             else:
103                 project_dir_id = data_pool.create(cr, uid, {'name': 'Projects'})
104
105             mid = model_pool.search(cr, uid, [('model','=','account.analytic.account')])
106             dir_pool.write(cr, uid, [project_dir_id], {
107                 'type':'ressource',
108                 'ressource_type_id': mid[0],
109                 'domain': '[]',
110                 'ressource_tree': 1
111         })
112 document_configuration()
113
114 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: