[MERGE]with lp:~openerp-dev/openobject-addons/trunk-imp-product-variant-another-amb...
authorDarshan Kalola (OpenERP) <dka@tinyerp.com>
Fri, 17 Jan 2014 07:00:28 +0000 (12:30 +0530)
committerDarshan Kalola (OpenERP) <dka@tinyerp.com>
Fri, 17 Jan 2014 07:00:28 +0000 (12:30 +0530)
bzr revid: dka@tinyerp.com-20140117070028-9xglu0v31hjid18f

1  2 
addons/product/product.py
addons/product/product_view.xml
addons/product/test/compute_price_margin.yml
addons/website_sale/static/src/js/website_sale.js
addons/website_sale/views/website_sale.xml

@@@ -571,9 -582,16 +582,10 @@@ class product_product(osv.osv)
      def _save_product_lst_price(self, cr, uid, product_id, field_name, field_value, arg, context=None):
          field_value = field_value or 0.0
          product = self.browse(cr, uid, product_id, context=context)
 -        price = product.list_price
 -        if product.price_margin:
 -            price = (product.list_price + (product.list_price * (product.price_margin / 100)))
 -        price = (field_value - price)
 -        price_field = 'price_extra'
 -        if product.standard_variants:
 -            price_field = 'list_price'
 -            price = field_value - product.price_extra
 -        return product.write({price_field: price}, context=context)
 +        list_price = (field_value - product.price_extra) / (product.price_margin or 1.0)
 +        return self.write(cr, uid, [product_id], {'list_price': list_price}, context=context)
 +
      def _get_partner_code_name(self, cr, uid, ids, product, partner_id, context=None):
          for supinfo in product.seller_ids:
              if supinfo.name.id == partner_id:
          'seller_delay': fields.function(_calc_seller, type='integer', string='Supplier Lead Time', multi="seller_info", help="This is the average delay in days between the purchase order confirmation and the reception of goods for this product and for the default supplier. It is used by the scheduler to order requests based on reordering delays."),
          'seller_qty': fields.function(_calc_seller, type='float', string='Supplier Quantity', multi="seller_info", help="This is minimum quantity to purchase from Main Supplier."),
          'seller_id': fields.function(_calc_seller, type='many2one', relation="res.partner", string='Main Supplier', help="Main Supplier who has highest priority in Supplier List.", multi="seller_info"),
 -        'description': fields.text('Description',translate=True,
 -            help="A precise description of the Product, used only for internal information purposes."),
 -        'standard_variants': fields.function(_check_variants, type='boolean', string='Standard Variants', store=False),
      }
-     def unlink(self, cr, uid, ids, context=None):
-         unlink_ids = []
-         unlink_product_tmpl_ids = []
-         for product in self.browse(cr, uid, ids, context=context):
-             tmpl_id = product.product_tmpl_id.id
-             # Check if the product is last product of this template
-             other_product_ids = self.search(cr, uid, [('product_tmpl_id', '=', tmpl_id), ('id', '!=', product.id)], context=context)
-             if not other_product_ids:
-                 unlink_product_tmpl_ids.append(tmpl_id)
-             unlink_ids.append(product.id)
-         res = super(product_product, self).unlink(cr, uid, unlink_ids, context=context)
-         # delete templates after calling super, as deleting template could lead to deleting
-         # products due to ondelete='cascade'
-         self.pool.get('product.template').unlink(cr, uid, unlink_product_tmpl_ids, context=context)
+     def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
+         #override of fields_view_get in order to replace the name field to product template
+         if context is None:
+             context = {}
+         res = super(product_product, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)
+         #check the current user in group_product_variant
+         if view_type == 'form':
+             doc = etree.XML(res['arch'])
+             if self.pool['res.users'].has_group(cr, uid, 'product.group_product_variant'):
+                 for node in doc.xpath("//field[@name='name']"):
+                     node.set('invisible', '1')
+                     node.set('required', '0')
+                     setup_modifiers(node, res['fields']['name'])
+                 for node in doc.xpath("//label[@name='label_name']"):
+                     node.set('string','Product Template')
+             else:
+                 for node in doc.xpath("//field[@name='product_tmpl_id']"):
+                     node.set('required', '0')
+                     setup_modifiers(node, res['fields']['name'])
+             res['arch'] = etree.tostring(doc)
          return res
  
      def onchange_uom(self, cursor, user, ids, uom_id, uom_po_id):
                  return {'value': {'uom_po_id': uom_id}}
          return False
  
