def on_menomesi_calendar_button_clicked(self, button): if Environment.view =="week": one_week = relativedelta(weeks=-1) nextmonth = Environment.currentData+one_week else: one_month = relativedelta(months=-1) nextmonth = Environment.currentData+one_month self.create_planning_frame(currentData=nextmonth)
def calcolo_ricarico_medio_e_influenza_sulle_vendite(self): idsCliente = [] idsArticoli = [] artiID = [] intervallo = '' self.res = [] # Prelevo i dati dalla ui daData = stringToDate(self.da_data_entry.get_text()) aData = stringToDate(self.a_data_entry.get_text()) # Id dei clienti clienti = ClienteCategoriaCliente().select(idCategoria = self.cateClienteId, batchSize=None) for cli in clienti: idsCliente.append(cli.id_cliente) # id degli articoli articoli = Articolo().select(idCategoria = self.cateArticoloId, produttore = produt, batchSize=None) for art in articoli: idsArticoli.append(art.id) # inizializzo un po' di variabili e dizionari quantitaVendutaDict = {} quantitaAcquistata = 0 quantitaAcquistataTotale = 0 valoreAcquistoDict= {} valoreAcquisto = 0 quantitaVenduta = 0 quantitaVendutaTotale = 0 valoreAcquistoTotale= 0 valoreVenditaDict = {} valoreVendita = 0 valoreVenditaTotale = Decimal("0") ricaricomedioDict = {} incidenzaAcquistoDict = {} incidenzaVenditaDict = {} # smisto i dati secondo categoriaArticolo print " ID CATEGORIE", self.cateArticoloId for arto in self.cateArticoloId: # INIZIO livello categoria nomeCategoria = CategoriaArticolo().getRecord(id=arto) articoli = Articolo().select(idCategoria = arto, produttore = produt, batchSize=None) print "ARTICOLI IN QUELLA CATEGORIA", len(articoli) for art in articoli: # INIZIO livello articolo print "INIZIO AD ELABORARE L'ARTICOLO ", art.id quantitaVendutaUNO = 0 quantitaVendutaTotaleUNO = 0 quantitaAcquistataUNO = 0 quantitaAcquistataTotaleUNO = 0 # tutte le righe movimento per la vendita righeArticoloMovimentate= Environment.params["session"]\ .query(RigaMovimento, TestataMovimento)\ .filter(TestataMovimento.data_movimento.between(daData, aData))\ .filter(TestataMovimento.id_cliente.in_(idsCliente))\ .filter(RigaMovimento.id_testata_movimento == TestataMovimento.id)\ .filter(Riga.id_magazzino.in_(self.magazzinoId))\ .filter(Riga.id_articolo == art.id)\ .all() print "RIGHE DI MOVIMENTO VENDITA", righeArticoloMovimentate for rig in righeArticoloMovimentate: # Quanti ne ho venduti IN TOTALE quantitaVendutaUNO += rig[0].quantita quantitaVendutaTotaleUNO += rig[0].quantita quantitaVendutaTotale += rig[0].quantita quantitaAcquistataUNO = 0 rigaArticoloMovimentata= Environment.params["session"]\ .query(RigaMovimento, TestataMovimento)\ .filter(TestataMovimento.data_movimento.between(daData+relativedelta(months=-4), aData))\ .filter(TestataMovimento.id_cliente == None)\ .filter(TestataMovimento.id_fornitore != None)\ .filter(RigaMovimento.id_testata_movimento == TestataMovimento.id)\ .filter(Riga.id_magazzino.in_(self.magazzinoId))\ .filter(Riga.id_articolo == art.id)\ .all() if not rigaArticoloMovimentata: forni= leggiFornitura(art.id) valoreAcquisto += (forni["prezzoNetto"]*quantitaVendutaUNO) valoreAcquistoTotale += (forni["prezzoNetto"]*quantitaVendutaUNO) print " PREZZO DA FORNITURA" else: # for r in rigaArticoloMovimentata: valoreAcquisto += (rigaArticoloMovimentata[0][0].valore_unitario_netto*quantitaVendutaUNO) valoreAcquistoTotale += (rigaArticoloMovimentata[0][0].valore_unitario_netto*quantitaVendutaUNO) quantitaAcquistataUNO += rigaArticoloMovimentata[0][0].quantita quantitaAcquistataTotaleUNO += rigaArticoloMovimentata[0][0].quantita # quantitaAcquistataTotale += r[0].quantita print " VALORE ACQUISTO", valoreAcquisto ope = leggiOperazione(rig[1].operazione) if ope["fonteValore"] =="vendita_iva": # devo scorporare l'iva dal prezzo finale di vendita imponibile = Decimal(str(float(rig[0].valore_unitario_netto)/(1+float(rig[0].percentuale_iva)/100))) elif ope["fonteValore"] =="vendita_senza_iva": imponibile = Decimal(str(float(rig[0].valore_unitario_netto))) else: print "TIPO DI FONTE VALORE PER LA VENDITA NN RICONOSCIUTO" valoreVendita += (imponibile*quantitaVendutaUNO) valoreVenditaTotale += (imponibile*quantitaVendutaUNO) # QUESTO LIVELLO ARTICOLO if quantitaVendutaTotaleUNO <= quantitaAcquistataTotaleUNO: print "ARTICOLO %s OK", str(art.id), quantitaVendutaTotaleUNO,quantitaAcquistataTotaleUNO else: print " SERVE TROVARE UN PREZZO ACQUISTO", str(art.id),quantitaVendutaTotaleUNO,quantitaAcquistataTotaleUNO # Questo livello categoria quantitaVenduta =+quantitaVendutaTotale if valoreAcquisto!=0: ricaricomedioDict[nomeCategoria.denominazione] = ((valoreVendita - valoreAcquisto )/ valoreAcquisto) *100 else: ricaricomedioDict[nomeCategoria.denominazione] = 0 quantitaVendutaDict[nomeCategoria.denominazione] = quantitaVenduta or Decimal("0") valoreAcquistoDict[nomeCategoria.denominazione] = valoreAcquisto or Decimal("0") valoreVenditaDict[nomeCategoria.denominazione] = valoreVendita or Decimal("0") quantitaVenduta = 0 valoreAcquisto = 0 valoreVendita = 0 # Questo livello fuori da tutto for k,v in valoreVenditaDict.items(): if v: incidenzaVenditaDict[k] = v*100 / valoreVenditaTotale else: incidenzaVenditaDict[k] = 0 for k,v in valoreAcquistoDict.items(): if v: incidenzaAcquistoDict[k] = v*100 / valoreAcquistoTotale else: incidenzaAcquistoDict[k] = 0 pageData = { "file": "statistica_ricarico_medio_e_influenza_vendite.html", "categorieArticolo": self.cateArticoloDen, "quantitaVendutaDict":quantitaVendutaDict, "valoreAcquistoDict":valoreAcquistoDict, "valoreVenditaDict":valoreVenditaDict, "ricaricomedioDict":ricaricomedioDict, "incidenzaVenditaDict": incidenzaVenditaDict, "incidenzaAcquistoDict": incidenzaAcquistoDict, "quantitaVendutaTotale": quantitaVendutaTotale, "valoreAcquistoTotale": valoreAcquistoTotale, "valoreVenditaTotale": valoreVenditaTotale, "daData": self.da_data_entry.get_text(), "aData":self.a_data_entry.get_text(), "produttore": produt, "cateclienti": self.cateClienteDen, "magazzini": self.magazzinoDen, "nomestatistica":self.nome_stat} view = HtmlViewer(pageData) return
def on_anno_calendar_spinbutton_change_value(self, spinbutton): if int(spinbutton.get_value()) != Environment.workinYearc: newYear = int(spinbutton.get_value()) - Environment.workinYearc one_year = relativedelta(years=newYear) nextyear = Environment.currentData+one_year self.create_planning_frame(currentData=nextyear)
def on_menogiorni_calendar_button_clicked(self, button): one_day = relativedelta(days=-1) tomorrow = Environment.currentData+one_day self.create_planning_frame(currentData=tomorrow)
def create_planning_frame(self,d=1,m=1,y=0, currentData=None,view=None): promeDict= {} prevesDict = {} prevesDictAT = {} ordesDict = {} ordesDictAT = {} if d==1 and m==1 and y ==0 and not currentData: currentData = datetime.date.today() m = currentData.month y = currentData.year d = currentData.day if currentData: m = currentData.month y = currentData.year d = currentData.day Environment.currentData = currentData if view: Environment.view = view else: try: view = Environment.view except: view = "month" weekDay = currentData.weekday() workinMonth = Environment.workinMonth= m workinYearc = Environment.workinYearc= y self.anno_calendar_spinbutton.set_value(int(workinYearc)) workinDay = Environment.workinDay = d if os.name=="nt": dayName2 = calendar.day_name dayName = [x.decode("iso8859-1") for x in dayName2] else: dayName2 = calendar.day_name dayName = [x.decode("iso8859-1") for x in dayName2] monthName = calendar.month_name cale = calendar.Calendar().monthdatescalendar(workinYearc,workinMonth) first_day = relativedelta(days=-(workinDay-1)) last_day = relativedelta(days=(last_day_of_month(workinYearc, workinMonth)-workinDay)) currentLastDay = currentData+last_day currentFirstDay = currentData+first_day eventipromes_ins = [] eventipromes_scad = [] if self.promemoria_ins_check.get_active(): promes = Promemoria().select(da_data_inserimento= currentFirstDay, a_data_scadenza=currentLastDay, batchSize=None) for p in promes: eventipromes_ins.append((p.data_inserimento.toordinal(),{"id":p.id, "short":p.oggetto, "tipo":"data_inserimento", "colore":"#F2859A"},p.data_inserimento.day)) if self.promemoria_scad_check.get_active(): promes = Promemoria().select(da_data_inserimento= currentFirstDay, a_data_scadenza=currentLastDay, batchSize=None) for p in promes: eventipromes_scad.append((p.data_scadenza.toordinal(),{"id":p.id, "short":p.oggetto, "tipo":"data_scadenza", "colore":"#148F14"},p.data_scadenza.day)) eventipreves = [] eventiprevesAT = [] if self.preventivi_check.get_active(): preves = TestataDocumento().select(daData= currentFirstDay, aData=currentLastDay, batchSize=None, idOperazione="Preventivo") for p in preves: eventipreves.append((p.data_documento.toordinal(),{"id":p.id, "short":p.ragione_sociale_cliente, "tipo":"data_documento", "colore":"#6495ED"},p.data_documento.day)) if posso("GN"): arcTemp = TestataGestioneNoleggio().select(idTestataDocumento=p.id, batchSize=None) for a in arcTemp: startDate =a.data_inizio_noleggio stopDate =a.data_fine_noleggio dateList= date_range(startDate,stopDate) for d in dateList: eventiprevesAT.append((d.toordinal(),{"id":p.id, "short":p.ragione_sociale_cliente, "tipo":"data_documento", "colore":"#AFEEEE"},d.day)) eventiordes = [] eventiordesAT = [] if self.ordini_check.get_active(): ordes = TestataDocumento().select(daData= currentFirstDay, aData=currentLastDay, batchSize=None, idOperazione="Ordine da cliente") for p in ordes: eventiordes.append((p.data_documento.toordinal(),{ "id":p.id, "short":p.ragione_sociale_cliente, "tipo":"data_documento", "colore":"#FFA500"},p.data_documento.day)) if posso("GN"): arcTemp = TestataGestioneNoleggio().select(idTestataDocumento=p.id, batchSize=None) for a in arcTemp: startDate =a.data_inizio_noleggio stopDate =a.data_fine_noleggio dateList= date_range(startDate,stopDate) for d in dateList: eventiordesAT.append((d.toordinal(),{"id":p.id, "short":p.ragione_sociale_cliente, "tipo":"data_documento", "colore":"red"},d.day)) onlyWeek = self.onlyWeek(cale, workinDay, workinMonth, workinYearc,dayName) pageData = {"file": "planning.html", "cale":cale, "onlyWeek":onlyWeek, "eventipromes_ins": eventipromes_ins, "eventipromes_scad": eventipromes_scad, "eventipreves":eventipreves, "eventiprevesAT": eventiprevesAT, "eventiordes":eventiordes, "eventiordesAT": eventiordesAT, "dayName" :dayName, "monthName": monthName, "workinDay":workinDay, "weekDay":weekDay, "workinMonth":workinMonth, "workinYearc":workinYearc, "view":view} self.hhttmmll = renderTemplate(pageData) renderHTML(self.htmlPlanningWidget,self.hhttmmll)