| 1 | # -*- coding: utf-8 -*- |
|---|
| 2 | |
|---|
| 3 | # Promogest |
|---|
| 4 | # |
|---|
| 5 | # Copyright (C) 2005 by Promotux Informatica - http://www.promotux.it/ |
|---|
| 6 | # Author: Andrea Argiolas <andrea@promotux.it> |
|---|
| 7 | |
|---|
| 8 | from Dao import Dao |
|---|
| 9 | |
|---|
| 10 | from sqlalchemy import * |
|---|
| 11 | from sqlalchemy.orm import * |
|---|
| 12 | from ScontoTestataDocumento import ScontoTestataDocumento |
|---|
| 13 | from DestinazioneMerce import DestinazioneMerce |
|---|
| 14 | from TestataMovimento import TestataMovimento |
|---|
| 15 | from Pagamento import Pagamento |
|---|
| 16 | from Vettore import Vettore |
|---|
| 17 | from promogest.modules.Agenti.dao.Agente import Agente |
|---|
| 18 | from Fornitore import Fornitore |
|---|
| 19 | from Cliente import Cliente |
|---|
| 20 | from RigaDocumento import RigaDocumento |
|---|
| 21 | from RigaDocumento import * |
|---|
| 22 | from AliquotaIva import AliquotaIva |
|---|
| 23 | from RigaMovimento import RigaMovimento |
|---|
| 24 | from Banca import Banca |
|---|
| 25 | from Riga import Riga |
|---|
| 26 | from Articolo import Articolo |
|---|
| 27 | from ScontoRigaMovimento import ScontoRigaMovimento |
|---|
| 28 | from TestataDocumentoScadenza import TestataDocumentoScadenza |
|---|
| 29 | |
|---|
| 30 | #from DaoUtils import * |
|---|
| 31 | from decimal import * |
|---|
| 32 | from promogest.ui.utils import * |
|---|
| 33 | from promogest.ui.utilsCombobox import * |
|---|
| 34 | |
|---|
| 35 | from promogest.Environment import * |
|---|
| 36 | from promogest import Environment |
|---|
| 37 | |
|---|
| 38 | class TestataDocumento(Dao): |
|---|
| 39 | |
|---|
| 40 | def __init__(self, arg=None): |
|---|
| 41 | Dao.__init__(self, entity=self) |
|---|
| 42 | |
|---|
| 43 | self.__righeDocumento = None |
|---|
| 44 | self.__operazione = None |
|---|
| 45 | self.__dbScadenzeDocumento = [] |
|---|
| 46 | self.__ScadenzeDocumento = [] |
|---|
| 47 | self.__dbScontiTestataDocumento = [] |
|---|
| 48 | self.__scontiTestataDocumento = [] |
|---|
| 49 | self.__dbRigheDocumentoPart = [] |
|---|
| 50 | self.__dbRigheMovimentoPart = [] |
|---|
| 51 | self.__righeDocumento = [] |
|---|
| 52 | self._totaleImponibile = 0 |
|---|
| 53 | self._totaleNonScontato = 0 |
|---|
| 54 | self._totaleScontato = 0 |
|---|
| 55 | self._totaleImponibile = 0 |
|---|
| 56 | self._totaleImponibileScontato = 0 |
|---|
| 57 | self._totaleImposta = 0 |
|---|
| 58 | self._totaleImpostaScontata = 0 |
|---|
| 59 | self._totaleScontato = 0 |
|---|
| 60 | self._castellettoIva = 0 |
|---|
| 61 | self.__data_inizio_noleggio = None |
|---|
| 62 | self.__data_fine_noleggio = None |
|---|
| 63 | self.__numeroMagazzini = 0 |
|---|
| 64 | |
|---|
| 65 | @reconstructor |
|---|
| 66 | def init_on_load(self): |
|---|
| 67 | self.__dbScadenzeDocumento = [] |
|---|
| 68 | self.__dbScontiTestataDocumento = [] |
|---|
| 69 | self.__dbRigheDocumentoPart = [] |
|---|
| 70 | self.__dbRigheMovimentoPart = [] |
|---|
| 71 | self.__righeDocumento = [] |
|---|
| 72 | self.__ScadenzeDocumento = [] |
|---|
| 73 | self.__scontiTestataDocumento = [] |
|---|
| 74 | self.__data_inizio_noleggio = None |
|---|
| 75 | self.__data_fine_noleggio = None |
|---|
| 76 | |
|---|
| 77 | def _getScadenzeDocumento(self): |
|---|
| 78 | if self.id: |
|---|
| 79 | self.__dbScadenzeDocumento = params['session']\ |
|---|
| 80 | .query(TestataDocumentoScadenza)\ |
|---|
| 81 | .with_parent(self)\ |
|---|
| 82 | .filter_by(id_testata_documento=self.id)\ |
|---|
| 83 | .all() |
|---|
| 84 | self.__ScadenzeDocumento = self.__dbScadenzeDocumento[:] |
|---|
| 85 | return self.__ScadenzeDocumento |
|---|
| 86 | |
|---|
| 87 | def _setScadenzeDocumento(self, value): |
|---|
| 88 | self.__ScadenzeDocumento = value |
|---|
| 89 | |
|---|
| 90 | #if Environment.conf.hasPagamenti == True: |
|---|
| 91 | scadenze = property(_getScadenzeDocumento, _setScadenzeDocumento) |
|---|
| 92 | |
|---|
| 93 | def sort_by_attr(self,seq,attr): |
|---|
| 94 | intermed = [ (getattr(seq[i],attr), i, seq[i]) for i in xrange(len(seq)) ] |
|---|
| 95 | intermed.sort() |
|---|
| 96 | return [ tup[-1] for tup in intermed ] |
|---|
| 97 | |
|---|
| 98 | def _getRigheDocumento(self): |
|---|
| 99 | if self.id: |
|---|
| 100 | self.__dbRigheDocumentoPart = params['session']\ |
|---|
| 101 | .query(RigaDocumento )\ |
|---|
| 102 | .filter(RigaDocumento.id_testata_documento == self.id).all() |
|---|
| 103 | try: |
|---|
| 104 | self.__dbRigheMovimentoPart = params['session']\ |
|---|
| 105 | .query(RigaMovimento)\ |
|---|
| 106 | .join(RigaMovimento.testata_movimento)\ |
|---|
| 107 | .filter(RigaMovimento.id_testata_movimento==select([TestataMovimento.id], \ |
|---|
| 108 | TestataMovimento.id_testata_documento==self.id)).all() |
|---|
| 109 | except: |
|---|
| 110 | self.rollback() |
|---|
| 111 | test = TestataMovimento().select(idTestataDocumento = self.id) |
|---|
| 112 | if len(test) >1: |
|---|
| 113 | Environment.pg2log.debug("ATTENZIONEEEEEEEEE due movimenti fanno riferimento ad una sola testata documento:"+str(self.id)) |
|---|
| 114 | for t in test: |
|---|
| 115 | Environment.pg2log.debug("DATI MOVIMENTO ERRATI id:"+str(t.id)) |
|---|
| 116 | messageInfo(msg="""ATTENZIONE, Più di un movimento fa riferimento |
|---|
| 117 | allo stesso documento. |
|---|
| 118 | Contattare l'assistenza con urgenza""") |
|---|
| 119 | self.__dbRigheDocumento = self.__dbRigheDocumentoPart + self.__dbRigheMovimentoPart |
|---|
| 120 | self.__dbRigheDocumento = self.sort_by_attr(self.__dbRigheDocumento,"id") |
|---|
| 121 | self.__righeDocumento = self.__dbRigheDocumento[:] |
|---|
| 122 | else: |
|---|
| 123 | self.__righeDocumento = [] |
|---|
| 124 | return self.__righeDocumento |
|---|
| 125 | |
|---|
| 126 | def _setRigheDocumento(self, value): |
|---|
| 127 | self.__righeDocumento =value |
|---|
| 128 | |
|---|
| 129 | righe = property(_getRigheDocumento, _setRigheDocumento) |
|---|
| 130 | |
|---|
| 131 | def _getDocumentTotalConfections(self): |
|---|
| 132 | """ |
|---|
| 133 | Ritorna il numero totale delle confezioni inserite nelle righe del documento: |
|---|
| 134 | quantità Totale = sommatoria(i=1 to n)[quantità (riga i) * moltiplicatore(riga i)] |
|---|
| 135 | """ |
|---|
| 136 | __quantitaTotale = 0 |
|---|
| 137 | if len(self.righe) > 0: |
|---|
| 138 | for r in self.righe: |
|---|
| 139 | __quantitaTotale += float(r.quantita*r.moltiplicatore) |
|---|
| 140 | return __quantitaTotale |
|---|
| 141 | |
|---|
| 142 | totalConfections = property(_getDocumentTotalConfections) |
|---|
| 143 | |
|---|
| 144 | def _getNumeroMagazzini(self): |
|---|
| 145 | """ |
|---|
| 146 | Restituisce il numero di magazzini presenti nel documento. Ci serve per poter effettuare |
|---|
| 147 | il trasferimento di articoli che partono tutti dallo stesso magazzino |
|---|
| 148 | """ |
|---|
| 149 | __numeroMagazzini = [] |
|---|
| 150 | for riga in self.righe: |
|---|
| 151 | if riga.id_magazzino not in __numeroMagazzini: |
|---|
| 152 | __numeroMagazzini.append(riga.id_magazzino) |
|---|
| 153 | return len(__numeroMagazzini) |
|---|
| 154 | |
|---|
| 155 | #__numeroMagazzini = 0 |
|---|
| 156 | |
|---|
| 157 | #if len(self.righe) > 0 and self.id: |
|---|
| 158 | #mov_query = params['session'].query(RigaMovimento.id).filter(RigaMovimento.id_testata_movimento == self.id) |
|---|
| 159 | #doc_query = params['session'].query(RigaDocumento.id).filter(RigaDocumento.id_testata_documento == self.id) |
|---|
| 160 | #res = params['session'].query(Riga.id_magazzino).filter(or_(Riga.id.in_(mov_query),Riga.id.in_(doc_query))).distinct().count() |
|---|
| 161 | #__numeroMagazzini = res |
|---|
| 162 | #return __numeroMagazzini |
|---|
| 163 | |
|---|
| 164 | numeroMagazzini = property(_getNumeroMagazzini) |
|---|
| 165 | |
|---|
| 166 | def _getScontiTestataDocumento(self): |
|---|
| 167 | if not self.__scontiTestataDocumento and self.id: |
|---|
| 168 | self.__dbScontiTestataDocumento = ScontoTestataDocumento().select(join = ScontoTestataDocumento.TD, |
|---|
| 169 | idScontoTestataDocumento=self.id, |
|---|
| 170 | batchSize=None) |
|---|
| 171 | self.__scontiTestataDocumento = self.__dbScontiTestataDocumento |
|---|
| 172 | return self.__scontiTestataDocumento |
|---|
| 173 | |
|---|
| 174 | def _setScontiTestataDocumento(self, value): |
|---|
| 175 | self.__scontiTestataDocumento = value |
|---|
| 176 | |
|---|
| 177 | sconti = property(_getScontiTestataDocumento, _setScontiTestataDocumento) |
|---|
| 178 | |
|---|
| 179 | def _getStringaScontiTestataDocumento(self): |
|---|
| 180 | (listSconti, applicazione) = getScontiFromDao(self._getScontiTestataDocumento(), self.applicazione_sconti) |
|---|
| 181 | return getStringaSconti(listSconti) |
|---|
| 182 | stringaSconti = property(_getStringaScontiTestataDocumento) |
|---|
| 183 | |
|---|
| 184 | |
|---|
| 185 | def _getIntestatario(self): |
|---|
| 186 | """ |
|---|
| 187 | Restituisce la ragione sociale o cognome + nome |
|---|
| 188 | se la ragione sociale e' vuota |
|---|
| 189 | """ |
|---|
| 190 | intestatario = '' |
|---|
| 191 | |
|---|
| 192 | if self.id_cliente is not None: |
|---|
| 193 | if (hasattr(self, 'ragione_sociale_cliente') and |
|---|
| 194 | hasattr(self, 'cognome_cliente') and |
|---|
| 195 | hasattr(self, 'nome_cliente')): |
|---|
| 196 | intestatario = self.ragione_sociale_cliente |
|---|
| 197 | if intestatario == '': |
|---|
| 198 | intestatario = self.cognome_cliente + ' ' + self.nome_cliente |
|---|
| 199 | return intestatario |
|---|
| 200 | else: |
|---|
| 201 | cliente = leggiCliente(self.id_cliente) |
|---|
| 202 | intestatario = cliente['ragioneSociale'] |
|---|
| 203 | if intestatario == '': |
|---|
| 204 | intestatario = cliente['cognome'] + ' ' + cliente['nome'] |
|---|
| 205 | return intestatario |
|---|
| 206 | elif self.id_fornitore is not None: |
|---|
| 207 | if (hasattr(self, 'ragione_sociale_fornitore') and |
|---|
| 208 | hasattr(self, 'cognome_fornitore') and |
|---|
| 209 | hasattr(self, 'nome_fornitore')): |
|---|
| 210 | intestatario = self.ragione_sociale_fornitore |
|---|
| 211 | if intestatario == '': |
|---|
| 212 | intestatario = self.cognome_fornitore + ' ' + self.nome_fornitore |
|---|
| 213 | return intestatario |
|---|
| 214 | else: |
|---|
| 215 | fornitore = leggiFornitore(self.id_fornitore) |
|---|
| 216 | intestatario = fornitore['ragioneSociale'] |
|---|
| 217 | if intestatario == '': |
|---|
| 218 | intestatario = fornitore['cognome'] + ' ' + fornitore['nome'] |
|---|
| 219 | return intestatario |
|---|
| 220 | else: |
|---|
| 221 | return '' |
|---|
| 222 | |
|---|
| 223 | intestatario = property(_getIntestatario, ) |
|---|
| 224 | |
|---|
| 225 | |
|---|
| 226 | def _getTotaliDocumento(self): |
|---|
| 227 | self.__operazione = leggiOperazione(self.operazione) |
|---|
| 228 | fonteValore = self.__operazione["fonteValore"] |
|---|
| 229 | |
|---|
| 230 | # FIXME: duplicated in AnagraficaDocumenti.py |
|---|
| 231 | totaleImponibile = Decimal(0) |
|---|
| 232 | totaleImposta = Decimal(0) |
|---|
| 233 | totaleNonScontato = Decimal(0) |
|---|
| 234 | totaleImpostaScontata = Decimal(0) |
|---|
| 235 | totaleImponibileScontato = Decimal(0) |
|---|
| 236 | totaleScontato = Decimal(0) |
|---|
| 237 | castellettoIva = {} |
|---|
| 238 | righeDocumento = self.righe |
|---|
| 239 | for riga in righeDocumento: |
|---|
| 240 | |
|---|
| 241 | # FIXME: added for supporting dumb rows when printing |
|---|
| 242 | if riga is None: |
|---|
| 243 | continue |
|---|
| 244 | #print "VALORIIIIIIIIIIIIIIIII", riga.quantita, riga.moltiplicatore, riga.valore_unitario_netto |
|---|
| 245 | if not riga.moltiplicatore: |
|---|
| 246 | riga.moltiplicatore = 1 |
|---|
| 247 | totaleRiga = Decimal(str(riga.quantita)) * Decimal(str(riga.moltiplicatore)) * mN(str(riga.valore_unitario_netto)) |
|---|
| 248 | percentualeIvaRiga = Decimal(str(riga.percentuale_iva)) |
|---|
| 249 | if percentualeIvaRiga != Environment.percentualeIvaRiga: |
|---|
| 250 | aliquotaIvaRiga = riga.aliquota |
|---|
| 251 | Environment.percentualeIvaRiga = percentualeIvaRiga |
|---|
| 252 | Environment.aliquotaIvaRiga = aliquotaIvaRiga |
|---|
| 253 | else: |
|---|
| 254 | aliquotaIvaRiga = Environment.aliquotaIvaRiga |
|---|
| 255 | #aliquotaIvaRiga = righeDocumento[i].aliquota |
|---|
| 256 | |
|---|
| 257 | |
|---|
| 258 | if (fonteValore == "vendita_iva" or fonteValore == "acquisto_iva"): |
|---|
| 259 | totaleImponibileRiga = calcolaPrezzoIva(totaleRiga, -1 * percentualeIvaRiga) |
|---|
| 260 | else: |
|---|
| 261 | totaleImponibileRiga = mN(totaleRiga,2) |
|---|
| 262 | totaleRiga = calcolaPrezzoIva(totaleRiga, percentualeIvaRiga) |
|---|
| 263 | |
|---|
| 264 | totaleImpostaRiga = mN(totaleRiga,2) - totaleImponibileRiga |
|---|
| 265 | totaleNonScontato += totaleRiga |
|---|
| 266 | totaleImponibile += totaleImponibileRiga |
|---|
| 267 | totaleImposta += totaleImpostaRiga |
|---|
| 268 | |
|---|
| 269 | if aliquotaIvaRiga not in castellettoIva.keys(): |
|---|
| 270 | castellettoIva[aliquotaIvaRiga] = {'percentuale': percentualeIvaRiga, |
|---|
| 271 | 'imponibile': totaleImponibileRiga, |
|---|
| 272 | 'imposta': totaleImpostaRiga, |
|---|
| 273 | 'totale': totaleRiga} |
|---|
| 274 | else: |
|---|
| 275 | castellettoIva[aliquotaIvaRiga]['percentuale'] = percentualeIvaRiga |
|---|
| 276 | castellettoIva[aliquotaIvaRiga]['imponibile'] += totaleImponibileRiga |
|---|
| 277 | castellettoIva[aliquotaIvaRiga]['imposta'] += totaleImpostaRiga |
|---|
| 278 | castellettoIva[aliquotaIvaRiga]['totale'] += totaleRiga |
|---|
| 279 | |
|---|
| 280 | totaleNonScontato = mN(totaleNonScontato, 2) |
|---|
| 281 | totaleImponibile = mN(totaleImponibile, 2) |
|---|
| 282 | totaleImposta = totaleNonScontato - totaleImponibile |
|---|
| 283 | for aliquotaIva in castellettoIva: |
|---|
| 284 | castellettoIva[aliquotaIva]['imponibile'] = mN(castellettoIva[aliquotaIva]['imponibile'], 2) |
|---|
| 285 | castellettoIva[aliquotaIva]['imposta'] = mN(castellettoIva[aliquotaIva]['imposta'], 2) |
|---|
| 286 | castellettoIva[aliquotaIva]['totale'] = mN(castellettoIva[aliquotaIva]['totale'], 2) |
|---|
| 287 | |
|---|
| 288 | totaleImpostaScontata = totaleImposta |
|---|
| 289 | totaleImponibileScontato = totaleImponibile |
|---|
| 290 | totaleScontato = totaleNonScontato |
|---|
| 291 | scontiSuTotale = self.sconti |
|---|
| 292 | applicazioneSconti = self.applicazione_sconti |
|---|
| 293 | |
|---|
| 294 | if len(scontiSuTotale) > 0: |
|---|
| 295 | for s in scontiSuTotale: |
|---|
| 296 | if s.tipo_sconto == 'percentuale': |
|---|
| 297 | if applicazioneSconti == 'scalare': |
|---|
| 298 | totaleScontato = mN(totaleScontato) * (1 - mN(s.valore) / 100) |
|---|
| 299 | elif applicazioneSconti == 'non scalare': |
|---|
| 300 | totaleScontato = mN(totaleScontato) - mN(totaleNonScontato) * mN(s.valore) / 100 |
|---|
| 301 | else: |
|---|
| 302 | raise Exception, ('BUG! Tipo di applicazione sconto ' |
|---|
| 303 | 'sconosciuto: %s' % s.tipo_sconto) |
|---|
| 304 | elif s.tipo_sconto == 'valore': |
|---|
| 305 | totaleScontato = mN(totaleScontato) - mN(s.valore) |
|---|
| 306 | |
|---|
| 307 | # riporta l'insieme di sconti ad una percentuale globale |
|---|
| 308 | if totaleNonScontato == 0: |
|---|
| 309 | totaleNonScontato = 1 |
|---|
| 310 | percentualeScontoGlobale = (1 - totaleScontato / totaleNonScontato) * 100 |
|---|
| 311 | totaleImpostaScontata = 0 |
|---|
| 312 | totaleImponibileScontato = 0 |
|---|
| 313 | totaleScontato = 0 |
|---|
| 314 | # riproporzione del totale, dell'imponibile e dell'imposta |
|---|
| 315 | for k in castellettoIva.keys(): |
|---|
| 316 | castellettoIva[k]['totale'] = mN(castellettoIva[k]['totale'] * (1 - mN(percentualeScontoGlobale) / 100), 2) |
|---|
| 317 | castellettoIva[k]['imponibile'] = mN(castellettoIva[k]['imponibile'] * (1 - mN(percentualeScontoGlobale) / 100),2) |
|---|
| 318 | castellettoIva[k]['imposta'] = castellettoIva[k]['totale'] - castellettoIva[k]['imponibile'] |
|---|
| 319 | |
|---|
| 320 | totaleImponibileScontato += castellettoIva[k]['imponibile'] |
|---|
| 321 | totaleImpostaScontata += castellettoIva[k]['imposta'] |
|---|
| 322 | |
|---|
| 323 | totaleScontato = mN(totaleImponibileScontato) + mN(totaleImpostaScontata) |
|---|
| 324 | |
|---|
| 325 | self._totaleNonScontato = mN(totaleNonScontato,2) |
|---|
| 326 | self._totaleScontato = mN(totaleScontato,2) |
|---|
| 327 | self._totaleImponibile = mN(totaleImponibile,2) |
|---|
| 328 | self._totaleImposta = mN(totaleImposta,2) |
|---|
| 329 | self._totaleImponibileScontato = mN(totaleImponibileScontato,2) |
|---|
| 330 | self._totaleImpostaScontata = mN(totaleImpostaScontata,2) |
|---|
| 331 | self._castellettoIva = [] |
|---|
| 332 | for k in castellettoIva.keys(): |
|---|
| 333 | dictCastellettoIva = castellettoIva[k] |
|---|
| 334 | dictCastellettoIva['aliquota'] = k |
|---|
| 335 | self._castellettoIva.append(dictCastellettoIva) |
|---|
| 336 | |
|---|
| 337 | return None |
|---|
| 338 | |
|---|
| 339 | totali = property(_getTotaliDocumento, ) |
|---|
| 340 | |
|---|
| 341 | def contieneMovimentazione(self, righe=None): |
|---|
| 342 | """ |
|---|
| 343 | Verifica se sono e devono essere presenti righe di movimentazione magazzino |
|---|
| 344 | dicesi riga di movimentazione se Ú legata ad una operazione che ha un segno |
|---|
| 345 | sia esso positivo o negativo e deve avere anche un id_articolo abbinato |
|---|
| 346 | """ |
|---|
| 347 | righeMovimentazione = False |
|---|
| 348 | operazione = leggiOperazione(self.operazione) |
|---|
| 349 | if operazione["segno"] != '': |
|---|
| 350 | if righe is not None: |
|---|
| 351 | for riga in righe: |
|---|
| 352 | if riga.id_articolo is not None: |
|---|
| 353 | righeMovimentazione = True |
|---|
| 354 | break |
|---|
| 355 | return righeMovimentazione |
|---|
| 356 | |
|---|
| 357 | |
|---|
| 358 | #Salvataggi subordinati alla testata Documento, iniziamo da righe documento e poi righe |
|---|
| 359 | def persist(self): |
|---|
| 360 | DaoTestataMovimento = None |
|---|
| 361 | params["session"].add(self) |
|---|
| 362 | params["session"].commit() |
|---|
| 363 | |
|---|
| 364 | Environment.pg2log.debug("INIZIO SALVATAGGIO DOCUMENTO") |
|---|
| 365 | self.scontiTestataDocumentoDel(id=self.id) |
|---|
| 366 | |
|---|
| 367 | self.testataDocumentoScadenzaDel(id=self.id) |
|---|
| 368 | self.righeDocumentoDel(id=self.id) |
|---|
| 369 | #verifica se sono presenti righe di movimentazione magazzino |
|---|
| 370 | contieneMovimentazione = self.contieneMovimentazione(righe=self.righeDocumento) |
|---|
| 371 | #cerco le testate movimento associate al documento |
|---|
| 372 | #FIXME: se ne trovo piu' di una ? (ad esempio se il documento e' in realta' un cappello) |
|---|
| 373 | res = TestataMovimento().select(idTestataDocumento = self.id,batchSize=None) |
|---|
| 374 | #Tutto nuovo non ci sono teste movimento relate a questa testata documento |
|---|
| 375 | if not res: |
|---|
| 376 | #se però c'Ú movimentazione vuol dire che ha un movimento abbinato |
|---|
| 377 | if contieneMovimentazione: |
|---|
| 378 | #creo una nuova testata movimento |
|---|
| 379 | DaoTestataMovimento = TestataMovimento() |
|---|
| 380 | DaoTestataMovimento.data_movimento = self.data_documento |
|---|
| 381 | if not DaoTestataMovimento.numero: |
|---|
| 382 | valori = numeroRegistroGet(tipo="Movimento", date=self.data_documento) |
|---|
| 383 | DaoTestataMovimento.numero = valori[0] |
|---|
| 384 | DaoTestataMovimento.registro_numerazione= valori[1] |
|---|
| 385 | DaoTestataMovimento.operazione = self.operazione |
|---|
| 386 | DaoTestataMovimento.id_cliente = self.id_cliente |
|---|
| 387 | DaoTestataMovimento.id_fornitore = self.id_fornitore |
|---|
| 388 | DaoTestataMovimento.note_interne = self.note_interne |
|---|
| 389 | DaoTestataMovimento.note_interne = self.note_interne |
|---|
| 390 | DaoTestataMovimento.id_testata_documento = self.id # abbino la testata alla testata movimento |
|---|
| 391 | elif len(res) == 1: |
|---|
| 392 | #print "RES Ã UGUALE AD UNO.... ESITE UN MOVIMENTO USO RES" |
|---|
| 393 | DaoTestataMovimento = res[0] #TestataMovimento().getRecord(id=res[0].id) |
|---|
| 394 | if not contieneMovimentazione: |
|---|
| 395 | #devo eliminare il movimento interamente, visto che non ci sono righe movimento |
|---|
| 396 | #self.righeMovimentoDel(id=DaoTestataMovimento.id) |
|---|
| 397 | DaoTestataMovimento.delete() |
|---|
| 398 | DaoTestataMovimento = None |
|---|
| 399 | else: |
|---|
| 400 | #la testata movimento e` gia` presente, quindi devo aggiornarla |
|---|
| 401 | DaoTestataMovimento.data_movimento = self.data_documento |
|---|
| 402 | DaoTestataMovimento.operazione = self.operazione |
|---|
| 403 | DaoTestataMovimento.id_cliente = self.id_cliente |
|---|
| 404 | DaoTestataMovimento.id_fornitore = self.id_fornitore |
|---|
| 405 | DaoTestataMovimento.note_interne = self.note_interne |
|---|
| 406 | DaoTestataMovimento.note_interne = self.note_interne |
|---|
| 407 | DaoTestataMovimento.id_testata_documento = self.id |
|---|
| 408 | #righeMovimentoDel(id=DaoTestataMovimento.id) |
|---|
| 409 | else: |
|---|
| 410 | # ci sono piu' movimenti collegati al documento |
|---|
| 411 | # FIXME: che fare ? |
|---|
| 412 | raise Exception, "ATTENZIONE CI SONO PIU' MOVIMENTI LEGATI AD UN DOCUMENTO" |
|---|
| 413 | #print "DOPO if di check di RES ", tempo() |
|---|
| 414 | righeMovimento = [] |
|---|
| 415 | righeDocumento = [] |
|---|
| 416 | scontiRigaMovimento = [] |
|---|
| 417 | if self.righeDocumento: #trattiamo le righe documento e movimento |
|---|
| 418 | #print "Prima del FOR delle RIGHE ", tempo() |
|---|
| 419 | for row in self.righeDocumento: |
|---|
| 420 | if (row.id_articolo is not None and contieneMovimentazione): |
|---|
| 421 | #salvo tra le righe movimenti |
|---|
| 422 | #print "RIGHE ",row.id_articolo, tempo() |
|---|
| 423 | daoRigaMovimento = RigaMovimento() |
|---|
| 424 | #daoRigaMovimento.id_testata_movimento = DaoTestataMovimento.id |
|---|
| 425 | daoRigaMovimento.valore_unitario_netto = row.valore_unitario_netto |
|---|
| 426 | daoRigaMovimento.valore_unitario_lordo = row.valore_unitario_lordo |
|---|
| 427 | daoRigaMovimento.quantita = row.quantita |
|---|
| 428 | daoRigaMovimento.moltiplicatore = row.moltiplicatore |
|---|
| 429 | daoRigaMovimento.applicazione_sconti = row.applicazione_sconti |
|---|
| 430 | daoRigaMovimento.percentuale_iva = row.percentuale_iva |
|---|
| 431 | daoRigaMovimento.descrizione = row.descrizione |
|---|
| 432 | daoRigaMovimento.id_listino = row.id_listino |
|---|
| 433 | daoRigaMovimento.id_magazzino = row.id_magazzino |
|---|
| 434 | daoRigaMovimento.id_articolo = row.id_articolo |
|---|
| 435 | daoRigaMovimento.id_multiplo = row.id_multiplo |
|---|
| 436 | daoRigaMovimento.codiceArticoloFornitore = row.codiceArticoloFornitore |
|---|
| 437 | if hasattr(conf, "GestioneNoleggio") and getattr(conf.GestioneNoleggio,'mod_enable')=="yes": |
|---|
| 438 | daoRigaMovimento.prezzo_acquisto_noleggio = row.prezzo_acquisto_noleggio |
|---|
| 439 | daoRigaMovimento.coeficente_noleggio = row.coeficente_noleggio |
|---|
| 440 | daoRigaMovimento.isrent = row.isrent |
|---|
| 441 | |
|---|
| 442 | scontiRigaMovimento = [] |
|---|
| 443 | if row.scontiRigaDocumento: |
|---|
| 444 | for v in row.scontiRigaDocumento: |
|---|
| 445 | daoScontoMovimento = ScontoRigaMovimento() |
|---|
| 446 | daoScontoMovimento.valore = v.valore |
|---|
| 447 | daoScontoMovimento.tipo_sconto = v.tipo_sconto |
|---|
| 448 | |
|---|
| 449 | scontiRigaMovimento.append(daoScontoMovimento) |
|---|
| 450 | if hasattr(conf, "SuMisura") and getattr(conf.SuMisura,'mod_enable')=="yes": |
|---|
| 451 | if row.misura_pezzo: |
|---|
| 452 | daoRigaMovimento.misura_pezzo = row.misura_pezzo |
|---|
| 453 | |
|---|
| 454 | daoRigaMovimento.scontiRigheMovimento = scontiRigaMovimento |
|---|
| 455 | righeMovimento.append(daoRigaMovimento) |
|---|
| 456 | #righeMovimento.scontiRigheMovimento = scontiRigaMovimento |
|---|
| 457 | else: |
|---|
| 458 | Environment.pg2log.debug("RIGA SENZA RIFERMENTO ARTICOLO QUINDI DESCRITTIVA, SALVO IN RIGADOCUMENTO") |
|---|
| 459 | #annullamento id della riga |
|---|
| 460 | #row._resetId() |
|---|
| 461 | #associazione alla riga della testata |
|---|
| 462 | row.id_testata_documento = self.id |
|---|
| 463 | righeMovimento.append(row) |
|---|
| 464 | |
|---|
| 465 | #print "DOPO IL FOR", tempo() |
|---|
| 466 | if (DaoTestataMovimento is not None): |
|---|
| 467 | if righeMovimento: |
|---|
| 468 | ##print "SE ARRIVI QUI DOVREBBE ANDARE TUTTO BENE" , righeMovimento |
|---|
| 469 | DaoTestataMovimento.righeMovimento=righeMovimento |
|---|
| 470 | DaoTestataMovimento.persist() |
|---|
| 471 | else: |
|---|
| 472 | for riga in righeMovimento: |
|---|
| 473 | riga.persist() |
|---|
| 474 | #print "DOPO IL PERSIST DI RIGA", tempo() |
|---|
| 475 | |
|---|
| 476 | if self.__ScadenzeDocumento: |
|---|
| 477 | for scad in self.__ScadenzeDocumento: |
|---|
| 478 | scad._resetId() |
|---|
| 479 | scad.id_testata_documento = self.id |
|---|
| 480 | scad.persist() |
|---|
| 481 | #print "DOPO SCADENZE", tempo() |
|---|
| 482 | |
|---|
| 483 | if self.__data_fine_noleggio and self.__data_inizio_noleggio: |
|---|
| 484 | tn = TestataGestioneNoleggio() |
|---|
| 485 | tn.id_testata_documento = self.id |
|---|
| 486 | tn.data_inizio_noleggio = self.data_inizio_noleggio |
|---|
| 487 | tn.data_fine_noleggio = self.data_fine_noleggio |
|---|
| 488 | tn.persist() |
|---|
| 489 | #print "DOPO FINE NOLEGGIO", tempo() |
|---|
| 490 | |
|---|
| 491 | if self.scontiSuTotale: |
|---|
| 492 | print "OLLELLEEEEEEEEEEEEEEOLLALLAAAAAAAAAAAA", self.scontiSuTotale |
|---|
| 493 | self.scontiTestataDocumentoDel(id=self.id) |
|---|
| 494 | for scontisutot in self.scontiSuTotale: |
|---|
| 495 | scontisutot.id_testata_documento = self.id |
|---|
| 496 | scontisutot.persist() |
|---|
| 497 | Environment.pg2log.debug("FINE SALVATAGGIO DOCUMENTO") |
|---|
| 498 | |
|---|
| 499 | |
|---|
| 500 | def righeDocumentoDel(self, id=None): |
|---|
| 501 | """ |
|---|
| 502 | Cancella le righe associate ad un documento |
|---|
| 503 | """ |
|---|
| 504 | row = RigaDocumento().select(idTestataDocumento= id, |
|---|
| 505 | offset = None, |
|---|
| 506 | batchSize = None) |
|---|
| 507 | if row: |
|---|
| 508 | for r in row: |
|---|
| 509 | if "SuMisura" in modulesList: |
|---|
| 510 | mp = MisuraPezzo().select(idRiga=r.id) |
|---|
| 511 | if mp: |
|---|
| 512 | for m in mp: |
|---|
| 513 | params['session'].delete(m) |
|---|
| 514 | params["session"].commit() |
|---|
| 515 | params['session'].delete(r) |
|---|
| 516 | params["session"].commit() |
|---|
| 517 | return True |
|---|
| 518 | |
|---|
| 519 | |
|---|
| 520 | |
|---|
| 521 | def scontiTestataDocumentoDel(self,id=None): |
|---|
| 522 | """ |
|---|
| 523 | Cancella gli sconti associati ad un documento |
|---|
| 524 | """ |
|---|
| 525 | row = ScontoTestataDocumento().select(idScontoTestataDocumento= id, |
|---|
| 526 | offset = None, |
|---|
| 527 | batchSize = None, |
|---|
| 528 | orderBy="id_testata_documento") |
|---|
| 529 | if row: |
|---|
| 530 | for r in row: |
|---|
| 531 | params['session'].delete(r) |
|---|
| 532 | params["session"].commit() |
|---|
| 533 | return True |
|---|
| 534 | |
|---|
| 535 | |
|---|
| 536 | def testataDocumentoScadenzaDel(self,id=None): |
|---|
| 537 | """ |
|---|
| 538 | Cancella la scadenza documento associato ad un documento |
|---|
| 539 | """ |
|---|
| 540 | row = TestataDocumentoScadenza().select(idTestataDocumentoScadenza= id, |
|---|
| 541 | offset = None, |
|---|
| 542 | batchSize = None, |
|---|
| 543 | orderBy="id_testata_documento") |
|---|
| 544 | for r in row: |
|---|
| 545 | params['session'].delete(r) |
|---|
| 546 | params["session"].commit() |
|---|
| 547 | return True |
|---|
| 548 | |
|---|
| 549 | def scontiRigaDocumentoDel(self,id=None): |
|---|
| 550 | """ |
|---|
| 551 | Cancella gli sconti legati ad una riga movimento |
|---|
| 552 | """ |
|---|
| 553 | row = ScontoRigaDocumento().select(idRigaDocumento= id, |
|---|
| 554 | offset = None, |
|---|
| 555 | batchSize = None) |
|---|
| 556 | if row: |
|---|
| 557 | for r in row: |
|---|
| 558 | params['session'].delete(r) |
|---|
| 559 | params["session"].commit() |
|---|
| 560 | return True |
|---|
| 561 | |
|---|
| 562 | |
|---|
| 563 | |
|---|
| 564 | def _al(self): |
|---|
| 565 | if self.AL: return self.AL.denominazione |
|---|
| 566 | else: return "" |
|---|
| 567 | aliquota_iva_esenzione = property(_al) |
|---|
| 568 | |
|---|
| 569 | |
|---|
| 570 | #property vettore |
|---|
| 571 | def _rag_soc_vett(self): |
|---|
| 572 | if self.PV: return self.PV.ragione_sociale |
|---|
| 573 | else: return "" |
|---|
| 574 | ragione_sociale_vettore = property(_rag_soc_vett) |
|---|
| 575 | |
|---|
| 576 | |
|---|
| 577 | #property destinazione_merce |
|---|
| 578 | def _destMerc(self): |
|---|
| 579 | if self.DM: dm = self.DM.denominazione |
|---|
| 580 | else: return "" |
|---|
| 581 | destinazione_merce = property(_destMerc) |
|---|
| 582 | |
|---|
| 583 | def _destMercInd(self): |
|---|
| 584 | if self.DM: return self.DM.indirizzo |
|---|
| 585 | else: return "" |
|---|
| 586 | indirizzo_destinazione_merce = property(_destMercInd) |
|---|
| 587 | |
|---|
| 588 | def _destMercloca(self): |
|---|
| 589 | if self.DM: return self.DM.localita |
|---|
| 590 | else: return "" |
|---|
| 591 | localita_destinazione_merce = property(_destMercloca) |
|---|
| 592 | |
|---|
| 593 | def _destMerccap(self): |
|---|
| 594 | if self.DM: return self.DM.cap |
|---|
| 595 | else: return "" |
|---|
| 596 | cap_destinazione_merce = property(_destMerccap) |
|---|
| 597 | |
|---|
| 598 | def _destMercprov(self): |
|---|
| 599 | if self.DM: return self.DM.provincia |
|---|
| 600 | else: return "" |
|---|
| 601 | provincia_destinazione_merce = property(_destMercprov) |
|---|
| 602 | |
|---|
| 603 | |
|---|
| 604 | #property banca |
|---|
| 605 | def _banca(self): |
|---|
| 606 | if self.BN: return self.BN.denominazione |
|---|
| 607 | else: return "" |
|---|
| 608 | banca = property(_banca) |
|---|
| 609 | |
|---|
| 610 | def _agenzia(self): |
|---|
| 611 | if self.BN: return self.BN.agenzia |
|---|
| 612 | else: return "" |
|---|
| 613 | agenzia = property(_agenzia) |
|---|
| 614 | |
|---|
| 615 | def _iban(self): |
|---|
| 616 | if self.BN: return self.BN.iban |
|---|
| 617 | else:return "" |
|---|
| 618 | iban = property(_iban) |
|---|
| 619 | |
|---|
| 620 | |
|---|
| 621 | #property pagamento |
|---|
| 622 | def _pagamento(self): |
|---|
| 623 | if self.PG: return self.PG.denominazione |
|---|
| 624 | else:return "" |
|---|
| 625 | pagamento = property(_pagamento) |
|---|
| 626 | |
|---|
| 627 | |
|---|
| 628 | |
|---|
| 629 | #property cliente |
|---|
| 630 | def _ragione_sociale_cliente(self): |
|---|
| 631 | if self.CLI: return self.CLI.ragione_sociale |
|---|
| 632 | else: return "" |
|---|
| 633 | ragione_sociale_cliente= property(_ragione_sociale_cliente) |
|---|
| 634 | |
|---|
| 635 | def _indirizzo_cliente(self): |
|---|
| 636 | if self.CLI: return self.CLI.sede_legale_indirizzo |
|---|
| 637 | else: return "" |
|---|
| 638 | indirizzo_cliente= property(_indirizzo_cliente) |
|---|
| 639 | |
|---|
| 640 | def _indirizzo_cliente_operativa(self): |
|---|
| 641 | if self.CLI: return self.CLI.sede_operativa_indirizzo |
|---|
| 642 | else: return "" |
|---|
| 643 | indirizzo_cliente_operativa= property(_indirizzo_cliente_operativa) |
|---|
| 644 | |
|---|
| 645 | def _cap_cliente(self): |
|---|
| 646 | if self.CLI: return self.CLI.sede_legale_cap |
|---|
| 647 | else:return "" |
|---|
| 648 | cap_cliente= property(_cap_cliente) |
|---|
| 649 | |
|---|
| 650 | def _cap_cliente_operativa(self): |
|---|
| 651 | if self.CLI: return self.CLI.sede_operativa_cap |
|---|
| 652 | else:return "" |
|---|
| 653 | cap_cliente_operativa= property(_cap_cliente_operativa) |
|---|
| 654 | |
|---|
| 655 | def _localita_cliente(self): |
|---|
| 656 | if self.CLI: return self.CLI.sede_legale_localita |
|---|
| 657 | else: return "" |
|---|
| 658 | localita_cliente= property(_localita_cliente) |
|---|
| 659 | |
|---|
| 660 | def _localita_cliente_operativa(self): |
|---|
| 661 | if self.CLI: return self.CLI.sede_operativa_localita |
|---|
| 662 | else: return "" |
|---|
| 663 | localita_cliente_operativa= property(_localita_cliente_operativa) |
|---|
| 664 | |
|---|
| 665 | def _provincia_cliente(self): |
|---|
| 666 | if self.CLI: return self.CLI.sede_legale_provincia |
|---|
| 667 | else: return "" |
|---|
| 668 | provincia_cliente= property(_provincia_cliente) |
|---|
| 669 | |
|---|
| 670 | def _provincia_cliente_operativa(self): |
|---|
| 671 | if self.CLI: return self.CLI.sede_operativa_provincia |
|---|
| 672 | else: return "" |
|---|
| 673 | provincia_cliente_operativa= property(_provincia_cliente_operativa) |
|---|
| 674 | |
|---|
| 675 | def _partita_iva_cliente(self): |
|---|
| 676 | if self.CLI: return self.CLI.partita_iva |
|---|
| 677 | else: return "" |
|---|
| 678 | partita_iva_cliente= property(_partita_iva_cliente) |
|---|
| 679 | |
|---|
| 680 | def _codice_fiscale_cliente(self): |
|---|
| 681 | if self.CLI: return self.CLI.codice_fiscale |
|---|
| 682 | else: return "" |
|---|
| 683 | codice_fiscale_cliente= property(_codice_fiscale_cliente) |
|---|
| 684 | |
|---|
| 685 | def _cognome_cliente(self): |
|---|
| 686 | if self.CLI: return self.CLI.cognome |
|---|
| 687 | else: return "" |
|---|
| 688 | cognome_cliente= property(_cognome_cliente) |
|---|
| 689 | |
|---|
| 690 | def _nome_cliente(self): |
|---|
| 691 | if self.CLI: return self.CLI.nome |
|---|
| 692 | else: return "" |
|---|
| 693 | nome_cliente= property(_nome_cliente) |
|---|
| 694 | |
|---|
| 695 | |
|---|
| 696 | |
|---|
| 697 | #property Fornitore |
|---|
| 698 | def _ragione_sociale_fornitore(self): |
|---|
| 699 | if self.FORN: return self.FORN.ragione_sociale |
|---|
| 700 | else: return "" |
|---|
| 701 | ragione_sociale_fornitore= property(_ragione_sociale_fornitore) |
|---|
| 702 | |
|---|
| 703 | def _indirizzo_fornitore(self): |
|---|
| 704 | if self.FORN: return self.FORN.sede_legale_indirizzo |
|---|
| 705 | else: return "" |
|---|
| 706 | indirizzo_fornitore= property(_indirizzo_fornitore) |
|---|
| 707 | |
|---|
| 708 | def _indirizzo_fornitore_operativa(self): |
|---|
| 709 | if self.FORN: return self.FORN.sede_operativa_indirizzo |
|---|
| 710 | else: return "" |
|---|
| 711 | indirizzo_fornitore_operativa= property(_indirizzo_fornitore_operativa) |
|---|
| 712 | |
|---|
| 713 | def _cap_fornitore(self): |
|---|
| 714 | if self.FORN: return self.FORN.sede_legale_cap |
|---|
| 715 | else: return "" |
|---|
| 716 | cap_fornitore= property(_cap_fornitore) |
|---|
| 717 | |
|---|
| 718 | def _cap_fornitore_operativa(self): |
|---|
| 719 | if self.FORN: return self.FORN.sede_operativa_cap |
|---|
| 720 | else: return "" |
|---|
| 721 | cap_fornitore_operativa= property(_cap_fornitore_operativa) |
|---|
| 722 | |
|---|
| 723 | def _localita_fornitore(self): |
|---|
| 724 | if self.FORN: return self.FORN.sede_legale_localita |
|---|
| 725 | else: return "" |
|---|
| 726 | localita_fornitore= property(_localita_fornitore) |
|---|
| 727 | |
|---|
| 728 | def _localita_fornitore_operativa(self): |
|---|
| 729 | if self.FORN: return self.FORN.sede_operativa_localita |
|---|
| 730 | else: return "" |
|---|
| 731 | localita_fornitore_operativa = property(_localita_fornitore_operativa) |
|---|
| 732 | |
|---|
| 733 | def _provincia_fornitore(self): |
|---|
| 734 | if self.FORN: return self.FORN.sede_legale_provincia |
|---|
| 735 | else: return "" |
|---|
| 736 | provincia_fornitore= property(_provincia_fornitore) |
|---|
| 737 | |
|---|
| 738 | def _provincia_fornitore_operativa(self): |
|---|
| 739 | if self.FORN: return self.FORN.sede_operativa_provincia |
|---|
| 740 | else: return "" |
|---|
| 741 | provincia_fornitore_operativa= property(_provincia_fornitore_operativa) |
|---|
| 742 | |
|---|
| 743 | def _partita_iva_fornitore(self): |
|---|
| 744 | if self.FORN: return self.FORN.partita_iva |
|---|
| 745 | else: return "" |
|---|
| 746 | partita_iva_fornitore= property(_partita_iva_fornitore) |
|---|
| 747 | |
|---|
| 748 | def _codice_fiscale_fornitore(self): |
|---|
| 749 | if self.FORN: return self.FORN.codice_fiscale |
|---|
| 750 | else: return "" |
|---|
| 751 | codice_fiscale_fornitore= property(_codice_fiscale_fornitore) |
|---|
| 752 | |
|---|
| 753 | def _cognome_fornitore(self): |
|---|
| 754 | if self.FORN: return self.FORN.cognome |
|---|
| 755 | else: return "" |
|---|
| 756 | cognome_fornitore= property(_cognome_fornitore) |
|---|
| 757 | |
|---|
| 758 | def _nome_fornitore(self): |
|---|
| 759 | if self.FORN: return self.FORN.nome |
|---|
| 760 | else: return "" |
|---|
| 761 | nome_fornitore= property(_nome_fornitore) |
|---|
| 762 | |
|---|
| 763 | #property Agente |
|---|
| 764 | def _ragione_sociale_agente(self): |
|---|
| 765 | if self.AGE: return self.AGE.ragione_sociale |
|---|
| 766 | else: return "" |
|---|
| 767 | ragione_sociale_agente= property(_ragione_sociale_agente) |
|---|
| 768 | |
|---|
| 769 | |
|---|
| 770 | if hasattr(conf, "GestioneNoleggio") and getattr(conf.GestioneNoleggio,'mod_enable')=="yes": |
|---|
| 771 | def _get_data_inizio_noleggio(self): |
|---|
| 772 | if not self.__data_inizio_noleggio: |
|---|
| 773 | if self.TGN: |
|---|
| 774 | self.__data_inizio_noleggio = self.TGN.data_inizio_noleggio |
|---|
| 775 | else: |
|---|
| 776 | self.__data_inizio_noleggio = "" |
|---|
| 777 | return self.__data_inizio_noleggio |
|---|
| 778 | def _set_data_inizio_noleggio(self, value): |
|---|
| 779 | self.__data_inizio_noleggio = value |
|---|
| 780 | data_inizio_noleggio = property(_get_data_inizio_noleggio, _set_data_inizio_noleggio) |
|---|
| 781 | |
|---|
| 782 | def _get_data_fine_noleggio(self): |
|---|
| 783 | if not self.__data_fine_noleggio: |
|---|
| 784 | if self.TGN: |
|---|
| 785 | self.__data_fine_noleggio = self.TGN.data_fine_noleggio |
|---|
| 786 | else: |
|---|
| 787 | self.__data_fine_noleggio = "" |
|---|
| 788 | return self.__data_fine_noleggio |
|---|
| 789 | def _set_data_fine_noleggio(self, value): |
|---|
| 790 | self.__data_fine_noleggio = value |
|---|
| 791 | data_fine_noleggio = property(_get_data_fine_noleggio, _set_data_fine_noleggio) |
|---|
| 792 | |
|---|
| 793 | |
|---|
| 794 | def delete(self): |
|---|
| 795 | print "PARTIAMO DA QUI" |
|---|
| 796 | #testataMovDel = TestataMovimento().select(id_testata_documento = self.id).all() |
|---|
| 797 | params['session'].delete(self) |
|---|
| 798 | params['session'].commit() |
|---|
| 799 | |
|---|
| 800 | |
|---|
| 801 | |
|---|
| 802 | |
|---|
| 803 | def filter_values(self,k,v): |
|---|
| 804 | if k == 'daNumero': |
|---|
| 805 | dic = {k:testata_documento.c.numero >= v} |
|---|
| 806 | elif k == 'aNumero': |
|---|
| 807 | dic = {k:testata_documento.c.numero <= v} |
|---|
| 808 | elif k == 'daParte': |
|---|
| 809 | dic = {k:testata_documento.c.parte >= v} |
|---|
| 810 | elif k == 'aParte': |
|---|
| 811 | dic = {k:testata_documento.c.parte <= v} |
|---|
| 812 | elif k == 'daData': |
|---|
| 813 | dic = {k:testata_documento.c.data_documento >= v} |
|---|
| 814 | elif k== 'aData': |
|---|
| 815 | dic = {k:testata_documento.c.data_documento <= v} |
|---|
| 816 | elif k =='protocollo': |
|---|
| 817 | dic = {k:testata_documento.c.protocollo.ilike("%"+v+"%")} |
|---|
| 818 | elif k == 'idOperazione': |
|---|
| 819 | dic = {k:testata_documento.c.operazione == v} |
|---|
| 820 | elif k == 'idMagazzino': |
|---|
| 821 | dic = {k:testata_movi.c.id.in_(select([RigaMovimento.id_testata_movimento],and_( |
|---|
| 822 | testata_movi.c.id_testata_documento == testata_documento.c.id, |
|---|
| 823 | Riga.id==RigaMovimento.id,Riga.id_magazzino== v))) |
|---|
| 824 | } |
|---|
| 825 | # dic = {k:and_(or_(testata_movi.c.id_testata_documento == testata_documento.c.id, |
|---|
| 826 | # testata_movi.c.id == RigaMovimento.id_testata_movimento, |
|---|
| 827 | # Riga.id==RigaMovimento.id, Riga.id_magazzino== v), |
|---|
| 828 | # or_(testata_documento.c.id == RigaDocumento.id_testata_documento, |
|---|
| 829 | # Riga.id==RigaDocumento.id, Riga.id_magazzino== v)) |
|---|
| 830 | # } |
|---|
| 831 | elif k == 'idCliente': |
|---|
| 832 | dic = {k:testata_documento.c.id_cliente == v} |
|---|
| 833 | elif k == 'idFornitore': |
|---|
| 834 | dic = {k:testata_documento.c.id_fornitore == v} |
|---|
| 835 | elif k == 'idAgente': |
|---|
| 836 | dic = {k:testata_documento.c.id_agente == v} |
|---|
| 837 | elif k == 'statoDocumento': |
|---|
| 838 | dic = {k:testata_documento.c.documento_saldato == v} |
|---|
| 839 | elif k == 'idArticolo': |
|---|
| 840 | dic = {k:and_(Articolo.id ==Riga.id_articolo, |
|---|
| 841 | riga.c.id==RigaMovimento.id, |
|---|
| 842 | RigaMovimento.id_testata_movimento == TestataMovimento.id, |
|---|
| 843 | TestataMovimento.id_testata_documento == testata_documento.c.id, |
|---|
| 844 | Articolo.id ==v)} |
|---|
| 845 | # dic = {k:testata_documento.c.id.in_(select([testata_documento.c.id], |
|---|
| 846 | # or_(and_(testata_movi.c.id_testata_documento == testata_documento.c.id, |
|---|
| 847 | # Riga.id==RigaMovimento.id,Articolo.id ==Riga.id_articolo, |
|---|
| 848 | # Articolo.id == v),and_(testata_documento.c.id==riga_doc.c.id_testata_documento, |
|---|
| 849 | # Riga.id==riga_doc.c.id,Articolo.id ==Riga.id_articolo, |
|---|
| 850 | # Articolo.id == v))))} |
|---|
| 851 | elif hasattr(conf, "GestioneNoleggio") and getattr(conf.GestioneNoleggio,'mod_enable')=="yes": |
|---|
| 852 | if k == 'daDataInizioNoleggio': |
|---|
| 853 | dic = {k:and_(testata_documento.c.id == TestataGestioneNoleggio.id_testata_documento, |
|---|
| 854 | TestataGestioneNoleggio.data_inizio_noleggio >= v)} |
|---|
| 855 | elif k== 'aDataInizioNoleggio': |
|---|
| 856 | dic = {k:and_(testata_documento.c.id == TestataGestioneNoleggio.id_testata_documento, |
|---|
| 857 | TestataGestioneNoleggio.data_inizio_noleggio <= v)} |
|---|
| 858 | if k == 'daDataFineNoleggio': |
|---|
| 859 | dic = {k:and_(testata_documento.c.id == TestataGestioneNoleggio.id_testata_documento, |
|---|
| 860 | TestataGestioneNoleggio.data_fine_noleggio >= v)} |
|---|
| 861 | elif k== 'aDataFineNoleggio': |
|---|
| 862 | dic = {k:and_(testata_documento.c.id == TestataGestioneNoleggio.id_testata_documento, |
|---|
| 863 | TestataGestioneNoleggio.data_fine_noleggio <= v)} |
|---|
| 864 | return dic[k] |
|---|
| 865 | |
|---|
| 866 | riga=Table('riga',params['metadata'],schema = params['schema'],autoload=True) |
|---|
| 867 | riga_doc=Table('riga_documento',params['metadata'],schema = params['schema'],autoload=True) |
|---|
| 868 | testata_documento=Table('testata_documento',params['metadata'],schema = params['schema'],autoload=True) |
|---|
| 869 | vettore = Table('vettore',params['metadata'],schema = params['schema'],autoload=True) |
|---|
| 870 | testata_movi=Table('testata_movimento',params['metadata'],schema = params['schema'],autoload=True) |
|---|
| 871 | agen = Table('agente',params['metadata'],schema = params['schema'],autoload=True) |
|---|
| 872 | paga = Table('pagamento',params['metadata'],schema = params['schema'],autoload=True) |
|---|
| 873 | clie = Table('cliente',params['metadata'],schema = params['schema'],autoload=True) |
|---|
| 874 | banc = Table('banca',params['metadata'],schema = params['schema'],autoload=True) |
|---|
| 875 | fornitor=Table('fornitore', params['metadata'], schema = params['schema'], autoload=True) |
|---|
| 876 | |
|---|
| 877 | std_mapper = mapper(TestataDocumento, testata_documento, properties={ |
|---|
| 878 | "rigadoc": relation(RigaDocumento, cascade="all, delete",backref="testata_documento"), |
|---|
| 879 | "testata_documento_scadenza" :relation(TestataDocumentoScadenza,cascade="all, delete", backref="testata_documento"), |
|---|
| 880 | "PG":relation(Pagamento,primaryjoin = testata_documento.c.id_pagamento==paga.c.id), |
|---|
| 881 | "BN":relation(Banca,primaryjoin = (testata_documento.c.id_banca==banc.c.id)), |
|---|
| 882 | "AL":relation(AliquotaIva,primaryjoin = (testata_documento.c.id_aliquota_iva_esenzione==AliquotaIva.id)), |
|---|
| 883 | "PV":relation(Vettore,primaryjoin = (testata_documento.c.id_vettore==vettore.c.id)), |
|---|
| 884 | "DM":relation(DestinazioneMerce, primaryjoin=(testata_documento.c.id_destinazione_merce==DestinazioneMerce.id)), |
|---|
| 885 | "TM":relation(TestataMovimento,primaryjoin = (testata_documento.c.id==testata_movi.c.id_testata_documento),cascade="all, delete", backref='TD'), |
|---|
| 886 | "CLI":relation(Cliente,primaryjoin = (testata_documento.c.id_cliente==clie.c.id)), |
|---|
| 887 | "FORN":relation(Fornitore,primaryjoin = (testata_documento.c.id_fornitore==fornitor.c.id)), |
|---|
| 888 | "AGE":relation(Agente,primaryjoin = (testata_documento.c.id_agente==agen.c.id)), |
|---|
| 889 | "OP":relation(Operazione,primaryjoin = (testata_documento.c.operazione==Operazione.denominazione), backref="TD"), |
|---|
| 890 | "STD":relation(ScontoTestataDocumento,primaryjoin = (testata_documento.c.id==ScontoTestataDocumento.id_testata_documento),cascade="all, delete, delete-orphan", backref="TD"), |
|---|
| 891 | #'lang':relation(Language, backref='user') |
|---|
| 892 | }, order_by=testata_documento.c.numero) |
|---|
| 893 | |
|---|
| 894 | if hasattr(conf, "GestioneNoleggio") and getattr(conf.GestioneNoleggio,'mod_enable')=="yes": |
|---|
| 895 | from promogest.modules.GestioneNoleggio.dao.TestataGestioneNoleggio import TestataGestioneNoleggio |
|---|
| 896 | std_mapper.add_property("TGN",relation(TestataGestioneNoleggio,primaryjoin=(testata_documento.c.id==TestataGestioneNoleggio.id_testata_documento),backref="TD",uselist = False)) |
|---|