[IMP] Document:
[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         conf_id = ids and ids[0] or False
37         conf = self.browse(cr, uid, conf_id, context)
38         dir_pool = self.pool.get('document.directory')
39         data_pool = self.pool.get('ir.model.data')
40         model_pool = self.pool.get('ir.model')
41         content_pool = self.pool.get('document.directory.content')
42         if conf.sale_order and self.pool.get('sale.order'):
43             # Sale order
44             dir_data_id = data_pool._get_id(cr, uid, 'document', 'dir_sale_order_all')
45             if dir_data_id:
46                 sale_dir_id = data_pool.browse(cr, uid, dir_data_id, context=context).res_id
47             else:
48                 sale_dir_id = data_pool.create(cr, uid, {'name': 'Sale Orders'})
49             mid = model_pool.search(cr, uid, [('model','=','sale.order')])
50             dir_pool.write(cr, uid, [sale_dir_id], {
51                 'type':'ressource',
52                 'ressource_type_id': mid[0],
53                 'domain': '[]',
54             })
55             # Qutation
56             dir_data_id = data_pool._get_id(cr, uid, 'document', 'dir_sale_order_quote')
57             if dir_data_id:
58                 quta_dir_id = data_pool.browse(cr, uid, dir_data_id, context=context).res_id
59             else:
60                 quta_dir_id = data_pool.create(cr, uid, {'name': 'Sale Quotations'})
61             
62             dir_pool.write(cr, uid, [quta_dir_id], {
63                 'type':'ressource',
64                 'ressource_type_id': mid[0],
65                 'domain': "[('state','=','draft')]",
66             })
67             # Sale Order Report
68             order_report_data_id = data_pool._get_id(cr, uid, 'sale', 'report_sale_order')
69             if order_report_data_id:
70                 order_report_id = data_pool.browse(cr, uid, order_report_data_id, context=context).res_id
71
72                 content_pool.create(cr, uid, {
73                     'name': "Print Order",
74                     'suffix': "_print",
75                     'report_id': order_report_id,
76                     'extension': '.pdf',
77                     'include_name': 1,
78                     'directory_id': sale_dir_id,
79                 })
80
81                 content_pool.create(cr, uid, {
82                     'name': "Print Qutation",
83                     'suffix': "_print",
84                     'report_id': order_report_id,
85                     'extension': '.pdf',
86                     'include_name': 1,
87                     'directory_id': quta_dir_id,
88                 })
89             
90
91         if conf.product and self.pool.get('product.product'):
92             # Product
93             dir_data_id = data_pool._get_id(cr, uid, 'document', 'dir_product')
94             if dir_data_id:
95                 product_dir_id = data_pool.browse(cr, uid, dir_data_id, context=context).res_id
96             else:
97                 product_dir_id = data_pool.create(cr, uid, {'name': 'Products'})
98             
99             mid = model_pool.search(cr, uid, [('model','=','product.product')])
100             dir_pool.write(cr, uid, [product_dir_id], {
101                 'type':'ressource',
102                 'ressource_type_id': mid[0],
103             })           
104
105         if conf.project and self.pool.get('account.analytic.account'):
106             # Project
107             dir_data_id = data_pool._get_id(cr, uid, 'document', 'dir_project')
108             if dir_data_id:
109                 project_dir_id = data_pool.browse(cr, uid, dir_data_id, context=context).res_id
110             else:
111                 project_dir_id = data_pool.create(cr, uid, {'name': 'Projects'})
112             
113             mid = model_pool.search(cr, uid, [('model','=','account.analytic.account')])
114             dir_pool.write(cr, uid, [project_dir_id], {
115                 'type':'ressource',
116                 'ressource_type_id': mid[0],
117                 'domain': '[]',
118                 'ressource_tree': 1
119         })        
120 document_configuration()