Commits

grasbauer  committed 0517640

Fixes according codereview

  • Participants
  • Parent commits 112a86a

Comments (0)

Files changed (3)

File configuration.xml

 <?xml version="1.0"?>
-    <!--
-        This file is part of Tryton. The COPYRIGHT file at the top level of
-        this repository contains the full copyright notices and license terms.
-    -->
+<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
+this repository contains the full copyright notices and license terms. -->
 <tryton>
     <data>
-        <menuitem name="Variant Configuration" 
+        <menuitem name="Product Configuration" 
             parent="product.menu_main_product"
             sequence="10" id="menu_product_configuration" 
             groups="product.group_product_admin"/>
             <field name="type">form</field>
             <field name="arch" type="xml">
                 <![CDATA[
-                <form string="Code Separator">
+                <form string="Variant Configuration">
                     <label name="code_separator"/>
                     <field name="code_separator"/>
                 </form>
             </field>
         </record>
 
-        <record model="ir.action.act_window" id="act_variant_configuration_form">
+        <record model="ir.action.act_window" 
+            id="act_variant_configuration_form">
             <field name="name">Variant Configuration</field>
             <field name="res_model">product.variant.configuration</field>
         </record>
 
-        <record model="ir.action.act_window.view" id="act_product_configuration_view1">
+        <record model="ir.action.act_window.view" 
+            id="act_product_configuration_view1">
             <field name="sequence" eval="10"/>
-            <field name="view" ref="act_variant_configuration_form"/>
+            <field name="view" ref="configuration_view_form"/>
             <field name="act_window" ref="act_variant_configuration_form"/>
         </record>
         
-        <menuitem parent="menu_product_configuration" id="menu_variant_configuration"
+        <menuitem parent="menu_product_configuration" 
+            id="menu_variant_configuration"
             action="act_variant_configuration_form"
             sequence="10" icon="tryton-list"
             groups="product.group_product_admin"/>
 
     attribute_values = fields.Many2Many('product.product-attribute.value',
         'product', 'value', 'Values', readonly=True)
-    template = fields.Many2One('product.template', 'Product Template',
-        ondelete='CASCADE', select=1,
-        states={
+
+    def __init__(self):
+        super(Product, self).__init__()
+        self.template.states = copy.copy(self.template.states)
+
+        states = {
             'required':Greater(Eval('active_id', 0), 0),
             'invisible':Not(Greater(Eval('active_id', 0), 0)),
             'readonly':Not(Bool(Eval('variant')))
-        })
+        }
+        for state, pyson in states.iteritems():
+            if not self.template.states.get(state):
+                self.template.states[state] = pyson
+            else:
+                self.template.states[state] = \
+                    Or(self.template.states[state],
+                    pyson)
 
     def create(self, values):
-        if not values.get('template'):
+        if values.get('template'):
             values = values.copy()
             values.pop('template')
         return super(Product, self).create(values)
 class Template(ModelSQL, ModelView):
     _name = "product.template"
 
-    basecode = fields.Char('Basecode',
+    template_code = fields.Char('Template Code',
+        required=True,
         states={
             'invisible': Not(Bool(Eval('attributes')))
-        }, depends=['attributes'])
+            }, depends=['attributes'])
     attributes = fields.Many2Many('product.template-product.attribute',
         'template', 'attribute', 'Attributes')
-    variant = fields.Function(fields.Boolean('Variant', select=1),
-        'get_variants', searcher="search_variant")
-    basedescription = fields.Text("Basedescription", translate=True)
+    variant = fields.Function(fields.Boolean('Variant'),
+        'get_variants', searcher='search_variants')
+    template_description = fields.Text("Template Description", translate=True)
 
     def __init__(self):
         super(Template, self).__init__()
         self._rpc.update({
             'generate_variants': True,
         })
-
+        #still here - but later in in product module
         for column in self._columns.itervalues():
             already = False
+            column.states = copy.copy(column.states)
             if 'readonly' in column.states:
                 already = column.states['readonly']
             column.states = {'readonly': Or(And(Bool(Eval('template')),
                 res[template.id] = True
         return res
 
-    def search_variant(self, name, clause):
+    def search_variants(self, name, clause):
         res = []
-        ids = self.search([('id', '>', 0)])
+        cursor = Transaction().cursor
+        cursor.execute('SELECT id FROM "' + self._table + '" WHERE True ')
+        ids = [i[0] for i in cursor.fetchall()]
         records = self.browse(ids)
         if clause[2] == True:
             for template in records:
                     res.append(template.id)
         return [('id', 'in', res)]
 
-    def create_code(self, basecode, variant):
+    def create_code(self, template_code, variant):
+        "Create code based on template and attributes"
         config_obj = self.pool.get('product.variant.configuration')
         config = config_obj.browse(1)
         sep = config.code_separator or ''
-        code = '%s%s' % (basecode or '', ['', sep][bool(basecode)])
+        code = '%s%s' % (template_code or '', ['', sep][bool(template_code)])
         code = code + sep.join(i.code for i in variant)
         return code
 
     def create_product(self, template, variant):
-        "create the product"
+        "Create product from template based on variant"
         product_obj = self.pool.get('product.product')
         value_obj = self.pool.get('product.product-attribute.value')
-        code = self.create_code(template.basecode, variant)
+        code = self.create_code(template.template_code, variant)
         new_id = product_obj.create({'template':template.id,
             'code':code})
         for value in variant:
         return True
 
     def generate_variants(self, ids):
-        """generate variants"""
+        """Generate variants"""
         if not ids:
             return {}
         res = {}
     _description = __doc__
 
     sequence = fields.Integer('Sequence')
-    name = fields.Char('Name', required=True, translate=True, select=1)
+    name = fields.Char('Name', required=True, translate=True)
     values = fields.One2Many('product.attribute.value', 'attribute', 'Values')
 
     def __init__(self):
     _description = __doc__
 
     sequence = fields.Integer('Sequence')
-    name = fields.Char('Name', required=True, select=1)
+    name = fields.Char('Name', required=True, translate=True)
     code = fields.Char('Code', required=True)
     attribute = fields.Many2One('product.attribute', 'Product Attribute',
         required=True)
     _description = __doc__
 
     attribute = fields.Many2One('product.attribute', 'Product Attribute',
-            ondelete='RESTRICT', required=True)
+            ondelete='RESTRICT', required=True, select=True)
     template = fields.Many2One('product.template', 'Product template',
-            ondelete='CASCADE', required=True)
+            ondelete='CASCADE', required=True, select=True)
 
 ProductTemplateAttribute()
 
     _description = __doc__
 
     product = fields.Many2One('product.product', 'Product',
-            ondelete='CASCADE', required=True)
+            ondelete='CASCADE', required=True, select=True)
     value = fields.Many2One('product.attribute.value', 'Attribute Value',
-            ondelete='CASCADE', required=True)
+            ondelete='RESTRICT', required=True, select=True)
 
 ProductAttributeValue()
 <?xml version="1.0"?>
