← Back to team overview

openerp-community team mailing list archive

lp:~camptocamp/openerp-product-attributes/6.1-fix-1259215-quickcreate-lep into lp:openerp-product-attributes/6.1

 

Leonardo Pistone @ camptocamp has proposed merging lp:~camptocamp/openerp-product-attributes/6.1-fix-1259215-quickcreate-lep into lp:openerp-product-attributes/6.1.

Requested reviews:
  Product Core Editors (product-core-editors)
Related bugs:
  Bug #1259215 in OpenERP Product Attributes: "production_lot_custom_attributes: quick create attribute from group form, KeyError: 'attribute_type' "
  https://bugs.launchpad.net/openerp-product-attributes/+bug/1259215

For more details, see:
https://code.launchpad.net/~camptocamp/openerp-product-attributes/6.1-fix-1259215-quickcreate-lep/+merge/198619
-- 
https://code.launchpad.net/~camptocamp/openerp-product-attributes/6.1-fix-1259215-quickcreate-lep/+merge/198619
Your team OpenERP Community is subscribed to branch lp:openerp-product-attributes/6.1.
=== modified file 'base_custom_attributes/custom_attributes.py'
--- base_custom_attributes/custom_attributes.py	2013-12-11 14:53:28 +0000
+++ base_custom_attributes/custom_attributes.py	2013-12-11 17:25:07 +0000
@@ -245,21 +245,33 @@
                  "but not in the database"),
         }
 
+    def name_create(self, cr, uid, name, context=None):
+        if context is None:
+            context = {}
+        rec_id = self.create(cr, uid, {
+            'field_description': name,
+            'name': 'x_{0}'.format(name),
+        }, context=context)
+        return self.name_get(cr, uid, [rec_id], context)[0]
+
     def create(self, cr, uid, vals, context=None):
         if vals.get('relation_model_id'):
             relation = self.pool.get('ir.model').read(
                 cr, uid, [vals.get('relation_model_id')], ['model'])[0]['model']
         else:
             relation = 'attribute.option'
-        if vals['attribute_type'] == 'select':
+        if vals.get('attribute_type') == 'select':
             vals['ttype'] = 'many2one'
             vals['relation'] = relation
-        elif vals['attribute_type'] == 'multiselect':
+        elif vals.get('attribute_type') == 'multiselect':
             vals['ttype'] = 'many2many'
             vals['relation'] = relation
             vals['serialized'] = True
         else:
-            vals['ttype'] = vals['attribute_type']
+            vals['ttype'] = (
+                vals.get('attribute_type')
+                or self._defaults.get('attribute_type')
+            )
 
         if vals.get('serialized'):
             field_obj = self.pool.get('ir.model.fields')
@@ -322,7 +334,8 @@
         return None
 
     _defaults = {
-        'model_id': _get_default_model
+        'model_id': _get_default_model,
+        'attribute_type': 'char',
     }
 
 


Follow ups