# -*- coding: utf-8 -*-

#!/usr/bin/python
# -*- coding: utf-8 -*-
##############################################
#
# ChriCar Beteiligungs- und Beratungs- GmbH
# Copyright (C) ChriCar Beteiligungs- und Beratungs- GmbH
# all rights reserved
# created 2009-08-18 23:44:30+02
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs.
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company.
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU Affero General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/> or
# write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
###############################################
import time
from osv import fields,osv
import pooler

class product_product(osv.osv):
    _inherit = "product.product"
    _order = "name_category,default_code,name_template,variants"

    def _update_category_name(self, cr, uid, ids, context=None):
        product_obj = self.pool.get('product.product')
        product_ids = product_obj.search(cr, uid, [('categ_id','in',ids)])
        return product_ids

    _columns = {
          'name_template': fields.function(_product_name, method=True, string="Product",type='char', size=128, select="1",
          'name_category': fields.related('categ_id', 'name', type="char", size=64, relation="product.category", string="Category",  select="1",
                       store =  { 'product.category' :
                           ( _update_category_name, ['name']
                            , 10)}
                    ),
     }
     # FIXME - not sure if index works if column default_code is empty 
     cr.execute('SELECT indexname FROM pg_indexes WHERE indexname = \'name_category_default_code_name_template_variants_index\'')
     if not cr.fetchone():
         cr.execute('CREATE INDEX name_category_default_code_name_template_variants_index ON product_product(name_category,default_code,name_template,variants);)

     }
product_product()
          

@@ -1888,131 +1888,8 @@
 = %7B%0A
-          'name_template': fields.function(_product_name, method=True, string=%22Product%22,type='char', size=128, select=%221%22,%0A
     
@@ -2214,17 +2214,16 @@
   %7D%0A    
- 
 # FIXME 
@@ -2281,16 +2281,43 @@
  empty %0A
+    def init(self, cr):%0A   
      cr.
@@ -2443,16 +2443,19 @@
 ')%0A     
+   
 if not c
@@ -2469,32 +2469,35 @@
 one():%0A         
+  
+ 
 cr.execute('CREA
@@ -2634,19 +2634,12 @@
 nts)
-;
+'
 )%0A%0A
-     %7D%0A
 prod

create index