Browse Source

[ADD] pricelist

robert 6 years ago
parent
commit
35e803e658
3 changed files with 43 additions and 2 deletions
  1. 2 0
      controllers/main.py
  2. 40 0
      controllers/product_pricelist.py
  3. 1 2
      controllers/product_template.py

+ 2 - 0
controllers/main.py

@@ -36,6 +36,7 @@ class PosSales(http.Controller):
         from account_journal import get_journals, get_currencies_from_journals
         from res_partner import get_customers
         from product_template import get_products
+        from product_pricelist import get_pricelists
         from account_payment_term import get_payment_terms
         from res_bank import get_banks
         from res_bank_payment_type import get_bank_payment_types
@@ -72,6 +73,7 @@ class PosSales(http.Controller):
                 'journals': get_journals(),
                 'customers': get_customers(image_type),
                 'products': get_products(image_type, map(lambda x: x.get('locationStock').get('id'), warehouses)),
+                'pricelists': get_pricelists('sale'),
                 'paymentTerms': get_payment_terms(),
                 'banks': get_banks(),
                 'bankPaymentTypes': get_bank_payment_types(),

+ 40 - 0
controllers/product_pricelist.py

@@ -0,0 +1,40 @@
+# -*- coding: utf-8 -*-
+from openerp.http import request as r
+
+_MODEL = 'product.pricelist'
+
+def get_pricelists(type='sale'):
+    domain = [
+        ('type', '=', type),
+        ('active', '=', True)
+    ]
+
+    return [
+        {
+            'id': p.id,
+            'name': p.display_name,
+            'type': p.type,
+            'versions': [
+                {
+                    'id': v.id,
+                    'name': v.display_name,
+                    'companyId': v.company_id.id or None,
+                    'items': [
+                        {
+                            'id': i.id,
+                            'name': i.display_name,
+                            'base': i.base,
+                            'basePricelistId': i.base_pricelist_id.id or None,
+                            'minQuantity': i.min_quantity,
+                            'priceDiscount': i.price_discount,
+                            'priceMaxMargin': i.price_max_margin,
+                            'priceMinMargin': i.price_min_margin,
+                            'priceRound': i.price_round,
+                            'priceSurcharge': i.price_surcharge,
+                            'productId': i.product_id.id or None
+                        } for i in v.items_id
+                    ],
+                } for v in p.version_id
+            ]
+        } for p in r.env[_MODEL].search(domain)
+    ]

+ 1 - 2
controllers/product_template.py

@@ -1,11 +1,9 @@
 # -*- coding: utf-8 -*-
 from docutils.nodes import entry
-
 from openerp.http import request as r
 
 _MODEL = 'product.template'
 
-
 def get_products(image_type='small', location_ids=None):
     domain = [
         ('sale_ok', '=', True), 
@@ -61,6 +59,7 @@ def get_products(image_type='small', location_ids=None):
                 'minimumPrice': p.minimum_price,
                 'maximumPrice': p.maximum_price,
                 'discount': 0,
+                'pricelistId': v.pricelist_id.id or None,
                 'locations': in_locations.get(v.id, [])
             } for v in p.product_variant_ids]
         } for p in r.env[_MODEL].search(domain)