[FIX] account: fixed yml issue of account cash statement
[odoo/odoo.git] / addons / document_webdav / document_webdav.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 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 import nodes
24 from tools import config
25
26 class document_davdir(osv.osv):
27     _inherit = 'document.directory'
28
29     _columns = {
30         # Placed here just for a reference
31         'dav_prop_ids': fields.one2many('document.webdav.dir.property', 'dir_id', 'DAV properties'),
32         }
33
34     def get_node_class(self, cr, uid, ids, dbro=None, dynamic=False, context=None):
35         # Note: in this function, nodes come from document_webdav/nodes.py !
36         if dbro is None:
37             dbro = self.browse(cr, uid, ids, context=context)
38
39         if dynamic:
40             assert dbro.type == 'directory'
41             return nodes.node_res_obj
42         elif dbro.type == 'directory':
43             return nodes.node_dir
44         elif dbro.type == 'ressource':
45             return nodes.node_res_dir
46         else:
47             raise ValueError("dir node for %s type", dbro.type)
48
49     def _prepare_context(self, cr, uid, nctx, context):
50         nctx.node_file_class = nodes.node_file
51         # We can fill some more fields, but avoid any expensive function
52         # that might be not worth preparing.
53         nctx.extra_ctx['webdav_path'] = '/'+config.get_misc('webdav','vdir','webdav')
54         usr_obj = self.pool.get('res.users')
55         res = usr_obj.read(cr, uid, uid, ['login'])
56         if res:
57             nctx.extra_ctx['username'] = res['login']
58         # TODO group
59         return
60
61     def _locate_child(self, cr, uid, root_id, uri,nparent, ncontext):
62         """ try to locate the node in uri,
63             Return a tuple (node_dir, remaining_path)
64         """
65         return (nodes.node_database(context=ncontext), uri)
66
67 document_davdir()
68
69 class dav_dir_property(osv.osv):
70     """ Arbitrary WebDAV properties, attached to document.directories.
71     
72     Some DAV properties have to be settable at directories, depending
73     on the database directory structure.
74     
75     Example would be the principal-URL.
76     
77     There _can_ be properties without a directory, which means that they
78     globally apply to all the directories (aka. collections) of the
79     present database.
80     """
81     _name = 'document.webdav.dir.property'
82     
83     _columns = {
84         'dir_id': fields.many2one('document.directory', 'Directory', required=False, select=1),
85         'namespace': fields.char('Namespace', size=127, required=True),
86         'name': fields.char('Name', size=64, required=True),
87         'value': fields.text('Value'),
88         'do_subst': fields.boolean('Substitute', required=True),
89         }
90         
91     _defaults = {
92         'do_subst': False,
93         }
94         
95 dav_dir_property()
96
97 #eof