PageRenderTime 36ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/core/promogest/modules/GestioneCommesse/ui/AnagraficaCommesseEdit.py

http://promogest.googlecode.com/
Python | 404 lines | 382 code | 7 blank | 15 comment | 0 complexity | 165ba1bfb811bdc5d5a8e62f6fe9c773 MD5 | raw file
Possible License(s): GPL-2.0
  1. # -*- coding: utf-8 -*-
  2. # Copyright (C) 2005, 2006, 2007 2008, 2009, 2010, 2011 by Promotux
  3. # di Francesco Meloni snc - http://www.promotux.it/
  4. # Author: Francesco Meloni <francesco@promotux.it>
  5. # This file is part of Promogest.
  6. # Promogest is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 2 of the License, or
  9. # (at your option) any later version.
  10. # Promogest is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. # You should have received a copy of the GNU General Public License
  15. # along with Promogest. If not, see <http://www.gnu.org/licenses/>.
  16. import sys
  17. from decimal import *
  18. from promogest import Environment
  19. from promogest.ui.AnagraficaComplessaEdit import AnagraficaEdit
  20. from promogest.modules.GestioneCommesse.dao.TestataCommessa import TestataCommessa
  21. from promogest.modules.GestioneCommesse.dao.RigaCommessa import RigaCommessa
  22. from promogest.dao.Cliente import Cliente
  23. from promogest.dao.Articolo import Articolo
  24. from promogest.dao.Fornitore import Fornitore
  25. from promogest.dao.Magazzino import Magazzino
  26. from promogest.dao.Vettore import Vettore
  27. from promogest.dao.Promemoria import Promemoria
  28. from promogest.dao.TestataDocumento import TestataDocumento
  29. from promogest.ui.utils import *
  30. from promogest.ui.utilsCombobox import *
  31. class AnagraficaCommesseEdit(AnagraficaEdit):
  32. """ Modifica un record dell'anagrafica delle commessa """
  33. def __init__(self, anagrafica):
  34. AnagraficaEdit.__init__(self,
  35. anagrafica,
  36. 'anagrafica_commessa_detail_vbox',
  37. 'Dati della commessa cliente.',
  38. gladeFile='GestioneCommesse/gui/_anagrafica_commessa_elements.glade',
  39. module=True)
  40. self._widgetFirstFocus = self.titolo_commessa_entry
  41. self.anagrafica = anagrafica
  42. self.editRiga = None
  43. self.daoo = None
  44. self.dao_temp = None
  45. self.dao_class = None
  46. self.dao_id = None
  47. self.num = None
  48. self.aziendaStr = Environment.azienda
  49. def draw(self, cplx=False):
  50. fillComboboxStadioCommessa(self.stadio_commessa_combobox.combobox)
  51. self.stadio_commessa_combobox.connect('clicked',
  52. on_stadio_commessa_combobox_clicked)
  53. model = self.tipo_combobox.get_model()
  54. model.clear()
  55. self.tipiDict = {"":None,
  56. "DOCUMENTO":"TestataDocumento",
  57. "PROMEMORIA":"Promemoria",
  58. "FORNITORE":"Fornitore",
  59. "ARTICOLO":"Articolo",
  60. "VETTORE":"Vettore",
  61. "MAGAZZINO":"Magazzino",
  62. "CLIENTE":"Cliente",
  63. "AGENTE":"Agente"}
  64. for t in self.tipiDict.keys():
  65. model.append((t,))
  66. self.open_button.set_sensitive(False)
  67. self.trova_button.set_sensitive(False)
  68. self.new_dao_button.set_sensitive(False)
  69. self.stampa_dao_button.set_sensitive(False)
  70. def composeInfoDaoLabel(self, dao):
  71. info = ""
  72. if not dao:
  73. info = ""
  74. elif dao.__class__.__name__ == "TestataDocumento":
  75. info = "<b>%s</b> - <b>del</b> %s <b>N°</b> %s - <b>Da/A</b> %s - <b>TOT: â&#x201A;?</b> %s" %(str(dao.operazione),
  76. dateToString(dao.data_documento),
  77. str(dao.numero),
  78. dao.intestatario,
  79. str(mN(dao._totaleScontato,2)))
  80. elif dao.__class__.__name__ == "Promemoria":
  81. info = "Promemoria <b>del</b> %s <b>Descr:</b> %s" %(str(dateToString(dao.data_inserimento)),
  82. dao.descrizione[0:50])
  83. elif dao.__class__.__name__ in ["Cliente", "Fornitore", "Vettore", "Agente"]:
  84. info = "<b>%s</b>, %s , %s %s" %(str(dao.__class__.__name__),
  85. dao.ragione_sociale,
  86. dao.cognome,
  87. dao.nome)
  88. elif dao.__class__.__name__ =="Magazzino":
  89. info = "Magazzino: %s , %s " %(str(dao.denominazione), str(dao.pvcode))
  90. self.info_dao_label.set_markup(info)
  91. def on_tipo_combobox_changed(self, combobox):
  92. """ """
  93. self.open_button.set_sensitive(False)
  94. self.trova_button.set_sensitive(False)
  95. self.new_dao_button.set_sensitive(False)
  96. self.stampa_dao_button.set_sensitive(False)
  97. self.tipo_dao = combobox.get_model().get_value(combobox.get_active_iter(), 0).lower()
  98. if self.tipo_dao:
  99. # self.open_button.set_sensitive(True)
  100. self.trova_button.set_sensitive(True)
  101. self.new_dao_button.set_sensitive(True)
  102. # self.stampa_dao_button.set_sensitive(True)
  103. else:
  104. self.composeInfoDaoLabel(None)
  105. def on_new_dao_button_clicked(self, button):
  106. if self.tipo_dao == "DOCUMENTO".lower():
  107. from promogest.ui.AnagraficaDocumenti import AnagraficaDocumenti
  108. anag = AnagraficaDocumenti(self.aziendaStr)
  109. showAnagrafica(self.getTopLevel(), anag)
  110. anag.on_record_new_activate()
  111. elif self.tipo_dao == "ARTICOLO".lower():
  112. from promogest.ui.AnagraficaArticoli import AnagraficaArticoli
  113. anag = AnagraficaArticoli(self.aziendaStr)
  114. showAnagrafica(self.getTopLevel(), anag)
  115. anag.on_record_new_activate()
  116. elif self.tipo_dao == "CLIENTE".lower():
  117. from promogest.ui.AnagraficaClienti import AnagraficaClienti
  118. anag = AnagraficaClienti(self.aziendaStr)
  119. showAnagrafica(self.getTopLevel(), anag)
  120. anag.on_record_new_activate()
  121. elif self.tipo_dao == "VETTORE".lower():
  122. from promogest.ui.AnagraficaVettori import AnagraficaVettori
  123. anag = AnagraficaVettori(self.aziendaStr)
  124. showAnagrafica(self.getTopLevel(), anag)
  125. anag.on_record_new_activate()
  126. elif self.tipo_dao == "FORNITORE".lower():
  127. from promogest.ui.AnagraficaFornitori import AnagraficaFornitori
  128. anag = AnagraficaFornitori(self.aziendaStr)
  129. showAnagrafica(self.getTopLevel(), anag)
  130. anag.on_record_new_activate()
  131. elif self.tipo_dao == "PROMEMORIA".lower():
  132. from promogest.ui.AnagraficaPromemoria import AnagraficaPromemoria
  133. anag = AnagraficaPromemoria(self.aziendaStr)
  134. showAnagrafica(self.getTopLevel(), anag)
  135. anag.on_record_new_activate()
  136. # from promogest.modules.Contatti.ui.AnagraficaContatti import AnagraficaContatti
  137. # anag = AnagraficaContatti(self.aziendaStr)
  138. # showAnagrafica(self.getTopLevel(), anag)
  139. # anag.on_record_new_activate()
  140. def on_trova_button_clicked(self, button):
  141. # self.new_dao_button.set_sensitive(False)
  142. def returnDao(anagWindow):
  143. if anag.dao:
  144. self.dao_temp = anag.dao
  145. self.composeInfoDaoLabel(anag.dao)
  146. self.open_button.set_sensitive(True)
  147. self.stampa_dao_button.set_sensitive(True)
  148. else:
  149. self.dao_temp = None
  150. if self.tipo_dao !="":
  151. if self.tipo_dao =="DOCUMENTO".lower():
  152. from promogest.ui.SimpleSearch.RicercaDocumenti import RicercaDocumenti
  153. anag = RicercaDocumenti()
  154. elif self.tipo_dao =="PROMEMORIA".lower():
  155. from promogest.ui.SimpleSearch.RicercaPromemoria import RicercaPromemoria
  156. anag = RicercaPromemoria()
  157. elif self.tipo_dao =="FORNITORE".lower():
  158. from promogest.ui.SimpleSearch.RicercaFornitori import RicercaFornitori
  159. anag = RicercaFornitori()
  160. elif self.tipo_dao =="ARTICOLO".lower():
  161. from promogest.ui.SimpleSearch.RicercaArticoli import RicercaArticoli
  162. anag = RicercaArticoli()
  163. elif self.tipo_dao =="VETTORE".lower():
  164. from promogest.ui.SimpleSearch.RicercaVettori import RicercaVettori
  165. anag = RicercaVettori()
  166. elif self.tipo_dao =="MAGAZZINO".lower():
  167. from promogest.ui.SimpleSearch.RicercaMagazzini import RicercaMagazzini
  168. anag = RicercaMagazzini()
  169. elif self.tipo_dao =="CLIENTE".lower():
  170. from promogest.ui.SimpleSearch.RicercaClienti import RicercaClienti
  171. anag = RicercaClienti()
  172. elif self.tipo_dao =="AGENTE".lower():
  173. from promogest.ui.SimpleSearch.RicercaAgenti import RicercaAgenti
  174. anag = RicercaAgenti()
  175. anagWindow = anag.getTopLevel()
  176. anagWindow.show_all()
  177. anagWindow.connect("hide",returnDao)
  178. def setDao(self, dao):
  179. if dao is None:
  180. # Ricrea il Dao con una connessione al DBMS SQL
  181. self.dao = TestataCommessa()
  182. a = select([func.max(TestataCommessa.numero)]).execute().fetchall() or 0
  183. numero = 0
  184. if a:
  185. numero = a[0][0] or 0
  186. self.dao.numero = numero+1
  187. else:
  188. self.dao = TestataCommessa().getRecord(id=dao.id)
  189. self._refresh()
  190. return self.dao
  191. def _refresh(self):
  192. """ Funzione che ricarica i dati in gui"""
  193. self.data_inizio_commessa_entry.set_text(dateToString(self.dao.data_inizio))
  194. self.data_fine_commessa_entry.set_text(dateToString(self.dao.data_fine))
  195. self.titolo_commessa_entry.set_text(self.dao.denominazione or "")
  196. bufferNote= self.commessa_testo.get_buffer()
  197. bufferNote.set_text(self.dao.note or "")
  198. self.commessa_testo.set_buffer(bufferNote)
  199. findComboboxRowFromId(self.stadio_commessa_combobox.combobox, self.dao.id_stadio_commessa)
  200. # findComboboxRowFromId(self.id_cliente_combobox, self.dao.id_cliente)
  201. self.id_cliente_combobox.setId(self.dao.id_cliente)
  202. self.id_articolo_combobox.setId(self.dao.id_articolo)
  203. # self.stadio_commessa_combobox.setId( self.dao.id_stadio_commessa)
  204. # findComboboxRowFromId(self.id_articolo_combobox, self.dao.id_articolo)
  205. model = self.riga_commessa_treeview.get_model()
  206. model.clear()
  207. for r in self.dao.righecommessa:
  208. if r.dao_class=="TestataDocumento":
  209. td = TestataDocumento().getRecord(id=r.id_dao)
  210. dc = td.operazione
  211. else:
  212. dc = r.dao_class
  213. model.append((r, str(len(model)+1),
  214. dateToString(r.data_registrazione),
  215. r.denominazione,
  216. dc,
  217. r.note,
  218. r.dao_class,
  219. str(r.id_dao)))
  220. def clear(self):
  221. self.data_ins_riga.set_text("")
  222. bufferNoteRiga= self.riga_testo.get_buffer()
  223. bufferNoteRiga.set_text("")
  224. self.riga_testo.set_buffer(bufferNoteRiga)
  225. self.info_dao_label.set_text("-")
  226. self.titolo_riga_commessa_entry.set_text("")
  227. self.tipo_combobox.set_active(0)
  228. self.composeInfoDaoLabel(None)
  229. def on_delete_row_button_clicked(self, button):
  230. """ Elimina la riga commessa selezionata"""
  231. rpn = None
  232. if self.editRiga:
  233. dao = RigaCommessa().getRecord(id=self.editRiga.id)
  234. if dao:
  235. dao.delete()
  236. self._editModel.remove(self._editIterator)
  237. self.clear()
  238. def on_add_row_button_clicked(self, button):
  239. """ Aggiunge la riga """
  240. titolo_riga = self.titolo_riga_commessa_entry.get_text()
  241. if not titolo_riga:
  242. titolo_riga = self.info_dao_label.get_text()
  243. bufferNoteRiga= self.riga_testo.get_buffer()
  244. note_riga = bufferNoteRiga.get_text(bufferNoteRiga.get_start_iter(), bufferNoteRiga.get_end_iter(),True) or ""
  245. if self.dao_temp:
  246. self.dao_id = self.dao_temp.id
  247. self.dao_class = self.dao_temp.__class__.__name__
  248. if titolo_riga =="" or titolo_riga =="-":
  249. obligatoryField(self.dialogTopLevel, self.titolo_riga_commessa_entry,
  250. msg="Campo obbligatorio: TITOLO RIGA!")
  251. data_ins_riga = dateToString(self.data_ins_riga.get_text())
  252. model = self.riga_commessa_treeview.get_model()
  253. if self.editRiga:
  254. riga = self.editRiga
  255. riga.numero = self.editRiga.numero
  256. else:
  257. riga = RigaCommessa()
  258. riga.numero = len(model)+1
  259. riga.dao_class = self.dao_class
  260. riga.id_dao = self.dao_id
  261. riga.data_registrazione = stringToDate(data_ins_riga)
  262. riga.denominazione = titolo_riga
  263. riga.note = note_riga
  264. if self.dao_class =="TestataDocumento":
  265. dc = self.dao_temp.operazione
  266. else:
  267. dc = self.dao_class
  268. dati = (riga,str(len(model)+1),data_ins_riga,
  269. titolo_riga,
  270. str(dc),
  271. note_riga,
  272. self.dao_class,
  273. str(self.dao_id))
  274. if self.editRiga:
  275. if riga.dao_class=="TestataDocumento":
  276. td = TestataDocumento().getRecord(id=riga.id_dao)
  277. dc = td.operazione
  278. else:
  279. dc = riga.dao_class
  280. self.rigaIter[0] = riga
  281. self.rigaIter[1] = str(riga.numero)
  282. self.rigaIter[2] = dateToString(riga.data_registrazione)
  283. self.rigaIter[3] = riga.denominazione[0:100]
  284. self.rigaIter[4] = dc
  285. self.rigaIter[5] = riga.note
  286. self.rigaIter[6] = riga.dao_class
  287. self.rigaIter[7] = riga.id_dao
  288. else:
  289. model.append(dati)
  290. self.riga_commessa_treeview.set_model(model)
  291. self.editRiga = None
  292. self.clear()
  293. def daoRetreive(self,daoId, daoName):
  294. """Funzione che restituisce un dao, dato una classe come stringa, ed un id
  295. """
  296. if daoName:
  297. return getattr(sys.modules[__name__], daoName)().getRecord(id=daoId)
  298. else:
  299. return None
  300. def on_rimuovi_button_clicked(self, button):
  301. """ Elimina la riga di prima nota selezionata
  302. """
  303. if self.editRiga:
  304. dao = RigaCommessa().getRecord(id=self.editRiga.id)
  305. dao.delete()
  306. self._editModel.remove(self._editIterator)
  307. self.clear()
  308. def on_riga_commessa_treeview_row_activated(self,treeview, path, column):
  309. """Selezione della riga nella treeview
  310. """
  311. self.composeInfoDaoLabel(None)
  312. self.dao_temp = None
  313. sel = self.riga_commessa_treeview.get_selection()
  314. (model, iterator) = sel.get_selected()
  315. self.rigaIter = model[iterator]
  316. self._editIterator = iterator
  317. self._editModel = model
  318. self.data_ins_riga.set_text(self.rigaIter[2] or "")
  319. self.titolo_riga_commessa_entry.set_text(self.rigaIter[3] or "")
  320. bufferNoteRiga= self.riga_testo.get_buffer()
  321. bufferNoteRiga.set_text(self.rigaIter[5] or "")
  322. self.riga_testo.set_buffer(bufferNoteRiga)
  323. self.dao_id = self.rigaIter[7]
  324. self.dao_class = self.rigaIter[6]
  325. self.dao_temp = self.daoRetreive(self.dao_id, self.dao_class)
  326. self.composeInfoDaoLabel(self.dao_temp)
  327. model = self.tipo_combobox.get_model()
  328. for r in model:
  329. if self.tipiDict[r[0]] == self.dao_class:
  330. self.tipo_combobox.set_active_iter(r.iter)
  331. self.editRiga = self.rigaIter[0]
  332. def saveDao(self, chiusura=False, tipo=None):
  333. """ Salvataggio della commessa nel tabase
  334. """
  335. model = self.riga_commessa_treeview.get_model()
  336. righe_ = []
  337. for m in model:
  338. righe_.append(m[0])
  339. self.dao.data_inizio = stringToDate(self.data_inizio_commessa_entry.get_text())
  340. if (self.dao.data_inizio == ''or self.dao.data_inizio==None):
  341. obligatoryField(self.dialogTopLevel,
  342. self.data_inizio_commessa_entry,
  343. 'Inserire la data della commessa !')
  344. self.dao.data_fine = stringToDate(self.data_fine_commessa_entry.get_text())
  345. self.dao.denominazione = self.titolo_commessa_entry.get_text()
  346. if self.dao.denominazione =="":
  347. obligatoryField(self.dialogTopLevel, self.titolo_commessa_entry,
  348. msg="Campo obbligatorio: TITOLO COMMESSA!")
  349. bufferNoteRiga= self.commessa_testo.get_buffer()
  350. self.dao.note = bufferNoteRiga.get_text(bufferNoteRiga.get_start_iter(), bufferNoteRiga.get_end_iter(),True) or ""
  351. self.dao.righecommessa = righe_
  352. self.dao.id_stadio_commessa = findIdFromCombobox(self.stadio_commessa_combobox.combobox)
  353. self.dao.id_cliente = findIdFromCombobox(self.id_cliente_combobox)
  354. self.dao.id_articolo =findIdFromCombobox(self.id_articolo_combobox)
  355. if self.dao.id_cliente == None:
  356. obligatoryField(self.dialogTopLevel, self.id_cliente_combobox,
  357. msg="Campo obbligatorio: CLIENTE!")
  358. self.dao.persist()
  359. self.clear()
  360. def showAnagrafica(window, anag, button=None, mainClass=None):
  361. anagWindow = anag.getTopLevel()
  362. # anagWindow.connect("destroy", on_anagrafica_destroyed, [window, button,mainClass])
  363. #anagWindow.connect("hide", on_anagrafica_destroyed, [window, button,mainClass])
  364. # anagWindow.set_transient_for(window)
  365. # setattr(anagWindow, "mainClass",mainClass)
  366. anagWindow.show_all()