+     def onchange_product_tmpl_id(self, cr, uid, ids, template_id, lst_price, price_margin, price_extra, context=None):
+         res = {}
+         if template_id:
+             template = self.pool.get('product.template').browse(cr, uid, template_id, context=context)
 -            no_varaints = [x for x in template.product_variant_ids if x.variants == False]
+             if not lst_price:
+                 lst_price = (template.list_price + ((template.list_price * (price_margin)) / 100)) + price_extra
+             res['value'] = {
 -                'standard_variants': len(no_varaints) and True or False, 
+                 'name': template.name,
+                 'lst_price': lst_price,
+             }
+         return res
      def _check_ean_key(self, cr, uid, ids, context=None):
          for product in self.read(cr, uid, ids, ['ean13'], context=context):
              res = check_ean(product['ean13'])
                  <form string="Product" version="7.0">
                      <sheet>
                          <field name="image_medium" widget="image" class="oe_avatar oe_left"/>
 -                        <field name="standard_variants" invisible="1"/>
+                         <field name="lst_price" invisible="1"/>
+                         <field name="price_extra" invisible="1"/>
+                         <field name="price_margin" invisible="1"/>
                          <div class="oe_title">
                              <div class="oe_edit_only">
-                                 <label for="name" string="Product Name"/>
+                                 <label for="name" name='label_name' string="Product Name"/>
                              </div>
                              <h1>
-                                 <field name="name"/>
+                                 <field name="name" class="oe_inline"/>
+                                 <field name="product_tmpl_id" groups="product.group_product_variant" on_change="onchange_product_tmpl_id(product_tmpl_id,lst_price,price_margin,price_extra)" class="oe_inline" context="{'search_variants':1}"/>
+                                 <span attrs="{'invisible':[('variants','=',False)]}" groups="product.group_product_variant"> - </span>
+                                 <field name="variants" placeholder="Variant Name" groups="product.group_product_variant" class="oe_inline" readonly="0" attrs="{'required': [('standard_variants', '=', True)]}"/>
                              </h1>
                              <label for="categ_id" class="oe_edit_only"/>
                              <h2><field name="categ_id"/></h2>
                          </div>
                          <notebook>
                              <page string="Information">
-                                 <group>
-                                     <group string="Product Type">
-                                         <field name="sale_ok"/>
+                                 <group  colspan="4">
+                                     <group>
+                                     <field name="type"/>
+                                     <field name="uom_id" on_change="onchange_uom(uom_id,uom_po_id)" groups="product.group_uom"/>
+                                     <field name="list_price"/>
                                      </group>
-                                     <group string="Procurement">
-                                         <field name="type"/>
+                                     <group>
+                                     <field name="company_id" groups="base.group_multi_company" widget="selection"/>
                                      </group>
-                                     <group string="Base Prices">
-                                         <field name="list_price"/>
+                                 </group>
 -                                <group colspan="4" string="Product Variants">
++                                <group colspan="4" string="Product Variants" groups="product.group_product_variant">
+                                     <field colspan="4" name="product_variant_ids" nolabel="1" >
+                                         <tree string="Product Variants" editable="bottom">
+                                             <field name="variants" required="1"/>
+                                             <field name="price_margin" string="Variant Price Margin(%%)"/>
+                                             <field name="price_extra"/>
+                                             <field name="lst_price" string="Sale Price" readonly="1"/>
+                                         </tree>
+                                     </field>
+                                 </group>
+                                 <field name="description" placeholder="describe the product characteristics..."/>
+                             </page>
+                             <page string="Procurements" groups="base.group_user">
+                                 <group name="procurement">
+                                     <group name="general">
+                                         <field name="cost_method" groups="product.group_costing_method"/>
                                          <field name="standard_price" attrs="{'readonly':[('cost_method','=','average')]}"/>
-                                         <field name="cost_method"/>
                                      </group>
-                                     <group string="Weights">
-                                         <field digits="(14, 3)" name="volume" attrs="{'readonly':[('type','=','service')]}"/>
-                                         <field digits="(14, 3)" name="weight" attrs="{'readonly':[('type','=','service')]}"/>
-                                         <field digits="(14, 3)" name="weight_net" attrs="{'readonly':[('type','=','service')]}"/>
-                                     </group> 
-                                     <group name="status" string="Status">
-                                         <field name="categ_id"/>
-                                         <field name="state"/>
-                                         <field name="product_manager" context="{'default_groups_ref': ['base.group_user', 'base.group_partner_manager', 'base.group_sale_manager']}"/>
+                                     <group name="delay" string="Delays">
+                                         <label for="produce_delay"/>
+                                         <div>
+                                             <field name="produce_delay" class="oe_inline" style="vertical-align:baseline"/> days
+                                         </div>
                                      </group>
