Advertisement
Guest User

Untitled

a guest
May 30th, 2016
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.99 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. import psycopg2, sys, psycopg2.extras, time
  4.  
  5. order = 4419
  6.  
  7. try:
  8.     con = psycopg2.connect(host='localhost', database='DB01', user='odoo', password='*****')
  9.     cur = con.cursor()
  10.     po_lines = '''SELECT pos_order_line.id, pos_order_line.order_id, product_template.name, pos_order_line.qty, product_template.pos_categ_id
  11.               FROM public.pos_order_line, public.product_template
  12.               WHERE pos_order_line.product_id = product_template.id AND  pos_order_line.order_id = %s
  13.               AND (product_template.pos_categ_id != 5 AND product_template.pos_categ_id != 6)
  14.               ORDER BY pos_order_line.id ASC'''
  15.  
  16.     cur.execute(po_lines,[order]); fetch_lines = cur.fetchall()
  17.     instr = []
  18.     newTable = []
  19.     for i, line in enumerate(fetch_lines):
  20.         print line
  21.         if line[2].startswith('#') or line[2].startswith('----'):
  22.             if line[2].startswith('#'):
  23.                 instr.insert(1," Cortar em dois")
  24.             if line[2].startswith('----'):
  25.                 instr.insert(0, "!SERVIR DEPOIS!")
  26.         elif i == len(fetch_lines):
  27.             newTable.append([line[0], line[1], line[2], line[3], instr])
  28.         elif i < len(fetch_lines):
  29.             newTable.append([line[0], line[1], line[2], line[3], ''])
  30.     print newTable
  31.  
  32. except psycopg2.DatabaseError, e:
  33.     print 'Error %s' % e
  34.     sys.exit(1)
  35.  
  36. finally:
  37.     if con:
  38.         con.close()
  39.  
  40. Result:
  41. /usr/bin/python2.7 /home/effe/PycharmProjects/Odoo_DB_Access/new_divina_pos_test2.py
  42. (12811, 4419, 'Crudo GR', Decimal('1.0'), 1)
  43. (12812, 4419, 'Salame e Grana GR', Decimal('1.0'), 1)
  44. (12813, 4419, '---- servir depois ----', Decimal('1.0'), 7)
  45. (12814, 4419, 'Nutella Ban GR', Decimal('1.0'), 3)
  46. (12815, 4419, '# Cortar em dois', Decimal('1.0'), 7)
  47. [[12811, 4419, 'Crudo GR', Decimal('1.0'), ''], [12812, 4419, 'Salame e Grana GR', Decimal('1.0'), ''], [12814, 4419, 'Nutella Ban GR', Decimal('1.0'), '']]
  48.  
  49. Process finished with exit code 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement