Skip to Content
Menu
This question has been flagged
3542 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]


Avatar
Discard