Advertisement
webmanix

contagem

Sep 21st, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. import psycopg2
  2. import datetime
  3. import sys
  4.  
  5. conn = psycopg2.connect('dbname=cigarro host=10.40.140.25 user=postgres password=postgres')
  6. cur = conn.cursor()
  7.  
  8. connmatriz = psycopg2.connect('dbname=matrizpitstop host=10.40.140.25 user=postgres password=postgres')
  9. curmatriz = connmatriz.cursor()
  10.  
  11. cur.execute('SELECT produto, (select empresa from estoque where id = estoque), '
  12. ' last_modified, quant FROM saldos WHERE estoque in (select id from estoque where id > 99)')
  13.  
  14. cigarros = {}
  15.  
  16. for rec in cur:
  17. curmatriz.execute(" SELECT "
  18. " (select nome from produto where grid = produto) nome, quantidade "
  19. " FROM "
  20. " lancto WHERE empresa = %d AND data >= '%s' "
  21. " and operacao in ('V', 'C', 'DF') and produto in"
  22. " (SELECT grid FROM produto WHERE codigo_barra = '%s') "
  23. % (rec[1], rec[2], rec[0]))
  24.  
  25. info = curmatriz.fetchone()
  26.  
  27. if info is not None:
  28. #info = info + (rec[3],)
  29. #cigarros[rec[0]] = info + rec
  30. saldo = rec[3] - info[1]
  31. print("[%s] %s = %d" % (rec[0], info[0], saldo))
  32. #print(cigarros[rec[0]])
  33.  
  34. #for rec in
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement