Skip to Content
Menu
This question has been flagged

ean13 is stored in product_product table:

id | ean13 | create_date | default_code | name_template |    ...   | active

----+---------------+----------------------------+--------------+---------------+------------+-------------------+-----------------+---------------+-----------+----------------------------+--------

  32 | 2910000000185 | 2015-07-11 10:08:14.009873 | | FOOBAR1 | 1 | | 51 | | 1 | 2015-07-11 10:08:14.009873 | t


however, you can not recover ean13 from product_product attributes


print product_fields

[{'ean13': False, 'id': 32, 'name_template': u'FOOBAR1'}]

print product_id32.ean13

False

print product_id32.name_template

FOOBAR1


How do I recover ean13 value for a given product?

 

Avatar
Discard
Best Answer

Please explain more deeply what you need/want to archive, because I use EAN codes from my external programs every day.

For example, if you need a very simple program for Python based on id search:

import psycopg2, sys, psycopg2.extras
try:
con = psycopg2.connect(host='localhost', database='Database', user='xxxxxx', password='xxxxxx')
cur = con.cursor()
sql_query = 'Select id, name_template, ean13 from product_product where id = %s'
idt = '66'
cur.execute(sql_query,[idt]); product_fields = cur.fetchone()
print product_fields
print 'id:', product_fields[0]
print 'name_template:', product_fields[1]
print 'ean13:', product_fields[2]
except psycopg2.DatabaseError, e:
print 'Error %s' % e
sys.exit(1)
finally:
if con:
con.close()

output :

/usr/bin/python2.7 /home/effe/.PyCharm40/config/scratches/scratch
(66, 'Formaggi', '1002000000003')
id: 66
name_template: Formaggi
ean13: 1002000000003
Process finished with exit code 0

Or from a quick query for a specific EAN13 from Postgres:

Select id, name_template, ean13 from product_product where ean13 = '1002000000003'

 

id
product_template
Ean13
66 
Formaggi
1002000000003

Both examples are simple to edit for your needs. 

Avatar
Discard
Author

Thanks for your answer and examples The question arised while trying to modify "create" method to add automatically an EAN13 code when a product is created. As 'ean13' is a field of 'product.product' initially you start modifying 'create' method for 'product.product', but the EAN13 code is actually managed and populated via 'create' method in 'product.template' (so 'create' method for 'product.product' has no visibility on the EAN13 entered by the user). Once business logic is moved into 'create' 'product.template' instead of 'product.product', it is easy to complete the task.

Now is clear.
Since I prefer manage Odoo externally trough Python to have a full control I don't have a deep knowledge of internal coding. Anyway, did you try to inherit the table adding a fields.related or compiling a simple fields.char it via on_change?

Author

I am not sure if on_change applies here, I have used once for on-the-fly calculations in a form. I guess there might be a way to trigger some code when a new product is added, which might fit in this scenario. Regarding the approach I was looking for, as the field is already there (ean13 in product_product table), it was just a matter of doing something if user has not entered EAN13, so I think that the "right" approach is to modify the method create adding the required logic. There might be other or better approaches though; I am far from having a sound knowledge of Odoo.

Related Posts Replies Views Activity
0
Jul 15
2508
1
May 16
2669
1
Feb 23
5756
6
Oct 15
7776
1
Jul 24
1981