Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- import psycopg2, sys, psycopg2.extras, time, pdb
- import operator
- order = 4558 # ordine test 4558
- try:
- con = psycopg2.connect(host='localhost', database='DB', user='odoo', password='******')
- cur = con.cursor()
- po_lines = '''SELECT pos_order_line.id, pos_order_line.order_id, product_template.name, pos_order_line.qty,
- res_partner.name
- FROM public.pos_order, public.pos_order_line, public.product_template,
- public.res_partner, public.pos_category
- WHERE pos_order.partner_id = res_partner.id AND pos_order_line.order_id = pos_order.id
- AND (product_template.pos_categ_id != 5 AND product_template.pos_categ_id != 6)
- AND pos_order_line.order_id = pos_order.id
- AND pos_order_line.product_id = product_template.id AND pos_category.id = product_template.pos_categ_id
- AND pos_order_line.qty > 0 AND pos_order_line.order_id = %s
- ORDER BY pos_order_line.id asc'''
- cur.execute(po_lines,[order]); fetch_lines = cur.fetchall()
- fetch_lines = sorted(fetch_lines, key=operator.itemgetter(2))
- print fetch_lines
- newTable = []
- Intr = ''
- LineCt = 0
- for line in fetch_lines:
- if line[2].startswith('#') or line[2].startswith('----'):
- if line[2].startswith('#'):
- Intr = Intr + line[2][2:]
- LineCt += 1
- if line[2].startswith('----'):
- Intr = '!SERVIR DEPOIS!' + Intr
- LineCt += 1
- for i, line in enumerate(fetch_lines):
- if line[2].startswith('#') or line[2].startswith('----'):
- pass
- elif i == len(fetch_lines) - LineCt:
- newTable.append([line[0], line[1], line[2], Intr, ""])
- Intr = ''
- elif i < len(fetch_lines):
- newTable.append([line[0], line[1], line[2], '', ""])
- print Intr
- nt = sorted(newTable, key=operator.itemgetter(0))
- for e in nt:
- print e
- except psycopg2.DatabaseError, e:
- print 'Error %s' % e
- sys.exit(1)
- finally:
- if con:
- con.close()
- -------------------
- Result:
- /usr/bin/python2.7 /home/effe/PycharmProjects/Odoo_DB_Access/test_pos.py
- [(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')]
- ------------------
- !SERVIR DEPOIS!!SERVIR DEPOIS!+ Alface+ Champinhons- RúcolaCortar em doisCortar em doisPara Levar
- [13264, 4558, 'Funghi GR', '', '']
- [13268, 4558, 'Formaggi GR', '', '']
- [13271, 4558, 'Nutella GR', '', '']
- [13274, 4558, 'Nutella Mor MD', '', '']
- Process finished with exit code 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement