Reviewers: ,


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

Affected files:
  M __init__.py
  M ir.py
  M product.py


Index: __init__.py
===================================================================

--- a/__init__.py
+++ b/__init__.py
@@ -1,5 +1,16 @@
 #This file is part of Tryton.  The COPYRIGHT file at the top level of
 #this repository contains the full copyright notices and license terms.

+from trytond.pool import Pool
 from .ir import *
 from .product import *
+
+
+def register():
+    Pool.register(
+        Property,
+        ProductCostHistory,
+        module='product_cost_history', type_='model')
+    Pool.register(
+        OpenProductCostHistory,
+        module='product_cost_history', type_='wizard')

Index: ir.py
===================================================================

--- a/ir.py
+++ b/ir.py
@@ -1,10 +1,11 @@
 #This file is part of Tryton.  The COPYRIGHT file at the top level of
 #this repository contains the full copyright notices and license terms.
-from trytond.model import ModelView, ModelSQL
+from trytond.pool import PoolMeta

+__all__ = ['Property']
+__metaclass__ = PoolMeta

-class Property(ModelSQL, ModelView):
-    _name = 'ir.property'
+
+class Property:
+    __name__ = 'ir.property'
     _history = True
-
-Property()

Index: product.py
===================================================================

--- a/product.py
+++ b/product.py
@@ -6,24 +6,27 @@
 from trytond.pool import Pool
 from trytond.transaction import Transaction

+__all__ = ['ProductCostHistory', 'OpenProductCostHistory']
+

 class ProductCostHistory(ModelSQL, ModelView):
     'History of Product Cost'
-    _name = 'product.product.cost_history'
-    _description = __doc__
+    __name__ = 'product.product.cost_history'
     _rec_name = 'date'
-
     template = fields.Many2One('product.template', 'Product')
     date = fields.DateTime('Date')
     cost_price = fields.Numeric('Cost Price')

-    def __init__(self):
-        super(ProductCostHistory, self).__init__()
-        self._order.insert(0, ('date', 'DESC'))
+    @classmethod
+    def __setup__(cls):
+        super(ProductCostHistory, cls).__setup__()
+        cls._order.insert(0, ('date', 'DESC'))

-    def table_query(self):
-        property_obj = Pool().get('ir.property')
-        field_obj = Pool().get('ir.model.field')
+    @staticmethod
+    def table_query():
+        pool = Pool()
+        Property = pool.get('ir.property')
+        Field = pool.get('ir.model.field')
         return ('SELECT '
                     'MAX(h.__id) AS id, '
                     'MAX(h.create_uid) AS create_uid, '
@@ -34,38 +37,33 @@
'CAST(TRIM(\',\' FROM SUBSTRING(h.res FROM \',.*\')) AS '
                         'INTEGER) AS template, '
'CAST(TRIM(\',\' FROM h.value) AS NUMERIC) AS cost_price '
-                'FROM "' + property_obj._table + '__history" h '
- 'JOIN "' + field_obj._table + '" f ON (f.id = h.field) '
+                'FROM "' + Property._table + '__history" h '
+                    'JOIN "' + Field._table + '" f ON (f.id = h.field) '
                 'WHERE f.name = \'cost_price\' '
                     'AND h.res LIKE \'product.template,%%\' '
'GROUP BY h.id, COALESCE(h.write_date, h.create_date), h.res, '
                     'h.value',
                 [])

-ProductCostHistory()
-

 class OpenProductCostHistory(Wizard):
     'Open Product Cost History'
-    _name = 'product.product.cost_history.open'
+    __name__ = 'product.product.cost_history.open'
     start_state = 'open'
-
open = StateAction('product_cost_history.act_product_cost_history_form')

-    def do_open(self, session, action):
+    def do_open(self, action):
         pool = Pool()
-        product_obj = pool.get('product.product')
+        Product = pool.get('product.product')

         active_id = Transaction().context.get('active_id')
         if not active_id or active_id < 0:
             action['pyson_domain'] = PYSONEncoder().encode([
-                ('template', '=', False),
-            ])
+                    ('template', '=', None),
+                    ])
         else:
-            product = product_obj.browse(active_id)
+            product = Product(active_id)
             action['pyson_domain'] = PYSONEncoder().encode([
-                ('template', '=', product.template.id),
-            ])
+                    ('template', '=', product.template.id),
+                    ])
         return action, {}
-
-OpenProductCostHistory()



--
[email protected] mailing list

Reply via email to