~tempo-openerp/+junk/loewert-report-name

« back to all changes in this revision

Viewing changes to addons/base_report_designer/plugin/openerp_report_designer/bin/script/modify.py

  • Committer: jbe at tempo-consulting
  • Date: 2013-08-21 08:48:11 UTC
  • Revision ID: jbe@tempo-consulting.fr-20130821084811-913uo4l7b5ayxq8m
[NEW] Création de la branche trunk Loewert

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#########################################################################
 
2
#
 
3
#  Copyright (c) 2003-2004 Danny Brewer d29583@groovegarden.com
 
4
#  Copyright (C) 2004-2010 OpenERP SA (<http://openerp.com>).
 
5
#
 
6
#  This library is free software; you can redistribute it and/or
 
7
#  modify it under the terms of the GNU Lesser General Public
 
8
#  License as published by the Free Software Foundation; either
 
9
#  version 2.1 of the License, or (at your option) any later version.
 
10
#
 
11
#  This library is distributed in the hope that it will be useful,
 
12
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
#  Lesser General Public License for more details.
 
15
#
 
16
#  You should have received a copy of the GNU Lesser General Public
 
17
#  License along with this library; if not, write to the Free Software
 
18
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
19
#
 
20
#  See:  http://www.gnu.org/licenses/lgpl.html
 
21
#
 
22
#############################################################################
 
23
 
 
24
import re
 
25
import uno
 
26
import string
 
27
import unohelper
 
28
import xmlrpclib
 
29
from com.sun.star.task import XJobExecutor
 
30
if __name__<>"package":
 
31
    from lib.gui import *
 
32
    from Expression import Expression
 
33
    from Fields import Fields
 
34
    from Repeatln import RepeatIn
 
35
    from lib.error import *
 
36
    database="test"
 
37
    uid = 3
 
38
 
 
39
class modify(unohelper.Base, XJobExecutor ):
 
40
    def __init__(self, ctx):
 
41
        self.ctx     = ctx
 
42
        self.module  = "openerp_report"
 
43
        self.version = "0.1"
 
44
 
 
45
        # Variable Declaration
 
46
        desktop = getDesktop()
 
47
        doc = desktop.getCurrentComponent()
 
48
        docinfo = doc.getDocumentInfo()
 
49
        self.oVC = doc.CurrentController.getViewCursor()
 
50
        if not docinfo.getUserFieldValue(0)=="":
 
51
            self.sMyHost= docinfo.getUserFieldValue(0)
 
52
        else:
 
53
            ErrorDialog(
 
54
                "Please insert user define field Field-1",
 
55
                "Just go to File->Properties->User Define \n"
 
56
                "Field-1 E.g. http://localhost:8069"
 
57
            )
 
58
            exit(1)
 
59
 
 
60
        # Check weather Field-4 is available or not otherwise exit from application
 
61
        if not docinfo.getUserFieldValue(3) == "" and not docinfo.getUserFieldValue(0)=="":
 
62
            if self.oVC.TextField:
 
63
                self.oCurObj=self.oVC.TextField
 
64
                item = self.oCurObj.Items[0]
 
65
 
 
66
                kind, group1, group2 = self.getOperation(self.oCurObj.Items[1] )
 
67
 
 
68
                start_group1 = group1[:group1.find(".")]
 
69
                stop_group1 = group1[group1.find("."):].replace(".", "/")
 
70
 
 
71
                if kind == "field":
 
72
                    Fields( start_group1, stop_group1, item, True )
 
73
                elif kind == "expression":
 
74
                    Expression( group1, item, True )
 
75
                elif kind == "repeatIn":
 
76
                    RepeatIn( start_group1, group2, stop_group1, item, True )
 
77
            else:
 
78
                ErrorDialog(
 
79
            "Please place your cursor at beginning of field that you want to modify.",""
 
80
                )
 
81
 
 
82
        else:
 
83
            ErrorDialog(
 
84
                "Please insert user define field Field-1 or Field-4",
 
85
                "Just go to File->Properties->User Define \n"
 
86
                "Field-1 E.g. http://localhost:8069 \n"
 
87
                "OR \n"
 
88
                "Field-4 E.g. account.invoice"
 
89
            )
 
90
            exit(1)
 
91
 
 
92
    def getOperation(self, str):
 
93
        #str = "[[ RepeatIn(objects, 'variable') ]]" #repeatIn
 
94
        #str = "[[ saleorder.partner_id.name ]]" # field
 
95
        #str = "[[ some thing complex ]]" # expression
 
96
        method1 = lambda x: (u'repeatIn', x.group(1), x.group(2))
 
97
        method2 = lambda x: (u'field', x.group(1), None)
 
98
        method3 = lambda x: (u'expression', x.group(1), None)
 
99
        regexes = [
 
100
            ('\\[\\[ *repeatIn\\( *(.+)*, *\'([a-zA-Z0-9_]+)\' *\\) *\\]\\]', method1),
 
101
            ('\\[\\[ *([a-zA-Z0-9_\.]+) *\\]\\]', method2),
 
102
            ('\\[\\[ *(.+) *\\]\\]', method3)
 
103
        ]
 
104
        for (rule,method) in regexes:
 
105
            res = re.match(rule, str)
 
106
            if res:
 
107
                return method(res)
 
108
 
 
109
if __name__<>"package":
 
110
    modify(None)
 
111
else:
 
112
    g_ImplementationHelper.addImplementation( modify, "org.openoffice.openerp.report.modify", ("com.sun.star.task.Job",),)
 
113
 
 
114
 
 
115
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: