[REF] stock: product quantity stat button
authorRichard Mathot <rim@openerp.com>
Wed, 26 Nov 2014 13:52:56 +0000 (14:52 +0100)
committerRichard Mathot <rim@openerp.com>
Wed, 26 Nov 2014 13:52:56 +0000 (14:52 +0100)
Clean version of stat button of product quantity. Will also work in
creation mode and avoid unuseful computed string field

(fix parts of commit 52c3b52bf09fea7e0920ebcec3f0e8acb066b2b7)

addons/stock/product.py
addons/stock/product_view.xml

index 0dd44af..dd88f00 100644 (file)
@@ -177,7 +177,6 @@ class product_product(osv.osv):
     _columns = {
         'reception_count': fields.function(_stock_move_count, string="Receipt", type='integer', multi='pickings'),
         'delivery_count': fields.function(_stock_move_count, string="Delivery", type='integer', multi='pickings'),
-        'qty_available_text': fields.function(_product_available_text, type='char'),
         'qty_available': fields.function(_product_available, multi='qty_available',
             type='float', digits_compute=dp.get_precision('Product Unit of Measure'),
             string='Quantity On Hand',
@@ -192,6 +191,7 @@ class product_product(osv.osv):
                  "or any of its children.\n"
                  "Otherwise, this includes goods stored in any Stock Location "
                  "with 'internal' type."),
+        'qty_available2': fields.related('qty_available', type="float", relation="product.product", string="On Hand"),
         'virtual_available': fields.function(_product_available, multi='qty_available',
             type='float', digits_compute=dp.get_precision('Product Unit of Measure'),
             string='Forecast Quantity',
@@ -234,11 +234,6 @@ class product_product(osv.osv):
         'orderpoint_ids': fields.one2many('stock.warehouse.orderpoint', 'product_id', 'Minimum Stock Rules'),
     }
 
-    _defaults = {
-        # Dirty hack to avoid empty stat button in create view
-        'qty_available_text': lambda *x: '0.0 On Hand',
-    }
-
     def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
         res = super(product_product,self).fields_view_get(cr, uid, view_id, view_type, context, toolbar=toolbar, submenu=submenu)
         if context is None:
@@ -339,7 +334,7 @@ class product_template(osv.osv):
 
     _columns = {
         'type': fields.selection([('product', 'Stockable Product'), ('consu', 'Consumable'), ('service', 'Service')], 'Product Type', required=True, help="Consumable: Will not imply stock management for this product. \nStockable product: Will imply stock management for this product."),
-        'qty_available_text': fields.function(_product_available_text, type='char'),
+        'qty_available2': fields.related('qty_available', type="float", relation="product.template", string="On Hand"),
         'property_stock_procurement': fields.property(
             type='many2one',
             relation='stock.location',
@@ -386,8 +381,6 @@ class product_template(osv.osv):
 
     _defaults = {
         'sale_delay': 7,
-        # Dirty hack to avoid empty stat button in create view
-        'qty_available_text': lambda *x: '0.0 On Hand',
     }
 
     def action_view_routes(self, cr, uid, ids, context=None):
index e361201..6a47664 100644 (file)
                            name="%(product_open_quants)d"
                            icon="fa-building-o"
                            type="action"  attrs="{'invisible':[('type', '=', 'service')]}" groups="stock.group_locations">
-                    <div><field name="qty_available_text"/></div>
+                        <field name="qty_available2" widget="statinfo"/>
                     </button>
                    <button class="oe_inline oe_stat_button" string="Moves" name= "%(act_product_stock_move_open)d" type="action" attrs="{'invisible':[('type', '=', 'service')]}" groups="stock.group_stock_user" icon="fa-arrows-v"/>
                    <button class="oe_inline oe_stat_button" name="%(product_open_orderpoint)d" type="action" 
                            name="action_open_quants"
                            icon="fa-building-o"
                            type="object"  attrs="{'invisible':[('type', '=', 'service')]}" groups="stock.group_locations">
-                   <div><field name="qty_available_text"/></div>
+                        <field name="qty_available2" widget="statinfo"/>
                    </button>
                    <button class="oe_inline oe_stat_button" string="Moves" name= "action_view_stock_moves" type="object" attrs="{'invisible':[('type', '=', 'service')]}" groups="stock.group_stock_user" icon="fa-arrows-v"/>
                    <button class="oe_inline oe_stat_button" name="action_view_orderpoints" type="object"