Advertisement
Guest User

Untitled

a guest
May 31st, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.22 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='Divina_DB01', user='odoo', password='ik0kil')
  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.                 instr = instr + " Cortar em dois"
  25.                 print instr
  26.             if line[2].startswith('----'):
  27.                 #instr.insert(0, "!SERVIR DEPOIS!")
  28.                 instr = '!SERVIR DEPOIS!' + instr
  29.                 print instr
  30.         elif i == len(fetch_lines):
  31.             newTable.append([line[0], line[1], line[2], line[3], instr])
  32.         elif i < len(fetch_lines):
  33.             newTable.append([line[0], line[1], line[2], line[3], ''])
  34.     print newTable
  35.  
  36. except psycopg2.DatabaseError, e:
  37.     print 'Error %s' % e
  38.     sys.exit(1)
  39.  
  40. finally:
  41.     if con:
  42.         con.close()
  43.  
  44. --------------------
  45. Result:
  46.  
  47. /usr/bin/python2.7 /home/effe/PycharmProjects/Odoo_DB_Access/new_divina_pos_test2.py
  48. (12811, 4419, 'Crudo GR', Decimal('1.0'), 1)
  49. (12812, 4419, 'Salame e Grana GR', Decimal('1.0'), 1)
  50. (12813, 4419, '---- servir depois ----', Decimal('1.0'), 7)
  51. !SERVIR DEPOIS!
  52. (12814, 4419, 'Nutella Ban GR', Decimal('1.0'), 3)
  53. (12815, 4419, '# Cortar em dois', Decimal('1.0'), 7)
  54. !SERVIR DEPOIS! Cortar em dois
  55. [[12811, 4419, 'Crudo GR', Decimal('1.0'), ''], [12812, 4419, 'Salame e Grana GR', Decimal('1.0'), ''], [12814, 4419, 'Nutella Ban GR', Decimal('1.0'), '']]
  56.  
  57. Process finished with exit code 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement