Source

trytond-product_price_list_category / price_list.py

Diff from to

price_list.py

 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()
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.