def show(self, id): """Handle the front-page.""" """GET /bookkeeping/id: Show a specific item""" results = OrderedDict() for i in ['total' , 'account_code', 'vat_code', 'recs', 'issues']: results[i]=None # Total groupby = [Factb2b.booked, Factb2b.closed, Provenienze, Factb2b.doc_id, Factb2b.doc_date, Factb2b.doc_num] query_lst = groupby + FACT_B2B fltr = [and_(Factb2b.doc_id==id, Factb2b.supplier_id==Provenienze.numeroprovenienza)] results['total'] = self._datagrid(query_lst, groupby, fltr) # Account groupby = [Factb2b.doc_num,Factb2b.cost_center_code, Factb2b.account_code, Factb2b.account_desc, Factb2b.b2b_vat_code] query_lst = groupby + FACT_B2B fltr = [Factb2b.doc_id==id ] results['account_code'] = self._datagrid(query_lst, groupby, fltr) # Vat groupby = [Factb2b.doc_num, Factb2b.cost_center_code, Factb2b.b2b_vat_code] query_lst = groupby + FACT_B2B fltr = [Factb2b.doc_id==id] results['vat_code'] = self._datagrid(query_lst, groupby, fltr) # Receipts recs = [i[0] for i in DBSession.query(Factb2b.rec_num).filter( Factb2b.doc_id==id).distinct().all()] results['recs'] = [] for rec_num in recs: groupby = [Factb2b.doc_num, Factb2b.rec_num] query_lst = groupby + FACT_B2B fltr = [Factb2b.doc_id==id, Factb2b.rec_num==rec_num ] results['recs'].append(self._datagrid(query_lst, groupby, fltr)[0]) # Issues fltr = [Factb2b.doc_id==id, Factb2b.account_id==None ] results['issues'] = DBSession.query(Factb2b).filter(and_(*fltr)).all() # Products groupby = [Factb2b.doc_num, Factb2b.account_code, Factb2b.b2b_code, Factb2b.b2b_desc] query_lst = groupby + FACT_B2B_PRICE fltr = [Factb2b.doc_id==id] results['products'] = self._datagrid(query_lst, groupby, fltr) return dict(page='bookkeeping', results=results, id=id)
def showreport(self, id, ng=None,nr=None): """GET /showreport/id: Show a specific item""" doc = DBSession.query(Inventarit).filter(Inventarit.numeroinventario==id).one() """ tables = ( Inventarirconta, Prodotti, Reparti, Gruppireparti ) columns = [] query_args = [] for m in tables: for c in m.__table__.columns: if not c in columns: columns.append("%s"%(c)) query_args.append(c) """ totale_costo2 = Inventarirconta.costo2 * Inventarirconta.totale_qta COSTI = [ label('totale_costo', func.sum(totale_costo2)), ] fltr_query = [Inventarirconta.numeroinventario==id] group = [ Inventarirconta.numeroinventario, Gruppireparti.numerogrupporeparto, Gruppireparti.grupporeparto] group_tot = [ Inventarirconta.numeroinventario ] if ng: group = group +[ Reparti.numeroreparto, Reparti.reparto ] fltr_query = fltr_query + [Gruppireparti.numerogrupporeparto==ng] if nr: group = group + [ Prodotti.numeroprodotto, Prodotti.prodotto ] fltr_query = fltr_query + [Reparti.numeroreparto==nr] query_args = group + COSTI query_args_tot = group_tot + COSTI ret = DBSession.query(*query_args) ret_tot = DBSession.query(*query_args_tot) fltr = [and_( *fltr_query ) ] ret = ret.filter(*fltr) ret_tot = ret_tot.filter(*fltr) ret = self._get_joins(ret) ret_tot = self._get_joins(ret_tot) ret = ret.group_by(*group) ret_tot = ret_tot.group_by(*group_tot) results = ret.all() totals = ret_tot.all() return dict(page='stock', id=id, ng=ng, nr=nr, doc=doc, results=results, totals=totals)
def update(self, id, *args, **kw): """PUT /backoffice/id: Update an existing item""" # Forms posted to this method should contain a hidden field: # <input type="hidden" name="_method" value="PUT" /> # Or using helpers: # h.form(url('stock', id=ID), # method='put') # url('stock', id=ID) DBSession.query(Factb2b).filter_by(doc_id=id).update(dict(booked=1)) redirect(url('/bookkeeping/show/%s'%id))
def show(self, id): """GET /stocks/id: Show a specific item""" doc = DBSession.query(Inventarit).filter(Inventarit.numeroinventario==id).one() if not doc.inventariconta: Inventarirconta(numeroinventario=doc.numeroinventario) DBSession.add(Inventarirconta) DBSession.flush() result = views.get_stock(id) return dict(page='stock', doc=doc, result=result)
def updatecost(self, id): """GET /stocks/id: Show a specific item""" #result = views.get_stock_cogs(id) doc = DBSession.query(Inventarit).filter(Inventarit.numeroinventario==id).one() invs = DBSession.query(Inventarirconta).filter(Inventarirconta.numeroinventario==id).all() for ic in invs: ic.costo, ic.datacosto = gcogs(ic.numeroprodotto, doc.numeromagazzino ,date=doc.datainventario) if not ic.costo2 or ic.costo2 == 0: ic.costo2 = ic.costo DBSession.add(ic) redirect('/stock/show/'+id)
def updatedoc(self, id, doc_num, *args, **kw): """PUT /stocks/id: Update an existing item""" # Forms posted to this method should contain a hidden field: # <input type="hidden" name="_method" value="PUT" /> # Or using helpers: # h.form(url('stock', id=ID), # method='put') # url('stock', id=ID) print [args] print [kw] DBSession.query(Factb2b).filter_by(inputb2b_id=id,doc_num=doc_num ).update(dict(validated=1)) redirect(url('/b2b/showdoc/%s/%s'%(id,doc_num)))
def requestupg(self, id): """GET /stocks/id: Show a specific item""" date=datetime.now() try: obj = DBSession.query(Aggiornaic).filter(Aggiornaic.numeroinventario==id).one() except: obj = Aggiornaic() obj.numeroinventario=id obj.richiesta=date obj.status = 1 email = '' DBSession.add(obj) redirect('/stock/showcost/'+id)
def qta(cls, doc_id, prod_id): """""" try: ret = DBSession.query(Inventarirconta).filter( Inventarirconta.numeroinventario==doc_id, Inventarirconta.numeroprodotto==prod_id, ).one() except: ret = Inventarirconta() ret.numeroinventario=doc_id ret.numeroprodotto=prod_id ret.qta=0 DBSession.add(ret) DBSession.flush() return ret
def b2b_export(self, id): """""" validated = DBSession.query(Factb2b).filter(and_( Factb2b.inputb2b_id == id, Factb2b.booked != 1 )).all() return dict(page='modal',id=id,validated=validated, result=[id])
def _datagrid(self, query_lst , groupby, fltr, ordr=None): ret = DBSession.query(*query_lst) #ret = ret.order_by(Factb2b.row) ret = ret.group_by(*groupby).filter(and_(*fltr)) if ordr: ret = ret.order_by(*ordr) return ret.all()
def show(self, id): """GET /stocks/id: Show a specific item""" result = views.get_pricelist(id) ret = DBSession.query(Provenienze).filter(Provenienze.numeroprovenienza==id).one() return dict(page='stock', ret = ret, result=result)
def index(self, page=1): """Handle the front-page.""" results = DBSession.query(Prodotti) pags = paginate.Page(results, page, items_per_page=50) return dict(page='item', results=pags.items, pags=pags)
def product(self, id): """""" ret = DBSession.query(Prodotti ) ret = ret.filter(Prodotti.numeroprodotto==id) ret = ret.one() return dict(page='modal',result=ret)
def prezzo(self): try: l=DBSession.query(Listiniprodotti).filter(and_( Listiniprodotti.numeroprodotto=="%s"%self.numeroprodotto, Listiniprodotti.numerolistino==0 )).one() return l.prezzo except: return 0
def show(self, id): """GET /b2b/id: Show a specific item""" inputb2b = DBSession.query(Inputb2b).filter(Inputb2b.b2b_id==id).one() groupby = [Factb2b.booked, Factb2b.validated, Provenienze, Factb2b.doc_date, Factb2b.doc_num] query_lst = groupby + FACT_B2B fltr = [and_( Provenienze.numeroprovenienza==Factb2b.supplier_id, Factb2b.inputb2b_id == id ) ] results = self._datagrid(query_lst, groupby, fltr) return dict(page='b2b', id=id, inputb2b=inputb2b, results=results)
def update(self, id): """PUT /stocks/id: Update an existing item""" # Forms posted to this method should contain a hidden field: # <input type="hidden" name="_method" value="PUT" /> # Or using helpers: # h.form(url('stock', id=ID), # method='put') # url('stock', id=ID) ret = DBSession.query(Inputb2b).filter( Inputb2b.b2b_id==id).one() from ebetl.lib.etl.filconad import FilconadObj fobj = FilconadObj(config, ret.record) fobj.write_out(inputb2b_id=id) return redirect(url('/b2b/show/%s'%id))
def index(self): """Handle the front-page.""" results = DBSession.query(Inputb2b).order_by(Inputb2b.processed, Inputb2b.updated).all() return dict(page='b2b', results=results)
def index(self, *args, **kw): """Handle the front-page.""" print kw group_by = [Clientifid.codiceclientefid, Clientifid.nome, Clientifid.cognome, Clientifid.email] fltr = group_by + MEASURES ret = DBSession.query(*fltr) start = kw.get('start') if start: start_obj = datetime.datetime.strptime(start, "%Y/%m/%d") else: start_obj = datetime.datetime.now() kw['start'] = start_obj.strftime("%Y/%m/%d") print start_obj ret=ret.filter(Movimentit.datadocumento>=start_obj) end = kw.get('end') if end: end_obj = datetime.datetime.strptime(end, "%Y/%m/%d") else: end_obj = datetime.datetime.now() kw['end'] = end_obj.strftime("%Y/%m/%d") ret=ret.filter(Movimentit.datadocumento<=end_obj) produttori = kw.get('produttori') if produttori: produttori = json.loads(produttori) prdlist = [] if produttori: for p in produttori: prdlist.append(Produttori.numeroproduttore==p) if prdlist: ret=ret.filter(or_(*prdlist)) reparti = kw.get('reparti') if reparti: reparti = json.loads(reparti) replist = [] if reparti: for r in reparti: replist.append(Prodotti.numeroreparto==r) if replist: ret=ret.filter(or_(*replist)) # join on document header table join_condition=Clientifid.numeroclientefid==Ricevutet.numeroclientefid ret = ret.join(Ricevutet, join_condition) join_condition=Ricevutet.numeromovimento==Movimentit.numeromovimento ret = ret.join(Movimentit, join_condition) join_condition=Movimentit.numeromovimento==Movimentir.numeromovimento ret = ret.join(Movimentir, join_condition) join_condition=Prodotti.numeroprodotto==Movimentir.idprodotto ret = ret.join(Prodotti, join_condition) join_condition=Produttori.numeroproduttore==Prodotti.numeroproduttore ret = ret.outerjoin(Produttori, join_condition) results = ret.group_by(*group_by).all() #results=[] #join_condition=Movimentit.numeromovimento==Movimentir.numeromovimento #ret = ret.join(Movimentir, join_condition) columns = [l.key for l in fltr] return dict(page='marketing', columns=columns, results=results, kw=kw)
def supplier(self): return DBSession.query(Provenienze).filter_by(numeroprovenienza=self.supplier_id).one()
def showcost(self, id, *args): """GET /stocks/id: Show a specific item""" result = views.get_stock_cogs(id, *args) doc = DBSession.query(Inventarit).filter(Inventarit.numeroinventario==id).one() return dict(page='stock', doc=doc, result=result)
def listini(self): return DBSession.query(Listiniprodotti).filter_by( numeroprodotto=str(self.numeroprodotto)).all()
def udm_view(self): return DBSession.query(Unitamisure).filter_by( numerounitamisura=str(self.numeroumvisualizzazione)).one()
def index(self): """Handle the front-page.""" results = DBSession.query(Inventarit).all() return dict(page='stock', results=results)
def index(self): """Handle the front-page.""" results = DBSession.query(Provenienze).filter_by(tipoprovenienza='FOR').all() return dict(page='purchase', results=results)
def post(self, *args, **kw): print [args] print [kw] try: pk = kw.get('pk') value = kw.get('value') if not value: value = '0' value = float(value) name = kw.get('name') doc_id, prod_id = pk.split('/') if name == 'qta' or name == 'qtaconf': p = DBSession.query(Prodotti).filter_by(numeroprodotto = prod_id).one() d = DBSession.query(Inventarit).filter_by(numeroinventario = doc_id).one() try : ic = DBSession.query(Inventarirconta).filter(and_( Inventarirconta.numeroinventario == doc_id, Inventarirconta.numeroprodotto == prod_id )).one() except: ic = Inventarirconta(numeroinventario=doc_id, numeroprodotto=prod_id) ic.qta = 0 ic.qtaconf = 0 #ic.costo = gcogs(prod_id, d.numeromagazzino ,date=d.datainventario) ic.costo2 = 0 if not ic.costo: ic.costo = 0 if not ic.qta: ic.qta = 0 if not ic.qtaconf: ic.qtaconf = 0 setattr(ic,name,value) pzxc = p.pezzixcollo or 1 ic.totale_qta = ic.qta+ic.qtaconf*pzxc ic.totale_costo=ic.totale_qta*ic.costo kw['totale_costo'] = todecimal(ic.totale_costo ) kw['totale_qta']=todecimal(ic.totale_qta ) kw['costo'] = todecimal(ic.costo) DBSession.add(ic) elif name == 'costo2': p = DBSession.query(Prodotti).filter_by(numeroprodotto = prod_id).one() d = DBSession.query(Inventarit).filter_by(numeroinventario = doc_id).one() ic = DBSession.query(Inventarirconta).filter(and_( Inventarirconta.numeroinventario == doc_id, Inventarirconta.numeroprodotto == prod_id )).one() if not ic.costo: ic.costo = 0 #if not ic.qta: # ic.qta = 0 #if not ic.qtaconf: # ic.qtaconf = 0 setattr(ic,name,value) print name, value print ic.costo, ic.costo2 #pzxc = p.pezzixcollo or 1 #ic.totale_qta = ic.qta+ic.qtaconf*pzxc ic.totale_costo=ic.totale_qta*ic.costo2 kw['totale_costo'] = todecimal(ic.totale_costo ) #kw['costo'] = todecimal(ic.costo) DBSession.add(ic) except: raise pylons.response.status = "400 Error" return "Not a valid entry" """Handle the front-page.""" import json return json.dumps(kw)
def by_user_name(cls, username): """Return the user object whose user name is ``username``.""" return DBSession.query(cls).filter_by(user_name=username).first()
def index(self, *kw, **args): """Handle the front-page.""" data = DBSession.query(Tipologieprodotti).all() return dict(data=data)
def index(self, *kw, **args): """Handle the front-page.""" data = DBSession.query(Produttori).all() return dict(data=data)
def by_email_address(cls, email): """Return the user object whose email address is ``email``.""" return DBSession.query(cls).filter_by(email_address=email).first()