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
- order = 4419
- try:
- con = psycopg2.connect(host='localhost', database='DB01', 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, product_template.pos_categ_id
- FROM public.pos_order_line, public.product_template
- WHERE pos_order_line.product_id = product_template.id AND pos_order_line.order_id = %s
- AND (product_template.pos_categ_id != 5 AND product_template.pos_categ_id != 6)
- ORDER BY pos_order_line.id ASC'''
- cur.execute(po_lines,[order]); fetch_lines = cur.fetchall()
- instr = []
- newTable = []
- for i, line in enumerate(fetch_lines):
- print line
- if line[2].startswith('#') or line[2].startswith('----'):
- if line[2].startswith('#'):
- instr.insert(1," Cortar em dois")
- if line[2].startswith('----'):
- instr.insert(0, "!SERVIR DEPOIS!")
- elif i == len(fetch_lines):
- newTable.append([line[0], line[1], line[2], line[3], instr])
- elif i < len(fetch_lines):
- newTable.append([line[0], line[1], line[2], line[3], ''])
- print newTable
- 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/new_divina_pos_test2.py
- (12811, 4419, 'Crudo GR', Decimal('1.0'), 1)
- (12812, 4419, 'Salame e Grana GR', Decimal('1.0'), 1)
- (12813, 4419, '---- servir depois ----', Decimal('1.0'), 7)
- (12814, 4419, 'Nutella Ban GR', Decimal('1.0'), 3)
- (12815, 4419, '# Cortar em dois', Decimal('1.0'), 7)
- [[12811, 4419, 'Crudo GR', Decimal('1.0'), ''], [12812, 4419, 'Salame e Grana GR', Decimal('1.0'), ''], [12814, 4419, 'Nutella Ban GR', Decimal('1.0'), '']]
- Process finished with exit code 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement