Commits

Raimon Esteve (Zikzakmedia) committed 50fdefd

Active Record

  • Participants
  • Parent commits 73c891c

Comments (0)

Files changed (8)

+Version 2.6.0 - 2012-10-15
+* Active Record
+* Simplify module information with python configuration
+
 Version 2.4.0 - 2012-09-24
 * Initial release
 ==================================
 
 The product_price_list_formula module of the Tryton application platform.
-See __tryton__.py
 
 Installing
 ----------
 #The COPYRIGHT file at the top level of this repository contains 
 #the full copyright notices and license terms.
 
-from .product_price_list import *
+from trytond.pool import Pool
+from .price_list import *
+
+def register():
+    Pool.register(
+        PriceList,
+        PriceListLine,
+        module='product_price_list_formula', type_='model')

__tryton__.py

-#This file is part product_price_list_formula module for Tryton.
-#The COPYRIGHT file at the top level of this repository contains 
-#the full copyright notices and license terms.
-{
-    'name': 'Product Price List Formula',
-    'name_ca_ES': 'Formules tarifes de producte',
-    'name_es_ES': 'Formulas tarifas de producto',
-    'version': '2.4.0',
-    'author': 'Zikzakmedia',
-    'email': 'zikzak@zikzakmedia.com',
-    'website': 'http://www.zikzakmedia.com/',
-    'description': '''Add party and product in formula price list rules by parties.''',
-    'description_ca_ES': '''Afegeix party i product a les formules per les regles de tarifa per tercer.''',
-    'description_es_ES': 'Añade party y product a las fórmulas para las reglas de tarifa por tercero.',
-    'depends': [
-        'ir',
-        'res',
-        'product_price_list',
-    ],
-    'xml': [
-    ],
-    'translation': [
-        'locale/ca_ES.po',
-        'locale/es_ES.po',
-    ]
-}
+#This file is part product_price_list_formula module for 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, fields
+from trytond.tools import safe_eval, datetime_strftime
+from trytond.transaction import Transaction
+from trytond.pool import Pool, PoolMeta
+
+from decimal import Decimal
+
+__all__ = ['PriceList', 'PriceListLine']
+__metaclass__ = PoolMeta
+
+class PriceList:
+    __name__ = 'product.price_list'
+
+    @classmethod
+    def __setup__(cls):
+        super(PriceList, cls).__setup__()
+        cls._error_messages.update({
+            'not_found_price_list': 'Not found price list: %s!',
+        })
+
+    def _get_context_price_list_line(self, party, product, unit_price,
+            quantity, uom):
+        '''
+        Add party and product available in formula
+
+        :param party: the BrowseRecord of the party.party
+        :param product: the BrowseRecord of the product.product
+        :param unit_price: a Decimal for the default unit price in the
+            company's currency and default uom of the product
+        :param quantity: the quantity of product
+        :param uom: the BrowseRecord of the product.uom
+        :return: a dictionary
+        '''
+        res = super(PriceList, self)._get_context_price_list_line(
+            party, product, unit_price, quantity, uom)
+        res['product'] = product
+        res['party'] = party
+        res['quantity'] = quantity
+        res['price_list'] = Pool().get('product.price_list')
+        return res
+
+    @classmethod
+    def compute_price_list(self, price_list):
+        '''
+        Compute price based another price list
+
+        :param price_list: the price list id or the BrowseRecord of the
+            product.price_list
+        :return: the computed unit price
+        '''
+        if isinstance(price_list, (int, long)):
+            price_list = self(price_list)
+
+        try:
+            price_list.name
+        except:
+            self.raise_user_error('not_found_price_list', price_list)
+
+        quantity=0
+        product = Transaction().context['product']
+        return self.compute(
+                        price_list,
+                        Transaction().context['customer'],
+                        product, 
+                        Transaction().context['unit_price'],
+                        quantity,
+                        Transaction().context.get('uom', product.default_uom))
+
+
+class PriceListLine:
+    'Price List Line'
+    __name__ = 'product.price_list.line'
+
+    def check_formula(self):
+        '''
+        Check formula
+        Add new params test in context: product, customer and price list object
+        '''
+        pool = Pool()
+        PriceList = pool.get('product.price_list')
+        context = PriceList()._get_context_price_list_line(None, None,
+                Decimal('0.0'), 0, None)
+
+        product = pool.get('product.product').search([
+            ('salable', '=', True),
+            ], 0, 1, None)[0]
+        context['product'] =  pool.get('product.product')(product)
+        customer = pool.get('party.party').search([], 0, 1, None)[0]
+        context['customer'] = pool.get('party.party')(customer)
+        context['price_list'] = pool.get('product.price_list')
+
+        with Transaction().set_context(**context):
+            try:
+                if not isinstance(self.get_unit_price(), Decimal):
+                    return False
+            except Exception:
+                return False
+        return True

product_price_list.py

-#This file is part product_price_list_formula module for 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, fields
-from trytond.tools import safe_eval, datetime_strftime
-from trytond.transaction import Transaction
-from trytond.pool import Pool
-
-from decimal import Decimal
-
-class PriceList(ModelSQL, ModelView):
-    _name = 'product.price_list'
-
-    def __init__(self):
-        super(PriceList, self).__init__()
-        self._error_messages.update({
-            'not_found_price_list': 'Not found price list: %s!',
-        })
-
-    def _get_context_price_list_line(self, party, product, unit_price,
-            quantity, uom):
-        '''
-        Add party and product available in formula
-
-        :param party: the BrowseRecord of the party.party
-        :param product: the BrowseRecord of the product.product
-        :param unit_price: a Decimal for the default unit price in the
-            company's currency and default uom of the product
-        :param quantity: the quantity of product
-        :param uom: the BrowseRecord of the product.uom
-        :return: a dictionary
-        '''
-        res = super(PriceList, self)._get_context_price_list_line(
-            party, product, unit_price, quantity, uom)
-        res['product'] = product
-        res['party'] = party
-        res['quantity'] = quantity
-        res['price_list'] = Pool().get('product.price_list')
-        return res
-
-    def compute_price_list(self, price_list):
-        '''
-        Compute price based another price list
-
-        :param price_list: the price list id or the BrowseRecord of the
-            product.price_list
-        :return: the computed unit price
-        '''
-        if isinstance(price_list, (int, long)):
-            price_list = self.browse(price_list)
-
-        try:
-            price_list.name
-        except:
-            self.raise_user_error('not_found_price_list', price_list)
-
-        quantity=0
-        product = Transaction().context['product']
-
-        res = self.compute(
-                        price_list,
-                        Transaction().context['customer'],
-                        product, 
-                        Transaction().context['unit_price'],
-                        quantity,
-                        Transaction().context.get('uom', product.default_uom))
-        return res
-
-PriceList()
-
-class PriceListLine(ModelSQL, ModelView):
-    'Price List Line'
-    _name = 'product.price_list.line'
-
-    def check_formula(self, ids):
-        '''
-        Check formula
-        Add new params test in context: product, customer and price list object
-        '''
-        price_list_obj = Pool().get('product.price_list')
-        context = price_list_obj._get_context_price_list_line(None, None,
-                Decimal('0.0'), 0, None)
-
-        product = Pool().get('product.product').search([
-            ('salable', '=', True),
-            ], 0, 1, None)[0]
-        context['product'] =  Pool().get('product.product').browse(product)
-        customer = Pool().get('party.party').search([], 0, 1, None)[0]
-        context['customer'] = Pool().get('party.party').browse(customer)
-        context['price_list'] = Pool().get('product.price_list')
-
-        lines = self.browse(ids)
-        with Transaction().set_context(**context):
-            for line in lines:
-                try:
-                    if not isinstance(self.get_unit_price(line), Decimal):
-                        return False
-                except Exception:
-                    return False
-        return True
-
-PriceListLine()
 
 from setuptools import setup
 import re
+import os
+import ConfigParser
 
-info = eval(open('__tryton__.py').read())
+config = ConfigParser.ConfigParser()
+config.readfp(open('tryton.cfg'))
+info = dict(config.items('tryton'))
+for key in ('depends', 'extras_depend', 'xml'):
+    if key in info:
+        info[key] = info[key].strip().splitlines()
 major_version, minor_version, _ = info.get('version', '0.0.1').split('.', 2)
 major_version = int(major_version)
 minor_version = int(minor_version)
 
 setup(name='trytond_product_price_list_formula',
     version=info.get('version', '0.0.1'),
-    description=info.get('description', ''),
-    author=info.get('author', 'Zikzakmedia'),
-    author_email=info.get('email', 'zikzak@zikzakmedia.com'),
-    url=info.get('website', 'http://www.zikzakmedia.com'),
+    description='Tryton module to add formulas in product price list',
+    author='Zikzakmedia SL',
+    author_email='zikzak@zikzakmedia.com',
+    url='http://www.zikzakmedia.com',
     download_url="https://bitbucket.org/zikzakmedia/trytond-product_price_list_formula",
     package_dir={'trytond.modules.product_price_list_formula': '.'},
     packages=[
+[tryton]
+version=2.6.0
+depends:
+    ir
+    res
+    product_price_list
+xml: