Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2016
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.29 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. import psycopg2, sys, psycopg2.extras, time, pdb
  4. import operator
  5.  
  6. order = 4558 # ordine test 4558
  7.  
  8. try:
  9.     con = psycopg2.connect(host='localhost', database='DB', user='odoo', password='******')
  10.  
  11.     cur = con.cursor()
  12.  
  13.     po_lines = '''SELECT pos_order_line.id, pos_order_line.order_id, product_template.name, pos_order_line.qty,
  14.               res_partner.name
  15.                FROM  public.pos_order, public.pos_order_line, public.product_template,
  16.                public.res_partner, public.pos_category
  17.                WHERE pos_order.partner_id = res_partner.id AND pos_order_line.order_id = pos_order.id
  18.                AND (product_template.pos_categ_id != 5 AND product_template.pos_categ_id != 6)
  19.                AND pos_order_line.order_id = pos_order.id
  20.                AND pos_order_line.product_id = product_template.id AND pos_category.id = product_template.pos_categ_id
  21.                AND pos_order_line.qty > 0 AND pos_order_line.order_id = %s
  22.                ORDER BY pos_order_line.id asc'''
  23.  
  24.  
  25.  
  26.     cur.execute(po_lines,[order]); fetch_lines = cur.fetchall()
  27.     fetch_lines = sorted(fetch_lines, key=operator.itemgetter(2))
  28.     print fetch_lines
  29.     newTable = []
  30.     Intr = ''
  31.     LineCt = 0
  32.  
  33.     for line in fetch_lines:
  34.         if line[2].startswith('#') or line[2].startswith('----'):
  35.             if line[2].startswith('#'):
  36.                 Intr = Intr + line[2][2:]
  37.                 LineCt += 1
  38.             if line[2].startswith('----'):
  39.                 Intr = '!SERVIR DEPOIS!' + Intr
  40.                 LineCt += 1
  41.  
  42.     for i, line in enumerate(fetch_lines):
  43.         if line[2].startswith('#') or line[2].startswith('----'):
  44.             pass
  45.         elif i == len(fetch_lines) - LineCt:
  46.             newTable.append([line[0], line[1], line[2], Intr, ""])
  47.             Intr = ''
  48.         elif i < len(fetch_lines):
  49.             newTable.append([line[0], line[1], line[2], '', ""])
  50.  
  51.     print Intr
  52.     nt = sorted(newTable, key=operator.itemgetter(0))
  53.     for e in nt:
  54.         print e
  55.  
  56. except psycopg2.DatabaseError, e:
  57.     print 'Error %s' % e
  58.     sys.exit(1)
  59.  
  60. finally:
  61.     if con:
  62.         con.close()
  63. -------------------
  64. Result:
  65.  
  66. /usr/bin/python2.7 /home/effe/PycharmProjects/Odoo_DB_Access/test_pos.py
  67. [(13266, 4558, '# + Alface', Decimal('1.0'), 'Mesa 11'), (13265, 4558, '# + Champinhons', Decimal('1.0'), 'Mesa 11'), (13267, 4558, '# - R\xc3\xbacola', Decimal('1.0'), 'Mesa 11'), (13269, 4558, '# Cortar em dois', Decimal('1.0'), 'Mesa 11'), (13272, 4558, '# Cortar em dois', Decimal('1.0'), 'Mesa 11'), (13275, 4558, '# Para Levar', Decimal('1.0'), 'Mesa 11'), (13270, 4558, '---- servir depois ----', Decimal('1.0'), 'Mesa 11'), (13273, 4558, '---- servir depois ----', Decimal('1.0'), 'Mesa 11'), (13268, 4558, 'Formaggi GR', Decimal('1.0'), 'Mesa 11'), (13264, 4558, 'Funghi GR', Decimal('1.0'), 'Mesa 11'), (13271, 4558, 'Nutella GR', Decimal('1.0'), 'Mesa 11'), (13274, 4558, 'Nutella Mor MD', Decimal('1.0'), 'Mesa 11')]
  68. ------------------
  69. !SERVIR DEPOIS!!SERVIR DEPOIS!+ Alface+ Champinhons- RúcolaCortar em doisCortar em doisPara Levar
  70. [13264, 4558, 'Funghi GR', '', '']
  71. [13268, 4558, 'Formaggi GR', '', '']
  72. [13271, 4558, 'Nutella GR', '', '']
  73. [13274, 4558, 'Nutella Mor MD', '', '']
  74.  
  75. Process finished with exit code 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement