Odoo Help

Welcome!

This community 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.

0

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

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

Guys,

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 ?

[code]

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([

('Computer','Computer'),

('Server','Server'),

('Laptop','Laptop'),

('Processor','Processor'),

('Storage_device','Storage device'),

('Optical_drive','Optical drive'),

('RAM_module','RAM module'),

('Graphics_card','Graphics card'),

('Storage_controller','Storage controller'),

('Power_supply','Power supply'),

('Monitor','Monitor'),

('Motherboard','Motherboard'),

('Cable','Cable'),

('Case_part','Case part'),

('Peripheral','Peripheral'),

('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

[/code]


Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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