Raimon Esteve (Zikzakmedia) avatar Raimon Esteve (Zikzakmedia) committed 04a8e50

Active Record

Comments (0)

Files changed (7)

+Version 2.6.0 - 2012-10-15
+* Active Record
+* Simplify module information with python configuration
+
 Version 2.4.0 - 2012-09-25
 * Initial release
 ===================================
 
 The product_price_list_category 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 trytond.pool import Pool
 from .price_list import *
+
+
+def register():
+    Pool.register(
+        PriceList,
+        PriceListLine,
+        module='product_price_list_category', type_='model')

__tryton__.py

-#This file is part product_price_list_category 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 Category',
-    'name_ca_ES': 'Tarifes de producte per categoria',
-    'name_es_ES': 'Tarifas de producto por categoría',
-    'version': '2.4.0',
-    'author': 'Zikzakmedia',
-    'email': 'zikzak@zikzakmedia.com',
-    'website': 'http://www.zikzakmedia.com/',
-    'description': '''Define price list rules by category.''',
-    'description_ca_ES': '''Defineix regles de tarifa per categoria.''',
-    'description_es_ES': 'Define reglas de tarifa por categoría.',
-    'depends': [
-        'ir',
-        'res',
-        'product_price_list',
-    ],
-    'xml': [
-        'price_list.xml',
-    ],
-    'translation': [
-        'locale/ca_ES.po',
-        'locale/es_ES.po',
-    ]
-}
 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 trytond.pool import Pool, PoolMeta
 
-class PriceList(ModelSQL, ModelView):
+__all__ = ['PriceList', 'PriceListLine']
+__metaclass__ = PoolMeta
+
+class PriceList:
     'Price List'
-    _name = 'product.price_list'
+    __name__ = 'product.price_list'
 
-    def compute(self, price_list, party, product, unit_price, quantity, uom,
+    def compute(self, party, product, unit_price, quantity, uom,
             pattern=None):
         '''
         Compute price based on price list of party
 
-        :param price_list: the price list id or the BrowseRecord of the
-            product.price_list
-        :param party: the party id or the BrowseRecord of the party.party
-        :param product: the product id or 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 UOM id or the BrowseRecord of the product.uom
+        :param uom: a instance of the product.uom
         :param pattern: a dictionary with price list field as key
             and match value as value
         :return: the computed unit price
         '''
-        pool = Pool()
-        party_obj = pool.get('party.party')
-        product_obj = pool.get('product.product')
-        uom_obj = pool.get('product.uom')
-        price_list_line_obj = pool.get('product.price_list.line')
 
-        if not price_list:
-            return unit_price
-
-        if isinstance(price_list, (int, long)):
-            price_list = self.browse(price_list)
-
-        if isinstance(party, (int, long)):
-            party = party_obj.browse(party)
-
-        if isinstance(product, (int, long)):
-            product = product_obj.browse(product)
-
-        if isinstance(uom, (int, long)):
-            uom = uom_obj.browse(uom)
+        Uom = Pool().get('product.uom')
 
         if pattern is None:
             pattern = {}
 
         pattern = pattern.copy()
+        pattern['product'] = product and product.id or None
         pattern['category'] = product.category and product.category.id or None
-        pattern['product'] = product and product.id or None
-        pattern['quantity'] = uom_obj.compute_qty(uom, quantity,
+        pattern['quantity'] = Uom.compute_qty(uom, quantity,
                 product.default_uom, round=False)
-        
-        for line in price_list.lines:
-            if price_list_line_obj.match(line, pattern):
+
+        for line in self.lines:
+            if line.match(pattern):
                 with Transaction().set_context(
                         self._get_context_price_list_line(party, product,
                             unit_price, quantity, uom)):
-                    return price_list_line_obj.get_unit_price(line)
+                    return line.get_unit_price()
         return unit_price
 
-PriceList()
-
-class PriceListLine(ModelSQL, ModelView):
-    _name = 'product.price_list.line'
+class PriceListLine:
+    __name__ = 'product.price_list.line'
 
     category = fields.Many2One('product.category', 'Category')
-
-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_category',
     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 category option 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_category",
     package_dir={'trytond.modules.product_price_list_category': '.'},
     packages=[
     ],
     package_data={
         'trytond.modules.product_price_list_category': info.get('xml', []) \
-                + info.get('translation', []) \
-                + ['icons/*.svg'],
+            + ['tryton.cfg', 'locale/*.po'],
     },
     classifiers=[
         'Development Status :: 5 - Production/Stable',
+[tryton]
+version=2.6.0
+depends:
+    ir
+    res
+    product_price_list
+xml:
+    price_list.xml
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.