[IMP] : Added context=None on methods used for _constraints and replaced context...
[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 from osv import osv, fields
22 class document_configuration(osv.osv_memory):
23
24     _name='document.configuration'
25     _description = 'Auto Directory Configuration'
26     _inherit = 'res.config'   
27
28     _columns = {
29         'sale_order' : fields.boolean('Sale Order', help="Auto directory configuration for Sale Orders and Quotation with report."),
30         'product' : fields.boolean('Product', help="Auto directory configuration for Products."),
31         'project': fields.boolean('Project', help="Auto directory configuration for Projects."),
32     }
33     
34
35     def execute(self, cr, uid, ids, context=None):
36         if not context:
37             context = {}
38         conf_id = ids and ids[0] or False
39         conf = self.browse(cr, uid, conf_id, context=context)
40         dir_pool = self.pool.get('document.directory')
41         data_pool = self.pool.get('ir.model.data')
42         model_pool = self.pool.get('ir.model')
43         content_pool = self.pool.get('document.directory.content')
44         if conf.sale_order and self.pool.get('sale.order'):
45             # Sale order
46             dir_data_id = data_pool._get_id(cr, uid, 'document', 'dir_sale_order_all')
47             if dir_data_id:
48                 sale_dir_id = data_pool.browse(cr, uid, dir_data_id, context=context).res_id
49             else:
50                 sale_dir_id = data_pool.create(cr, uid, {'name': 'Sale Orders'})
51             mid = model_pool.search(cr, uid, [('model','=','sale.order')])
52             dir_pool.write(cr, uid, [sale_dir_id], {
53                 'type':'ressource',
54                 'ressource_type_id': mid[0],
55                 'domain': '[]',
56             })
57             # Qutation
58             dir_data_id = data_pool._get_id(cr, uid, 'document', 'dir_sale_order_quote')
59             if dir_data_id:
60                 quta_dir_id = data_pool.browse(cr, uid, dir_data_id, context=context).res_id
61             else:
62                 quta_dir_id = data_pool.create(cr, uid, {'name': 'Sale Quotations'})
63             
64             dir_pool.write(cr, uid, [quta_dir_id], {
65                 'type':'ressource',
66                 'ressource_type_id': mid[0],
67                 'domain': "[('state','=','draft')]",
68             })
69             # Sale Order Report
70             order_report_data_id = data_pool._get_id(cr, uid, 'sale', 'report_sale_order')
71             if order_report_data_id:
72                 order_report_id = data_pool.browse(cr, uid, order_report_data_id, context=context).res_id
73
74                 content_pool.create(cr, uid, {
75                     'name': "Print Order",
76                     'suffix': "_print",
77                     'report_id': order_report_id,
78                     'extension': '.pdf',
79                     'include_name': 1,
80                     'directory_id': sale_dir_id,
81                 })
82
83                 content_pool.create(cr, uid, {
84                     'name': "Print Qutation",
85                     'suffix': "_print",
86                     'report_id': order_report_id,
87                     'extension': '.pdf',
88                     'include_name': 1,
89                     'directory_id': quta_dir_id,
90                 })
91             
92
93         if conf.product and self.pool.get('product.product'):
94             # Product
95             dir_data_id = data_pool._get_id(cr, uid, 'document', 'dir_product')
96             if dir_data_id:
97                 product_dir_id = data_pool.browse(cr, uid, dir_data_id, context=context).res_id
98             else:
99                 product_dir_id = data_pool.create(cr, uid, {'name': 'Products'})
100             
101             mid = model_pool.search(cr, uid, [('model','=','product.product')])
102             dir_pool.write(cr, uid, [product_dir_id], {
103                 'type':'ressource',
104                 'ressource_type_id': mid[0],
105             })           
106
107         if conf.project and self.pool.get('account.analytic.account'):
108             # Project
109             dir_data_id = data_pool._get_id(cr, uid, 'document', 'dir_project')
110             if dir_data_id:
111                 project_dir_id = data_pool.browse(cr, uid, dir_data_id, context=context).res_id
112             else:
113                 project_dir_id = data_pool.create(cr, uid, {'name': 'Projects'})
114             
115             mid = model_pool.search(cr, uid, [('model','=','account.analytic.account')])
116             dir_pool.write(cr, uid, [project_dir_id], {
117                 'type':'ressource',
118                 'ressource_type_id': mid[0],
119                 'domain': '[]',
120                 'ressource_tree': 1
121         })        
122 document_configuration()