Odoo Help


Openerp AttributeError: 'NoneType' object has no attribute '_columns'

Ashish Singh
on 12/24/14, 7:20 AM 2,085 views

in which scenario we get following error

AttributeError: 'NoneType' object has no attribute '_columns'

When i just install 'product_custom_attributes_shop' in V7 then i got error.

How to resolve this error

@Kumar Please post your code here, which will give better idea to resolve the issue

Emipro Technologies Pvt. Ltd.
on 12/24/14, 7:42 AM

product.py from openerp.osv.orm import Model from openerp.osv import fields from openerp.osv.osv import except_osv import netsvc from lxml import etree from openerp.tools.translate import _ import re class product_product(Model): _inherit = "product.product" def _build_shop_attributes_notebook(self, cr, uid, shops, context=None): notebook = etree.Element('notebook', name="shop_attributes_notebook", colspan="4") toupdate_fields = [] for shop in shops: page = etree.SubElement(notebook, 'page', string=shop.name.capitalize()) for attribute in shop.shop_attribute_ids: toupdate_fields.append(attribute.name) self._build_attribute_field(cr, uid, page, attribute, context=context) return notebook, toupdate_fields def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False): result = super(product_product, self).fields_view_get(cr, uid, view_id,view_type,context,toolbar=toolbar, submenu=submenu) if view_type == 'form': eview = etree.fromstring(result['arch']) info_page = eview.xpath("//page[@string='Information']") if info_page: info_page = info_page[0] shop_obj = self.pool.get('sale.shop') shop_ids = shop_obj.search(cr, uid, [], context=context) shops = [] for shop in shop_obj.browse(cr, uid, shop_ids, context=context): if shop.shop_attribute_ids: shops.append(shop) if shops: attributes_notebook, toupdate_fields = self._build_shop_attributes_notebook(cr, uid, shops, context=context) result['fields'].update(self.fields_get(cr, uid, toupdate_fields, context)) main_page = etree.Element('page', string=_('Shop Attributes')) main_page.append(attributes_notebook) info_page.addnext(main_page) result['arch'] = etree.tostring(eview, pretty_print=True) result = self._fix_size_bug(cr, uid, result, context=context) return result def check_if_activable(self, cr, uid, vals, context=None): categ_ids = [vals['categ_id']] + vals.get('categ_ids', []) for key in vals.keys(): if re.match('x_shop.*?_attr_active', key) and vals[key]: shop_id = int(key.replace('x_shop', '').replace('_attr_active', '')) if not self.pool.get('product.category').check_if_in_shop_category(cr, uid, categ_ids, shop_id, context=context): shop = self.pool.get('sale.shop').browse(cr, uid, shop_id, context=context) raise except_osv( _("User Error"), _("The product must be in an children of one of this categories \"%s\" " "in order to be activable on the shop \"%s\"") %('", "'.join([categ.name for categ in shop.exportable_root_category_ids]), shop.name)) def create(self, cr, uid, vals, context=None): if context is None: context={} if not context.get('do_not_check_active_field_on_shop'): vals['categ_ids'] = vals.get('categ_ids', [(6,0,[])])[0][2] self.check_if_activable(cr, uid, vals, context=context) return super(product_product, self).create(cr, uid, vals, context=context) def write(self, cr, uid, ids, vals, context=None): if context is None: context={} need_check = False if not context.get('do_not_check_active_field_on_shop'): for key in vals.keys(): if re.match('x_shop.*?_attr_active', key) and vals[key] or key in ('categ_id', 'categ_ids'): need_check = True break res = super(product_product, self).write(cr, uid, ids, vals, context=context) if need_check: if not hasattr(ids, '__iter__'): ids = [ids] field_to_read = ['categ_ids', 'categ_id'] + [key for key in self._columns if re.match('x_shop.*?_attr_active', key)] for product in self.read(cr, uid, ids, field_to_read, context=context): product['categ_id'] = product['categ_id'][0] self.check_if_activable(cr, uid, product, context=context) return res product_product() class product_category(Model): _inherit = 'product.category' def check_if_in_shop_category(self, cr, uid, categ_ids, shop_id, context=None): exportable_category_ids = self.pool.get('sale.shop').read(cr, uid, shop_id, ['exportable_category_ids'])['exportable_category_ids'] for categ_id in categ_ids: if categ_id in exportable_category_ids: return True return False product_category() Product_attribute.py from openerp.osv.orm import Model from openerp.osv import fields import netsvc class attribute_shop_location(Model): _name = "attribute.shop.location" _description = "Attribute Shop Location" _order="sequence" _inherits = {'product.attribute': 'attribute_id'} _columns = { 'attribute_id': fields.many2one('product.attribute', 'Product Attribute', required=True, ondelete="cascade"), 'shop_id': fields.many2one('sale.shop', 'Shop', required=True), 'sequence': fields.integer('Sequence'), 'external_name': fields.char('External Name', size=128, required=True), } attribute_shop_location() sale.py ------------ from openerp.osv.orm import Model from openerp.osv import fields import netsvc class sale_shop(Model): _inherit = "sale.shop" def _get_exportable_product_ids(self, cr, uid, ids, name, args, context=None): res = {} for shop in self.browse(cr, uid, ids, context=context): res[shop.id] = self.pool.get('product.product').search(cr, uid, [['x_shop%s_attr_active'%shop.id, '=', True], ['active', '=', True]], context=context) return res _columns = { 'shop_attribute_ids': fields.one2many('attribute.shop.location', 'shop_id', 'Attributes'), 'exportable_product_ids': fields.function(_get_exportable_product_ids, method=True, type='one2many', relation="product.product", string='Exportable Products'), } def _prepare_attribute_shop_fields(self, cr, uid, context=None): return {'name': 'char', 'description': 'text', 'active': 'boolean'} def generate_shop_attributes(self, cr, uid, ids, context=None): attr_loc_obj = self.pool.get('attribute.shop.location') attr_obj = self.pool.get('product.attribute') model_id = self.pool.get('ir.model').search(cr, uid, [('model', '=', 'product.product')], context=context)[0] for shop in self.browse(cr, uid, ids, context=context): fields = self._prepare_attribute_shop_fields(cr, uid, context=context) for field, field_type in fields.items(): attribute_loc_ids = attr_loc_obj.search(cr, uid, [('shop_id', '=', shop.id),('external_name', '=', field)], context=context) if not attribute_loc_ids: field_name = 'x_shop%s_attr_%s' %(shop.id, field) prod_attribute_ids = attr_obj.search(cr, uid, [('name', '=', field_name)], context=context) if not prod_attribute_ids: vals = { 'name': field_name, 'field_description': field, 'attribute_type': field_type, 'based_on': 'product_product', 'translate': field_type in ('char', 'text'), } prod_attribute_id = attr_obj.create(cr, uid, vals, context=context) else: prod_attribute_id = prod_attribute_ids[0] attribute_id = attr_loc_obj.create(cr, uid, { 'external_name': field, 'attribute_id': prod_attribute_id, 'shop_id': shop.id }, context=context) attribute_loc_ids.append(attribute_id) return attribute_loc_ids sale_shop() __openerp__.py ------------------------------- { 'name': 'product_custom_attributes_shop', 'version': '6.1.1', 'category': 'Generic Modules/Others', 'license': 'AGPL-3', 'description': """ This module give the posibility to manage different value for special field (like name, description, metadata....) per shop. Indeed when you sale on an e-shop you must have for exemple a different description per product (ranking problem). This that module you will be able to add in the shop tab of the product a description per shop. """, 'author': 'Akretion', 'website': 'http://www.akretion.com/', 'depends': [ 'base_sale_multichannels', 'product_custom_attributes', 'sale', 'product', ], 'init': [], 'update': [ 'sale_view.xml', 'product_attribute_view.xml', 'security/ir.model.access.csv', ], 'demo': [], 'installable': True, 'active' : False, } product_attribute_view.xml -------------------------------------------- attribute.shop.location.form attribute.shop.location form attribute.shop.location.tree attribute.shop.location tree sale_view.xml ---------------------------- product_custom_attributs_shop.sale_shop.view_form sale.shop form <xpath expr="/form/notebook/page[@string='Extra Information']" position="after">

Ashish Singh
on 12/24/14, 8:11 AM
Umashankar Subramani
On 12/26/14, 6:17 AM


    I am new to odoo, i tried to give you some hint regarding the question.

    Nonetype means that function or instance of whatever Class or Object not working with you, you've actually got none. That means the function returns none.

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

2 follower(s)


Asked: 12/24/14, 7:20 AM
Seen: 2085 times
Last updated: 3/16/15, 8:10 AM