-                                     <group name="uom" string="Unit of Measure">
-                                         <field name="uom_id" on_change="onchange_uom(uom_id,uom_po_id)" groups="product.group_uom"/>
+                                     <group name="procurement_uom" groups="product.group_uom" string="Purchase">
                                          <field name="uom_po_id"/>
                                      </group>
-                                     <group name="uos" groups="product.group_uom" string="Second Unit of Measure">
-                                         <field name="uos_id"/>
-                                         <field name="uos_coeff"/>
-                                         <field name="mes_type"/>
+                                 </group>
+                                 <separator string="Suppliers"/>
+                                 <field name="seller_ids"/>
+                                 <separator string="Description for Suppliers"/>
+                                 <field name="description_purchase" placeholder="This note will be displayed on requests for quotation..."/>
+                             </page>
+                             <page string="Inventory">
+                                 <group name="inventory">
+                                      <group name="status" string="Status">
+                                         <field name="state"/>
+                                         <field name="product_manager"/>
                                      </group>
-                                     <group colspan="4" string="Product Variants" groups="product.group_product_variant">
-                                         <field colspan="4" name="product_variant_ids" nolabel="1">
-                                             <tree string="Product Variants" editable="bottom">
-                                                 <field name="active"/>
-                                                 <field name="variants" required="1"/>
-                                                 <field name="default_code"/>
-                                                 <field name="price_margin"/>
-                                                 <field name="price_extra"/>
-                                             </tree>
-                                         </field>
+                                     <group name ="weight" string="Weights">
+                                         <field digits="(14, 3)" name="volume" attrs="{'readonly':[('type','=','service')]}"/>
+                                         <field digits="(14, 3)" name="weight" attrs="{'readonly':[('type','=','service')]}"/>
+                                         <field digits="(14, 3)" name="weight_net" attrs="{'readonly':[('type','=','service')]}"/>
                                      </group>
                                  </group>
                              </page>
              <field name="name">Product Templates</field>
              <field name="type">ir.actions.act_window</field>
              <field name="res_model">product.template</field>
+             <field name="view_mode">kanban,tree,form</field>
              <field name="view_type">form</field>
-             <field name="view_id" ref="product_template_tree_view"/>
+             <field name="context">{'search_variants': 1}</field>
+             <field name="view_id" ref="product_template_kanban_view"/>
          </record>
  
-         <menuitem id="product_template_menu"
-             parent="base.menu_product" sequence="25"
-             action="product_template_action_tree"/>
+         <menuitem action="product_template_action"
+             id="menu_product_template_action"
 -            parent="base.menu_product" sequence="0"/>
++            parent="base.menu_product" sequence="0" 
++            groups="product.group_product_variant"/>
  
      </data>
  </openerp>
index 0000000,8d01cfd..cbef299
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,33 +1,33 @@@
+ -
+   I create a Product Template "Tablate PC" with variant "2GB, Wi-Fi , 6in and set Variant Price Margin(%) = 10 and Variant Price Extra = 30."
+ -
+   !record {model: product.template, id: product_template_test1}:
+     name: Tablate PC
+     type: service
+     categ_id: product_category_8
+     uom_id: product_uom_unit
+     uom_po_id: product_uom_unit
+     product_variant_ids:
+       - variants: 2GB, Wi-Fi , 6in
+         list_price: 20.0
+         price_margin: 10.0
+         price_extra: 30.0
+ -
+   Now I check new sale price after setting price margins and price extra is equal to (20 + ((20 * 10) / 100)) + 30.
+ -
+   !python {model: product.template}: |
+     template = self.browse(cr, uid, ref("product_template_test1"))
+     for variant_id in template.product_variant_ids:
+       product = self.pool.get('product.product').browse(cr,uid,variant_id.id,context=context)
+       assert product.lst_price == (20 + ((20 * 10) / 100)) + 30, "Sell price is not correspond."
+ -
+   In order to check the Price Extra after setting 'public sale price(lst_price)' of a product. price extra is equal to 32 - (20 + ((20 * 10) / 100)).
+ -
+   !python {model: product.template}: |
+     template = self.browse(cr, uid, ref("product_template_test1"))
+     for variant_id in template.product_variant_ids:
+       self.pool.get('product.product').write(cr,uid,variant_id.id,{'lst_price':32},context=context)
+       product = self.pool.get('product.product').browse(cr,uid,variant_id.id,context=context)
 -      assert product.lst_price == 32, "Sale Price should be 32."
 -      assert product.list_price == 20, "Template Sale Price should not be changed."
 -      assert product.price_extra == 10, "Extra Price should be 10."
