Reviewers: ,


Please review this at http://codereview.tryton.org/246002/

Affected files:
  M trytond/modules/stock/location.py
  M trytond/modules/stock/product.py
  M trytond/modules/stock/product.xml


Index: trytond/modules/stock/location.py
===================================================================

--- a/trytond/modules/stock/location.py
+++ b/trytond/modules/stock/location.py
@@ -1,6 +1,7 @@
 #This file is part of Tryton.  The COPYRIGHT file at the top level of
 #this repository contains the full copyright notices and license terms.
 import datetime
+from decimal import Decimal
 from trytond.model import ModelView, ModelSQL, fields
 from trytond.wizard import Wizard, StateView, Button, StateAction
 from trytond.backend import TableHandler
@@ -82,6 +83,8 @@
     quantity = fields.Function(fields.Float('Quantity'), 'get_quantity')
     forecast_quantity = fields.Function(fields.Float('Forecast Quantity'),
             'get_quantity')
+    cost_value = fields.Function(fields.Numeric('Cost Value'),
+        'get_quantity')

     def __init__(self):
         super(Location, self).__init__()
@@ -156,7 +159,7 @@
                 return dict([(i, 0) for i in ids])

         context = {}
-        if (name == 'quantity'
+        if (name in ('quantity', 'cost_value')
                 and Transaction().context.get('stock_date_end') >
                 date_obj.today()):
             context['stock_date_end'] = date_obj.today()
@@ -171,6 +174,11 @@
                     product_ids=[Transaction().context['product']],
                     with_childs=True, skip_zero=False).iteritems()

+        if name == 'cost_value':
+            product = product_obj.browse(Transaction().context['product'])
+            return dict((loc, Decimal(str(qty)) * product.cost_price)
+                for (loc, prod), qty in pbl)
+
         return dict([(loc,qty) for (loc,prod), qty in pbl])

     def _set_warehouse_parent(self, locations):

Index: trytond/modules/stock/product.py
===================================================================

--- a/trytond/modules/stock/product.py
+++ b/trytond/modules/stock/product.py
@@ -1,6 +1,7 @@
 #This file is part of Tryton.  The COPYRIGHT file at the top level of
 #this repository contains the full copyright notices and license terms.
 import datetime
+from decimal import Decimal
 from trytond.model import ModelView, ModelSQL, fields
 from trytond.wizard import Wizard, StateView, StateAction, Button
 from trytond.pyson import PYSONEncoder
@@ -15,10 +16,12 @@
     quantity = fields.Function(fields.Float('Quantity'), 'get_quantity')
     forecast_quantity = fields.Function(fields.Float('Forecast Quantity'),
             'get_quantity')
+    cost_value = fields.Function(fields.Numeric('Cost Value'),
+        'get_quantity')

     def get_quantity(self, ids, name):
         res = {}
-        if name not in ('quantity', 'forecast_quantity'):
+        if name not in ('quantity', 'forecast_quantity', 'cost_value'):
             raise Exception('Bad argument')

         for template in self.browse(ids):
@@ -66,6 +69,8 @@
             searcher='search_quantity')
     forecast_quantity = fields.Function(fields.Float('Forecast Quantity'),
             'get_quantity', searcher='search_quantity')
+    cost_value = fields.Function(fields.Numeric('Cost Value'),
+        'get_quantity')

     def get_quantity(self, ids, name):
         date_obj = Pool().get('ir.date')
@@ -74,7 +79,7 @@
             return dict((id, 0.0) for id in ids)

         context = {}
-        if (name == 'quantity'
+        if (name in ('quantity', 'cost_value')
                 and Transaction().context.get('stock_date_end')
                 and Transaction().context.get('stock_date_end') >
                 date_obj.today()):
@@ -93,6 +98,10 @@
         for location in Transaction().context['locations']:
             for product in ids:
                 res[product] += pbl.get((location, product), 0.0)
+        if name == 'cost_value':
+            for product in self.browse(ids):
+                res[product.id] = (Decimal(str(res[product.id]))
+                    * product.cost_price)
         return res

     def _search_quantity_eval_domain(self, line, domain):

Index: trytond/modules/stock/product.xml
===================================================================

--- a/trytond/modules/stock/product.xml
+++ b/trytond/modules/stock/product.xml
@@ -13,6 +13,7 @@
                         <field name="name"/>
                         <field name="code"/>
                         <field name="quantity"/>
+                        <field name="cost_value"/>
                         <field name="forecast_quantity"/>
                         <field name="default_uom"/>
                         <field name="type"/>
@@ -33,6 +34,7 @@
                         <field name="name"/>
                         <field name="quantity"/>
                         <field name="forecast_quantity"/>
+                        <field name="cost_value"/>
                         <field name="parent" tree_invisible="1"/>
                         <field name="childs" tree_invisible="1"/>
                     </tree>



--
[email protected] mailing list

Reply via email to