| 1 |
nino.borges |
596 |
"""
|
| 2 |
|
|
|
| 3 |
|
|
SOW_Automator
|
| 4 |
|
|
Created by
|
| 5 |
|
|
Emanuel Borges
|
| 6 |
|
|
12.07.2015
|
| 7 |
|
|
|
| 8 |
|
|
Class to help automate the process of making and editing those SOWs.
|
| 9 |
|
|
|
| 10 |
|
|
|
| 11 |
|
|
"""
|
| 12 |
|
|
|
| 13 |
|
|
import RelativityLib,os,shutil,time,WordLib, wx
|
| 14 |
|
|
#from win32com.client import Dispatch
|
| 15 |
|
|
|
| 16 |
|
|
|
| 17 |
|
|
class CreateSOW(object):
|
| 18 |
|
|
version = "0.01"
|
| 19 |
|
|
|
| 20 |
|
|
def __init__(self,salesPersonLastName, clientName, clientOffice, projectName, contractType,workflow):
|
| 21 |
|
|
"""lastname of the sales person"""
|
| 22 |
|
|
#self.salesPersonFirstName = salesPersonFirstName
|
| 23 |
|
|
self.contractType = contractType
|
| 24 |
|
|
self.workflow = workflow
|
| 25 |
|
|
self.salesPersonLastName = salesPersonLastName
|
| 26 |
|
|
self.GetAddress()
|
| 27 |
|
|
self.salesPersonFullName = "%s, %s"%(salesPersonLastName,self.salesPersonFirstName)
|
| 28 |
|
|
self.clientName = clientName
|
| 29 |
|
|
self.clientOffice = clientOffice
|
| 30 |
|
|
self.projectName = projectName
|
| 31 |
|
|
self.tempDir = os.getenv('TEMP')
|
| 32 |
|
|
self.userName = os.getenv('USERNAME')
|
| 33 |
|
|
if self.userName == "Emanual Borges":
|
| 34 |
|
|
self.sowFinalPath = r"C:\Users\Emanual Borges\OneDrive - Advanced Discovery\Documents\SOW"
|
| 35 |
|
|
self.sowTemplatePath = r"C:\Users\Emanual Borges\OneDrive - Advanced Discovery\Documents\SOW\_Template"
|
| 36 |
|
|
else:
|
| 37 |
|
|
self.sowFinalPath = self.userName = os.path.join(os.getenv('USERPROFILE'),'Desktop')
|
| 38 |
|
|
self.sowTemplatePath = os.getcwd()
|
| 39 |
|
|
#self.proposalTemplateFileName = r"Proposal2.docx"
|
| 40 |
|
|
if contractType == "SOW":
|
| 41 |
|
|
self.sowTemplateFileName = r"SOW Template2.docx"
|
| 42 |
|
|
else:
|
| 43 |
|
|
self.sowTemplateFileName = r"Proposal2.docx"
|
| 44 |
|
|
#self.wordApp = Dispatch('Word.Application')
|
| 45 |
|
|
|
| 46 |
|
|
|
| 47 |
|
|
|
| 48 |
|
|
def GetAddress(self):
|
| 49 |
|
|
"""Returns the full address for the sales person"""
|
| 50 |
|
|
#test = RelativityLib.Relativity_Connection()
|
| 51 |
|
|
db = RelativityLib.CustomObjectTable('BORGES_01_DEMO','Sales_People')
|
| 52 |
|
|
for num, name in db.itemMatrix.iteritems():
|
| 53 |
|
|
if self.salesPersonLastName == str(name):
|
| 54 |
|
|
salesPersonID = num
|
| 55 |
|
|
db.LoadSingleItem(salesPersonID)
|
| 56 |
|
|
for i in db.currentItems:
|
| 57 |
|
|
self.salesPersonDisplayName = i['Sales_Person_DisplayName']
|
| 58 |
|
|
self.salesPersonTitle = i['Title']
|
| 59 |
|
|
self.salesPersonStreetAddress = i['Street_Address']
|
| 60 |
|
|
self.salesPersonCity = i['City']['Name']
|
| 61 |
|
|
self.salesPersonState = i['State']['Name']
|
| 62 |
|
|
self.salesPersonZipcode = i['Zipcode']
|
| 63 |
|
|
self.salesPersonPhoneNumber = i['Phone_Number']
|
| 64 |
|
|
self.salesPersonEmailAddress = i['Email_Address']
|
| 65 |
|
|
self.salesPersonFirstName = i['Sales_Person_FirstName']
|
| 66 |
|
|
|
| 67 |
|
|
def ProcessSOW(self):
|
| 68 |
|
|
"""Once everything is ready, this is called to create the actual work"""
|
| 69 |
|
|
## Copy and rename the template, after checking if it already exists.
|
| 70 |
|
|
newFileName = "%s%s%s_%s-%s_%s.docx"%(self.salesPersonFirstName[0],
|
| 71 |
|
|
self.salesPersonLastName[0],
|
| 72 |
|
|
time.strftime("%m%d%Y"),
|
| 73 |
|
|
self.clientName,
|
| 74 |
|
|
self.clientOffice,
|
| 75 |
|
|
self.projectName)
|
| 76 |
|
|
if os.path.isfile(os.path.join(self.sowFinalPath,newFileName)):
|
| 77 |
|
|
print "ERROR: File Already Exists."
|
| 78 |
|
|
else:
|
| 79 |
|
|
#shutil.copyfile(os.path.join(self.sowTemplatePath,self.sowTemplateFileName),os.path.join(self.sowFinalPath,newFileName))
|
| 80 |
|
|
shutil.copyfile(os.path.join(self.sowTemplatePath,self.sowTemplateFileName),os.path.join(self.tempDir,newFileName))
|
| 81 |
|
|
#self.GetAddress()
|
| 82 |
|
|
print self.salesPersonDisplayName
|
| 83 |
|
|
print self.salesPersonTitle
|
| 84 |
|
|
print self.salesPersonStreetAddress
|
| 85 |
|
|
print self.salesPersonCity
|
| 86 |
|
|
print self.salesPersonState
|
| 87 |
|
|
print self.salesPersonZipcode
|
| 88 |
|
|
print self.salesPersonPhoneNumber
|
| 89 |
|
|
print self.salesPersonEmailAddress
|
| 90 |
|
|
#self.search_replace_all(os.path.join(self.sowFinalPath,newFileName), "<<ProjectName>>", self.projectName)
|
| 91 |
|
|
## Open document and start finding and replacing.
|
| 92 |
|
|
wa = WordLib.WordConnection(os.path.join(self.tempDir,newFileName))
|
| 93 |
|
|
wa.search_replace_all("<<Client>>",self.clientName)
|
| 94 |
|
|
wa.search_replace_all("<<ProjectName>>",self.projectName)
|
| 95 |
|
|
wa.search_replace_all("<<SalesPersonName>>",self.salesPersonDisplayName)
|
| 96 |
|
|
wa.search_replace_all("<<SalesPersonTitle>>",self.salesPersonTitle)
|
| 97 |
|
|
wa.search_replace_all("<<SalesPersonAddress>>",self.salesPersonStreetAddress)
|
| 98 |
|
|
wa.search_replace_all("<<SalesPersonCityStateZip>>","%s, %s %s"%(self.salesPersonCity, self.salesPersonState, self.salesPersonZipcode))
|
| 99 |
|
|
wa.search_replace_all("<<SalesPersonPhone>>",self.salesPersonPhoneNumber)
|
| 100 |
|
|
wa.search_replace_all("<<SalesPersonEmail>>",self.salesPersonEmailAddress)
|
| 101 |
|
|
wa.search_replace_all("<<FileName>>",os.path.splitext(newFileName)[0])
|
| 102 |
|
|
if self.workflow == "Xpress":
|
| 103 |
|
|
wa.table_row_delete(2,9)
|
| 104 |
|
|
wa.table_row_delete(2,9)
|
| 105 |
|
|
wa.table_row_delete(2,9)
|
| 106 |
|
|
wa.table_row_delete(3,9)
|
| 107 |
|
|
wa.table_row_delete(3,9)
|
| 108 |
|
|
wa.table_row_delete(3,9)
|
| 109 |
|
|
else:
|
| 110 |
|
|
wa.table_row_delete(2,7)
|
| 111 |
|
|
wa.table_row_delete(2,7)
|
| 112 |
|
|
|
| 113 |
|
|
wa.table_row_delete(3,7)
|
| 114 |
|
|
wa.table_row_delete(3,7)
|
| 115 |
|
|
|
| 116 |
|
|
wa.Save()
|
| 117 |
|
|
wa.Close()
|
| 118 |
|
|
os.rename(os.path.join(self.tempDir,newFileName),os.path.join(self.sowFinalPath,newFileName))
|
| 119 |
|
|
|
| 120 |
|
|
|
| 121 |
|
|
class MyFrame(wx.Frame):
|
| 122 |
|
|
def __init__(self, parent, ID, title, pos=wx.DefaultPosition):
|
| 123 |
|
|
print "CWD is %s"%os.getcwd()
|
| 124 |
|
|
wx.Frame.__init__(self, parent, ID, title, pos, size =(370,570))#(550,580))
|
| 125 |
|
|
self.panel = wx.Panel(self,-1)
|
| 126 |
|
|
print "Connecting to Relativity..."
|
| 127 |
|
|
db = RelativityLib.CustomObjectTable('BORGES_01_DEMO','Sales_People')
|
| 128 |
|
|
#print db.itemMatrix.values()
|
| 129 |
|
|
salesPersonList = db.itemMatrix.values()
|
| 130 |
|
|
clientNameLabel = wx.StaticText(self.panel, -1, "Client Name: ")
|
| 131 |
|
|
self.clientNameTextBox = wx.TextCtrl(self.panel, -1, "", wx.DefaultPosition, (90,-1))
|
| 132 |
|
|
projectNameLabel = wx.StaticText(self.panel, -1, "Project Name: ")
|
| 133 |
|
|
self.projectNameTextBox = wx.TextCtrl(self.panel, -1, "", wx.DefaultPosition, (90,-1))
|
| 134 |
|
|
officeLocationLabel = wx.StaticText(self.panel, -1, "Office Location: ")
|
| 135 |
|
|
self.officeLocationTextBox = wx.TextCtrl(self.panel, -1, "", wx.DefaultPosition, (90,-1))
|
| 136 |
|
|
salesPersonLabel = wx.StaticText(self.panel, -1, "Sales Person: ",wx.DefaultPosition)
|
| 137 |
|
|
self.salesPersonChoice = wx.Choice(self.panel, -1, wx.DefaultPosition, choices=salesPersonList)
|
| 138 |
|
|
self.CreateBoxesSection()
|
| 139 |
|
|
self.sowOrProposalRadio1 = wx.RadioButton(self.panel, -1, 'SOW',style=wx.RB_GROUP)
|
| 140 |
|
|
self.sowOrProposalRadio2 = wx.RadioButton(self.panel, -1, 'Proposal')
|
| 141 |
|
|
self.hostedRadio1 = wx.RadioButton(self.panel, -1, 'Hosted Using Xpress',style=wx.RB_GROUP)
|
| 142 |
|
|
self.hostedRadio2 = wx.RadioButton(self.panel, -1, 'Non-Hosted')
|
| 143 |
|
|
|
| 144 |
|
|
sowOrProposalStaticBox = wx.StaticBox(self.panel, -1, 'SOW or Proposal:')
|
| 145 |
|
|
sowOrProposalStaticBoxSizer = wx.StaticBoxSizer(sowOrProposalStaticBox, wx.HORIZONTAL)
|
| 146 |
|
|
|
| 147 |
|
|
pricingStaticBox = wx.StaticBox(self.panel, -1, 'Pricing:')
|
| 148 |
|
|
pricingStaticBoxSizer = wx.StaticBoxSizer(pricingStaticBox, wx.HORIZONTAL)
|
| 149 |
|
|
|
| 150 |
|
|
requiredSectionSizer = wx.GridBagSizer(10,2)
|
| 151 |
|
|
requiredSectionSizer.Add(clientNameLabel,pos = (0,0))
|
| 152 |
|
|
requiredSectionSizer.Add(self.clientNameTextBox,pos = (0,1),span=(1,4), flag = wx.EXPAND)
|
| 153 |
|
|
requiredSectionSizer.Add(projectNameLabel,pos = (1,0))
|
| 154 |
|
|
requiredSectionSizer.Add(self.projectNameTextBox,pos = (1,1))
|
| 155 |
|
|
requiredSectionSizer.Add(officeLocationLabel,pos = (2,0))
|
| 156 |
|
|
requiredSectionSizer.Add(self.officeLocationTextBox,pos = (2,1))
|
| 157 |
|
|
requiredSectionSizer.Add(salesPersonLabel,pos = (3,0))
|
| 158 |
|
|
requiredSectionSizer.Add(self.salesPersonChoice,pos = (3,1))
|
| 159 |
|
|
|
| 160 |
|
|
mainSizer = wx.BoxSizer(wx.VERTICAL)
|
| 161 |
|
|
sowOrProposalStaticBoxSizer.Add(self.sowOrProposalRadio1, 0, wx.ALL|wx.ALIGN_LEFT,20)
|
| 162 |
|
|
sowOrProposalStaticBoxSizer.Add(self.sowOrProposalRadio2, 0, wx.ALL|wx.ALIGN_LEFT,20)
|
| 163 |
|
|
mainSizer.Add(sowOrProposalStaticBoxSizer,0,wx.ALL, 20)
|
| 164 |
|
|
mainSizer.Add(requiredSectionSizer,0, wx.ALL, 20)
|
| 165 |
|
|
|
| 166 |
|
|
hostedStaticBox = wx.StaticBox(self.panel, -1, 'Hosted or Non-Hosted:')
|
| 167 |
|
|
hostedStaticBoxSizer = wx.StaticBoxSizer(hostedStaticBox, wx.HORIZONTAL)
|
| 168 |
|
|
hostedStaticBoxSizer.Add(self.hostedRadio1, 0, wx.ALL|wx.ALIGN_LEFT,20)
|
| 169 |
|
|
hostedStaticBoxSizer.Add(self.hostedRadio2, 0, wx.ALL|wx.ALIGN_LEFT,20)
|
| 170 |
|
|
mainSizer.Add(hostedStaticBoxSizer,0,wx.ALL, 20)
|
| 171 |
|
|
mainSizer.Add(pricingStaticBoxSizer,0,wx.ALL, 20)
|
| 172 |
|
|
|
| 173 |
|
|
mainSizer.Add(self.buttonSizer,0, wx.ALL|wx.ALIGN_BOTTOM|wx.ALIGN_CENTER, 10)
|
| 174 |
|
|
|
| 175 |
|
|
self.panel.SetSizer(mainSizer)
|
| 176 |
|
|
|
| 177 |
|
|
self.Bind(wx.EVT_BUTTON, self.CloseWindow, self.cancelButton)
|
| 178 |
|
|
self.Bind(wx.EVT_BUTTON, self.OnProcess, self.oKButton)
|
| 179 |
|
|
|
| 180 |
|
|
def CreateBoxesSection(self):
|
| 181 |
|
|
self.oKButton = wx.Button(self.panel, wx.ID_OK)
|
| 182 |
|
|
self.oKButton.SetDefault()
|
| 183 |
|
|
self.oKButton.SetSize(self.oKButton.GetBestSize())
|
| 184 |
|
|
self.cancelButton = wx.Button(self.panel, wx.ID_CANCEL)
|
| 185 |
|
|
self.cancelButton.SetSize(self.cancelButton.GetBestSize())
|
| 186 |
|
|
self.buttonSizer = wx.BoxSizer(wx.HORIZONTAL)
|
| 187 |
|
|
self.buttonSizer.Add(self.oKButton,0,wx.ALL,10)
|
| 188 |
|
|
self.buttonSizer.Add(self.cancelButton,0,wx.ALL,10)
|
| 189 |
|
|
|
| 190 |
|
|
def CloseWindow(self, event):
|
| 191 |
|
|
self.Close(True)
|
| 192 |
|
|
|
| 193 |
|
|
def OnProcess(self, event):
|
| 194 |
|
|
print self.clientNameTextBox.GetValue()
|
| 195 |
|
|
print self.projectNameTextBox.GetValue()
|
| 196 |
|
|
print self.officeLocationTextBox.GetValue()
|
| 197 |
|
|
print self.salesPersonChoice.GetStringSelection()
|
| 198 |
|
|
if self.hostedRadio1.GetValue():
|
| 199 |
|
|
print "Xpress Selected"
|
| 200 |
|
|
workflow = "Xpress"
|
| 201 |
|
|
elif self.hostedRadio2.GetValue():
|
| 202 |
|
|
print "NonHosted Selected"
|
| 203 |
|
|
workflow = "Non-Hosted"
|
| 204 |
|
|
if self.sowOrProposalRadio1.GetValue():
|
| 205 |
|
|
print "SOW Selected"
|
| 206 |
|
|
contractType= "SOW"
|
| 207 |
|
|
elif self.sowOrProposalRadio2.GetValue():
|
| 208 |
|
|
print "Proposal Selected"
|
| 209 |
|
|
contractType = "Proposal"
|
| 210 |
|
|
|
| 211 |
|
|
t = CreateSOW(self.salesPersonChoice.GetStringSelection(),
|
| 212 |
|
|
self.clientNameTextBox.GetValue(),
|
| 213 |
|
|
self.officeLocationTextBox.GetValue(),
|
| 214 |
|
|
self.projectNameTextBox.GetValue(), contractType, workflow)
|
| 215 |
|
|
|
| 216 |
|
|
self.Show(False)
|
| 217 |
|
|
finishedDlg = wx.MessageDialog(self, "A new SOW is being generated.", "MCP: Process Complete",wx.OK, wx.DefaultPosition)
|
| 218 |
|
|
finishedDlg.ShowModal()
|
| 219 |
|
|
t.ProcessSOW()
|
| 220 |
|
|
self.Destroy()
|
| 221 |
|
|
|
| 222 |
|
|
class MyApp(wx.App):
|
| 223 |
|
|
def OnInit(self):
|
| 224 |
|
|
self.frame = MyFrame(None, -1, "SOW Creator v %s"%CreateSOW.version)
|
| 225 |
|
|
self.frame.Show(True)
|
| 226 |
|
|
self.SetTopWindow(self.frame)
|
| 227 |
|
|
return True
|
| 228 |
|
|
|
| 229 |
|
|
|
| 230 |
|
|
if __name__ == '__main__':
|
| 231 |
|
|
app = MyApp(0)
|
| 232 |
|
|
app.MainLoop() |