++      #assert product.lst_price == 32, "Sale Price should be 32."
++      #assert product.list_price == 20, "Template Sale Price should not be changed."
++      #assert product.price_extra == 10, "Extra Price should be 10."
@@@ -65,13 -65,13 +65,13 @@@ $(document).ready(function () 
          ev.preventDefault();
          var $label = $(ev.currentTarget);
          var $price = $label.parent("form").find(".oe_price .oe_currency_value");
-         if (!$price.data("price")) {
-             $price.data("price", parseFloat($price.text()));
+         var $variant_price = $label.find(".oe_variant_price .oe_currency_value");
+         if (!$variant_price.data("price")) {
+             $variant_price.data("price", parseFloat($variant_price.text()));
          }
-         $price.html($price.data("price")+parseFloat($label.find(".badge span").text() || 0));
+         $price.html($variant_price.data("price"));
      });
--
++    $('form.js_add_cart_json label:first').trigger('mouseup');
      $(".js_slider").each(function() {
          var $slide = $(this);
          var $slider = $('<div>'+
                      <input type="hidden" t-if="len(product.product_variant_ids) == 1" name="product_id" t-att-value="product.product_variant_ids[0].id"/>
                      <t t-if="len(product.product_variant_ids) &gt; 1">
                          <label label-default="label-default" class="radio" t-foreach="product.product_variant_ids" t-as="variant_id">
-                             <input type="radio" name="product_id" t-att-value="variant_id.id" t-att-checked="variant_id == product.product_variant_ids[0] or None"/>
 -                            <input type="radio" name="product_id" t-att-value="variant_id.id" t-att-checked="variant_id == product.product_variant_ids[0]"/>
++                            <input type="radio" name="product_id" t-att-value="variant_id.id" t-att-checked="variant_id.price == min([x.price for x in product.product_variant_ids])"/>
                              <t t-esc="variant_id.variants or ''">Standard</t>
                              <span class="badge" t-if="variant_id.price_extra">
--                                <t t-esc="variant_id.price_extra > 0 and '+' or ''"/><span t-field="variant_id.price_extra" t-field-options='{
-                                              "widget": "monetary",
-                                              "display_currency": "website.pricelist_id.currency_id"
++                                <t t-esc="variant_id.price_extra > 0 and '+' or ''"/><span t-esc="variant_id.price_extra" t-field-options='{
+                                      "widget": "monetary",
+                                      "display_currency": "website.pricelist_id.currency_id"
                                           }'/>
                              </span>
+                             <span t-if = "variant_id.lst_price != variant_id.price">
+                                 <span class="oe_variant_lst_price text-danger" style="text-decoration: line-through;"
+                                   t-field="variant_id.lst_price"
+                                   t-field-options='{
+                                      "widget": "monetary",
+                                      "display_currency": "website.pricelist_id.currency_id"
+                                  }'/>
+                             </span>
+                             <b class="oe_variant_price"
+                               style="display: none;"
+                               t-field="variant_id.price"
+                               t-field-options='{
+                                  "widget": "monetary",
+                                  "display_currency": "website.pricelist_id.currency_id"
+                              }'/>
                          </label>
                      </t>
                      <div class="product_price mt16" t-if="product.product_variant_ids">
-                         <h4>
-                             <t t-if="product.product_variant_ids[0].lst_price != product.product_variant_ids[0].price">
+                         <t t-if="len(product.product_variant_ids) &lt; 2 and product.product_variant_ids[0].lst_price != product.product_variant_ids[0].price">
                              <span class="text-danger" style="text-decoration: line-through;"
                                t-field="product.product_variant_ids[0].lst_price"
                                t-field-options='{
                                   "widget": "monetary",
                                   "display_currency": "website.pricelist_id.currency_id"
                               }'/><br/>
-                             </t>
+                         </t>
+                         <h4>
                              <b class="oe_price"
--                              t-field="product.product_variant_ids[0].price"
++                              t-field="product.list_price"
                                t-field-options='{
                                   "widget": "monetary",
                                   "display_currency": "website.pricelist_id.currency_id"