Forráskód Böngészése

[FIX] customer pricelist id

robert 6 éve
szülő
commit
54fc4ec389
3 módosított fájl, 18 hozzáadás és 9 törlés
  1. 7 6
      controllers/main.py
  2. 8 2
      controllers/sale_order.py
  3. 3 1
      src/store/actions.js

+ 7 - 6
controllers/main.py

@@ -198,7 +198,7 @@ class PosSales(http.Controller):
         ╠╣ ║║║║║╚═╗╠═╣  ╠╩╗║ ║ ║║║ ╦║╣  ║   ╠═╝║ ║╚═╗  ╠═╝╠╦╝║ ║║  ║╣  ║║║ ║╠╦╝║╣ 
         ╚  ╩╝╚╝╩╚═╝╩ ╩  ╚═╝╚═╝═╩╝╚═╝╚═╝ ╩   ╩  ╚═╝╚═╝  ╩  ╩╚═╚═╝╚═╝╚═╝═╩╝╚═╝╩╚═╚═╝
         '''
-        def finish_budget_pos(journal_id, customer_id, cart_items, date_now, payment_term_id, warehouse_id, user_id):
+        def finish_budget_pos(journal_id, customer_id, cart_items, date_now, payment_term_id, warehouse_id, customer_pricelist_id, user_id):
             # Imports
             from account_journal import get_currency
             from sale_order import create_sale_from_cart
@@ -212,7 +212,7 @@ class PosSales(http.Controller):
             self.make_info_log('[OK] Getting journal')
 
             # Create sale order
-            sale_order = create_sale_from_cart(customer_id, cart_items, date_now, currency_id, payment_term_id, warehouse_id, user_id)
+            sale_order = create_sale_from_cart(customer_id, cart_items, date_now, currency_id, payment_term_id, warehouse_id, customer_pricelist_id, user_id)
             self.make_info_log('[OK] Creating sale order')
 
             return (sale_order.id, currency_id)
@@ -222,9 +222,9 @@ class PosSales(http.Controller):
         ╠╣ ║║║║║╚═╗╠═╣  ╚═╗╠═╣║  ║╣   ╠═╝║ ║╚═╗  ╠═╝╠╦╝║ ║║  ║╣  ║║║ ║╠╦╝║╣ 
         ╚  ╩╝╚╝╩╚═╝╩ ╩  ╚═╝╩ ╩╩═╝╚═╝  ╩  ╚═╝╚═╝  ╩  ╩╚═╚═╝╚═╝╚═╝═╩╝╚═╝╩╚═╚═╝
         '''
-        def finish_sale_pos(journal_id, customer_id, cart_items, date_now, payment_term_id, payment, payment_method, bank_payment_data, warehouse_id, user_id):
+        def finish_sale_pos(journal_id, customer_id, cart_items, date_now, payment_term_id, payment, payment_method, bank_payment_data, warehouse_id, customer_pricelist_id, user_id):
             # Create budget
-            sale_order_id, currency_id = finish_budget_pos(journal_id, customer_id, cart_items, date_now, payment_term_id, warehouse_id, user_id)
+            sale_order_id, currency_id = finish_budget_pos(journal_id, customer_id, cart_items, date_now, payment_term_id, warehouse_id, customer_pricelist_id, user_id)
 
             # Imports
             from sale_order import confirm_sale_order
@@ -375,6 +375,7 @@ class PosSales(http.Controller):
             mode = row.get('mode', 'sale')
             journal_id = row.get('journalId', None)
             customer_id = row.get('customerId', None)
+            customer_pricelist_id = row.get('customerPricelistId', None)
             cart_items = row.get('items', [])
             payment_term_id = row.get('paymentTermId', None)
             warehouse_id = row.get('warehouseId', None)
@@ -384,10 +385,10 @@ class PosSales(http.Controller):
             bank_payment_data = row.get('bankPaymentData', {})
 
             if mode == 'budget':
-                finish_budget_pos(journal_id, customer_id, cart_items, date_now, payment_term_id, warehouse_id, user_id)
+                finish_budget_pos(journal_id, customer_id, cart_items, date_now, payment_term_id, warehouse_id, customer_pricelist_id, user_id)
 
             if mode == 'sale':
-                finish_sale_pos(journal_id, customer_id, cart_items, date_now, payment_term_id, payment, payment_method, bank_payment_data, warehouse_id, user_id)
+                finish_sale_pos(journal_id, customer_id, cart_items, date_now, payment_term_id, payment, payment_method, bank_payment_data, warehouse_id, customer_pricelist_id, user_id)
 
             if mode == 'product_picking':
                 finish_process_picking(journal_id, customer_id, cart_items, date_now, payment_term_id, warehouse_id, user_id)

+ 8 - 2
controllers/sale_order.py

@@ -44,10 +44,13 @@ def get_sale_orders():
     ]
 
 
-def create_sale_from_cart(partner_id, cart_items, date_confirm, currency_id, payment_term_id=None, warehouse_id=None, user_id=None):
+def create_sale_from_cart(partner_id, cart_items, date_confirm, currency_id, payment_term_id=None, warehouse_id=None, customer_pricelist_id=None, user_id=None):
     '''
     '''
-    def get_pricelist(currency_id):
+    def get_pricelist(currency_id, customer_pricelist_id=None):
+        if customer_pricelist_id:
+            return request.env['product.pricelist'].browse([customer_pricelist_id])
+
         domain = [
             ('active', '=', True),
             ('type', '=', 'sale')
@@ -89,6 +92,9 @@ def create_sale_from_cart(partner_id, cart_items, date_confirm, currency_id, pay
 
     pricelist = get_pricelist(currency_id)
 
+    if len(pricelist) > 1:
+        pricelist = pricelist[0]
+
     values = {
         'partner_id': partner_id,
         'order_line': [[0, False, {

+ 3 - 1
src/store/actions.js

@@ -163,9 +163,10 @@ const actions = {
                     }
                 }),
                 customerId: getters.selectedCustomer.id,
+                customerPricelistId: getters.customerPricelist.id,
                 currencyId: getters.selectedCurrency.id,
                 warehouseId: getters.selectedWarehouse.id,
-                userId: getters.selectedUser.id
+                userId: getters.selectedUser.id,
             }
         }
 
@@ -179,6 +180,7 @@ const actions = {
                 payment: getters.initialPayment > getters.amountToPay ? getters.amountToPay : getters.initialPayment,
                 paymentMethod: getters.paymentMethod,
                 customerId: getters.selectedCustomer.id,
+                customerPricelistId: getters.customerPricelist.id,
                 currencyId: getters.selectedCurrency.id,
                 warehouseId: getters.selectedWarehouse.id,
                 bankPaymentData: {