-    <!--
-        This file is part of Tryton. The COPYRIGHT file at the top level of
-        this repository contains the full copyright notices and license terms.
-    -->
+<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
+this repository contains the full copyright notices and license terms. -->
 <tryton>
     <data>
         <record model="ir.ui.view" id="product_view_form">
                 <data>
                     <xpath expr="/form/field[@name=&quot;active&quot;]"
                         position="after">
-                        <label name="basecode"/>
-                        <field name="basecode"/>
+                        <label name="template_code"/>
+                        <field name="template_code"/>
                     </xpath>
                     <xpath expr="/form/notebook/page[@id=&quot;general&quot;]"
                         position="after">
                     </xpath>
                     <xpath expr="/form/notebook/page[@id=&quot;general&quot;]"
                         position="after">
-                        <page string="Basedescription" col="4" id="description"
+                        <page string="Template Description" col="4" id="description"
                             states="{'invisible': Not(Bool(Eval('variant')))}">
-                            <field name="basedescription" colspan="4"/>
+                            <field name="template_description" colspan="4"/>
                         </page>
                     </xpath>
                     <xpath expr="/form/notebook/page[@id=&quot;general&quot;]"
         </record>
 
         <menuitem name="Templates" parent="product.menu_main_product"
-            sequence="10" id="menu_product_template" action="act_template_form"/>
+            sequence="1" id="menu_product_template" action="act_template_form"/>
 
         <record model="ir.action.act_window" id="act_product_attribute_form">
             <field name="name">Product Attributes</field>