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