grasbauer committed 3680d0e

The method generate_variants is deleting variants if there are no references in the database
(to prevent getting variants twice)
we have to think about this behavior

Comments (0)

Files changed (2)

     _name = 'product.product'
     attribute_values = fields.Many2Many('product.product-attribute.value',
-        'product', 'value', 'Values', readonly=True,
+        'product', 'value', 'Values', readonly=False,
         order=[('value', 'DESC')])
     template = fields.Many2One('product.template', 'Product Template',
         ondelete='CASCADE', select=1,
     def get_variants(self, ids, name):
         res = {}
         for template in self.browse(ids):
-            res[] = len(template.products)
+            res[] = len(template.products) - 1
         return res
     def search_variants(self, name, clause):
     def generate_variants(self, ids):
         """generate variants"""
+        pool = Pool()
+        prod_obj = pool.get('product.product')
         if not ids:
             return False
         for template in self.browse(ids):
             for variant in variants:
                 if not variant in already:
                     self.create_product(template, variant)
-            Pool().get('product.product').delete(to_del)
+            for i in to_del:
+                #this needs a fix:
+                # if there are f.e. stock.moves for a product or it it used in
+                # sales you can't delete it - so we need to check it
+                try:prod_obj.delete(i)
+                except:pass
         return True
                     <xpath expr="/form/notebook/page[@id=&quot;general&quot;]"
                         <page string="Basedescription" col="4" id="description"
-                            states="{'invisible': Not(Bool(Eval('variants')))}">
+                            states="{'invisible': And(Bool(Eval('template')),Bool(Eval('variants')))}">
                             <field name="basedescription" colspan="4"/>
+                        <field name="basecode"/> 
                         <field name="variants"/>   
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.