1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 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 ##############################################################################
21 from osv import osv, fields
22 class document_configuration(osv.osv_memory):
24 _name='document.configuration'
25 _description = 'Auto Directory Configuration'
26 _inherit = 'res.config'
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."),
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'):
44 dir_data_id = data_pool._get_id(cr, uid, 'document', 'dir_sale_order_all')
46 sale_dir_id = data_pool.browse(cr, uid, dir_data_id, context=context).res_id
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], {
52 'ressource_type_id': mid[0],
56 dir_data_id = data_pool._get_id(cr, uid, 'document', 'dir_sale_order_quote')
58 quta_dir_id = data_pool.browse(cr, uid, dir_data_id, context=context).res_id
60 quta_dir_id = data_pool.create(cr, uid, {'name': 'Sale Quotations'})
62 dir_pool.write(cr, uid, [quta_dir_id], {
64 'ressource_type_id': mid[0],
65 'domain': "[('state','=','draft')]",
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
72 content_pool.create(cr, uid, {
73 'name': "Print Order",
75 'report_id': order_report_id,
78 'directory_id': sale_dir_id,
81 content_pool.create(cr, uid, {
82 'name': "Print Qutation",
84 'report_id': order_report_id,
87 'directory_id': quta_dir_id,
91 if conf.product and self.pool.get('product.product'):
93 dir_data_id = data_pool._get_id(cr, uid, 'document', 'dir_product')
95 product_dir_id = data_pool.browse(cr, uid, dir_data_id, context=context).res_id
97 product_dir_id = data_pool.create(cr, uid, {'name': 'Products'})
99 mid = model_pool.search(cr, uid, [('model','=','product.product')])
100 dir_pool.write(cr, uid, [product_dir_id], {
102 'ressource_type_id': mid[0],
105 if conf.project and self.pool.get('account.analytic.account'):
107 dir_data_id = data_pool._get_id(cr, uid, 'document', 'dir_project')
109 project_dir_id = data_pool.browse(cr, uid, dir_data_id, context=context).res_id
111 project_dir_id = data_pool.create(cr, uid, {'name': 'Projects'})
113 mid = model_pool.search(cr, uid, [('model','=','account.analytic.account')])
114 dir_pool.write(cr, uid, [project_dir_id], {
116 'ressource_type_id': mid[0],
120 document_configuration()