Odoo Help


[SOLVED]: Selection field and action - how to pass value to the method ?

Dr Obx
on 3/21/16, 11:32 AM 560 views


I have one fields.boolean, one fields.selection and def get_list(self.cr,uid, fields, context=None):

and depending on the selection and boolean, I would like to search table and create a CSV.

But I can't get value from field selection and boolean for this action, it tells me ...global name not defined or other errors like that.

How can I pass value within the form to make this action work ?


class stock_list(osv.osv):

_name = 'stock.list'

_description = 'List of products and quantities CSV creator'

_columns = {

'location_1': fields.boolean('Production - 7'),

'location_2': fields.boolean('Suppliers - 8'),

'location_3': fields.boolean('Inventory loss - 5'),

'location_4': fields.boolean('Customers - 9'),

'list_body': fields.html('List'),

'product': fields.char('Product'),

'product_lines': fields.selection([





('Storage_device','Storage device'),

('Optical_drive','Optical drive'),

('RAM_module','RAM module'),

('Graphics_card','Graphics card'),

('Storage_controller','Storage controller'),

('Power_supply','Power supply'),




('Case_part','Case part'),


('Internal_component','Internal component')], 'Product type', help='Select a prodct type.', require=True),

'quantity': fields.float('Quantity'),

'location': fields.char('Location ID'),


def get_list(self, cr, uid, fields, name, context=None):

obj = self.pool.get('stock.list')

print obj

print '===================================================================================================='

obj_id = obj.search(cr, uid,[('product_lines','=',False)])

print obj_id

print '===================================================================================================='

# la = self._columns['location_1']

# print la

# lb = self._columns['location_2']

# print lb

# lc = self._columns['location_3']

# print lc

# ld = self._columns['location_4']

# print ld

pl = self._columns['product_lines']

print pl

s = 'Processor'

print ''

body = '-------------------------------------------------------------------------------------------------\n'

body += '| ID | Name | Condition |Qty |\n'

body += '|-----|--------------------------------------------------------------------|------------|-------|\n'

cr.execute(""" SELECT id, name, condition FROM product_template WHERE product_lines_id ilike '%s' and sale_ok = '%s';""" %(self._columns['product_lines'],True))

products = cr.fetchall()

for product in products:

if product:

cr.execute(""" SELECT sum(qty) FROM stock_quant WHERE product_id = '%s' and location_id != '%s' and location_id != '%s' and location_id != '%s' GROUP BY product_id;"""%(product[0], 5,7,9))#4 - scrapped, 6 - Procurements,

quantity = cr.fetchall()

if quantity:

id = product[0]

name = ' '.join(product[1].split())[:68]

cond = product[2]

qty = quantity[0][0]

body += "|{:<5}|{:<68}|{:<12}|{:>7}|\n".format(id,name,cond,qty)

body += '-------------------------------------------------------------------------------------------------\n'

print body


About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 3/21/16, 11:32 AM
Seen: 560 times
Last updated: 3/23/16, 6:39 PM