2013-04-22 17:04:29 +00:00
|
|
|
#########################################################################
|
2010-09-18 07:24:46 +00:00
|
|
|
#
|
2013-04-22 17:04:29 +00:00
|
|
|
# Copyright (c) 2003-2004 Danny Brewer d29583@groovegarden.com
|
|
|
|
# Copyright (C) 2004-2010 OpenERP SA (<http://openerp.com>).
|
2010-09-18 07:24:46 +00:00
|
|
|
#
|
2013-04-22 17:04:29 +00:00
|
|
|
# This library is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
|
|
# License as published by the Free Software Foundation; either
|
|
|
|
# version 2.1 of the License, or (at your option) any later version.
|
2010-09-18 07:24:46 +00:00
|
|
|
#
|
2013-04-22 17:04:29 +00:00
|
|
|
# This library is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# Lesser General Public License for more details.
|
2012-08-06 16:28:17 +00:00
|
|
|
#
|
2013-04-22 17:04:29 +00:00
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
|
|
# License along with this library; if not, write to the Free Software
|
2013-05-14 14:37:28 +00:00
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2012-08-06 16:28:17 +00:00
|
|
|
#
|
2013-04-22 17:04:29 +00:00
|
|
|
# See: http://www.gnu.org/licenses/lgpl.html
|
2012-08-06 16:28:17 +00:00
|
|
|
#
|
2013-04-22 17:04:29 +00:00
|
|
|
#############################################################################
|
2010-09-18 07:24:46 +00:00
|
|
|
|
|
|
|
import re
|
|
|
|
import uno
|
|
|
|
import string
|
|
|
|
import unohelper
|
|
|
|
import xmlrpclib
|
|
|
|
from com.sun.star.task import XJobExecutor
|
|
|
|
if __name__<>"package":
|
|
|
|
from lib.gui import *
|
|
|
|
from Expression import Expression
|
|
|
|
from Fields import Fields
|
|
|
|
from Repeatln import RepeatIn
|
|
|
|
from lib.error import *
|
|
|
|
database="test"
|
|
|
|
uid = 3
|
|
|
|
|
|
|
|
class modify(unohelper.Base, XJobExecutor ):
|
2012-03-05 18:40:03 +00:00
|
|
|
def __init__(self, ctx):
|
2010-09-18 07:24:46 +00:00
|
|
|
self.ctx = ctx
|
|
|
|
self.module = "openerp_report"
|
|
|
|
self.version = "0.1"
|
|
|
|
|
|
|
|
# Variable Declaration
|
|
|
|
desktop = getDesktop()
|
|
|
|
doc = desktop.getCurrentComponent()
|
|
|
|
docinfo = doc.getDocumentInfo()
|
|
|
|
self.oVC = doc.CurrentController.getViewCursor()
|
|
|
|
if not docinfo.getUserFieldValue(0)=="":
|
|
|
|
self.sMyHost= docinfo.getUserFieldValue(0)
|
|
|
|
else:
|
|
|
|
ErrorDialog(
|
2013-03-04 17:31:32 +00:00
|
|
|
"Please insert user define field Field-1",
|
|
|
|
"Just go to File->Properties->User Define \n"
|
|
|
|
"Field-1 E.g. http://localhost:8069"
|
|
|
|
)
|
2010-09-18 07:24:46 +00:00
|
|
|
exit(1)
|
|
|
|
|
|
|
|
# Check weather Field-4 is available or not otherwise exit from application
|
|
|
|
if not docinfo.getUserFieldValue(3) == "" and not docinfo.getUserFieldValue(0)=="":
|
|
|
|
if self.oVC.TextField:
|
|
|
|
self.oCurObj=self.oVC.TextField
|
2013-03-04 17:31:32 +00:00
|
|
|
item = self.oCurObj.Items[0]
|
2010-09-18 07:24:46 +00:00
|
|
|
|
2013-03-04 17:31:32 +00:00
|
|
|
kind, group1, group2 = self.getOperation(self.oCurObj.Items[1] )
|
2010-09-18 07:24:46 +00:00
|
|
|
|
2013-03-04 17:31:32 +00:00
|
|
|
start_group1 = group1[:group1.find(".")]
|
|
|
|
stop_group1 = group1[group1.find("."):].replace(".", "/")
|
2010-09-18 07:24:46 +00:00
|
|
|
|
|
|
|
if kind == "field":
|
2013-03-04 17:31:32 +00:00
|
|
|
Fields( start_group1, stop_group1, item, True )
|
2010-09-18 07:24:46 +00:00
|
|
|
elif kind == "expression":
|
|
|
|
Expression( group1, item, True )
|
|
|
|
elif kind == "repeatIn":
|
2013-03-04 17:31:32 +00:00
|
|
|
RepeatIn( start_group1, group2, stop_group1, item, True )
|
2010-09-18 07:24:46 +00:00
|
|
|
else:
|
|
|
|
ErrorDialog(
|
2012-08-06 16:28:17 +00:00
|
|
|
"Please place your cursor at beginning of field that you want to modify.",""
|
2013-03-04 17:31:32 +00:00
|
|
|
)
|
2010-09-18 07:24:46 +00:00
|
|
|
|
|
|
|
else:
|
|
|
|
ErrorDialog(
|
2013-03-04 17:31:32 +00:00
|
|
|
"Please insert user define field Field-1 or Field-4",
|
|
|
|
"Just go to File->Properties->User Define \n"
|
|
|
|
"Field-1 E.g. http://localhost:8069 \n"
|
|
|
|
"OR \n"
|
|
|
|
"Field-4 E.g. account.invoice"
|
|
|
|
)
|
2010-09-18 07:24:46 +00:00
|
|
|
exit(1)
|
|
|
|
|
|
|
|
def getOperation(self, str):
|
|
|
|
#str = "[[ RepeatIn(objects, 'variable') ]]" #repeatIn
|
|
|
|
#str = "[[ saleorder.partner_id.name ]]" # field
|
|
|
|
#str = "[[ some thing complex ]]" # expression
|
|
|
|
method1 = lambda x: (u'repeatIn', x.group(1), x.group(2))
|
|
|
|
method2 = lambda x: (u'field', x.group(1), None)
|
|
|
|
method3 = lambda x: (u'expression', x.group(1), None)
|
|
|
|
regexes = [
|
2013-03-04 17:31:32 +00:00
|
|
|
('\\[\\[ *repeatIn\\( *(.+)*, *\'([a-zA-Z0-9_]+)\' *\\) *\\]\\]', method1),
|
|
|
|
('\\[\\[ *([a-zA-Z0-9_\.]+) *\\]\\]', method2),
|
|
|
|
('\\[\\[ *(.+) *\\]\\]', method3)
|
2010-09-18 07:24:46 +00:00
|
|
|
]
|
|
|
|
for (rule,method) in regexes:
|
2013-03-04 17:31:32 +00:00
|
|
|
res = re.match(rule, str)
|
|
|
|
if res:
|
|
|
|
return method(res)
|
2010-09-18 07:24:46 +00:00
|
|
|
|
|
|
|
if __name__<>"package":
|
|
|
|
modify(None)
|
|
|
|
else:
|
|
|
|
g_ImplementationHelper.addImplementation( modify, "org.openoffice.openerp.report.modify", ("com.sun.star.task.Job",),)
|
|
|
|
|
2011-11-22 08:51:38 +00:00
|
|
|
|
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|