Procházet zdrojové kódy

[ADD] customer pricelist configuration

robert před 6 roky
rodič
revize
f0089ad2e0

+ 1 - 0
controllers/res_config.py

@@ -13,6 +13,7 @@ def get_pos_config():
         'viewCurrencyExchanges': config.view_currency_exchanges,
         'allowChangeUser': config.allow_change_user,
         'allowChangeDate': config.allow_change_date,
+        'allowPricelist': config.allow_pricelist,
         'currencies': [
             {
                 'id': currency.id,

+ 2 - 1
controllers/res_partner.py

@@ -19,7 +19,8 @@ def get_customers(image_type='small'):
             'ruc': customer.ruc or None,
             'phone': customer.phone or None,
             'mobile': customer.mobile or None,
-            'email': customer.email or None
+            'email': customer.email or None,
+            'pricelistId': customer.property_product_pricelist.id or None
         } for customer in request.env['res.partner'].search(domain)
     ]
 

+ 3 - 0
models/res_config.py

@@ -11,6 +11,7 @@ class ResConfig(models.TransientModel):
     view_currency_exchanges = fields.Boolean(default=False, string='Permitir ver cambio de monedas')
     allow_change_user = fields.Boolean(default=False, string='Permitir cambiar el usuario')
     allow_change_date = fields.Boolean(default=False, string='Permitir cambiar la fecha')
+    allow_pricelist = fields.Boolean(default=False, string='Permitir tarifa de precios')
     currency_ids = fields.Many2many('res.currency', string='Monedas')
 
     '''
@@ -24,6 +25,7 @@ class ResConfig(models.TransientModel):
         ir_config.set_param('eiru_pos.view_currency_exchanges', repr(self.view_currency_exchanges))
         ir_config.set_param('eiru_pos.allow_change_user', repr(self.allow_change_user))
         ir_config.set_param('eiru_pos.allow_change_date', repr(self.allow_change_date))
+        ir_config.set_param('eiru_pos.allow_pricelist', repr(self.allow_pricelist))
         ir_config.set_param('eiru_pos.currency_ids', repr(self.currency_ids.mapped(lambda x: x.id)))
 
     @api.model
@@ -36,5 +38,6 @@ class ResConfig(models.TransientModel):
             'view_currency_exchanges': safe_eval(ir_config.get_param('eiru_pos.view_currency_exchanges', 'False')),
             'allow_change_user': safe_eval(ir_config.get_param('eiru_pos.allow_change_user', 'False')),
             'allow_change_date': safe_eval(ir_config.get_param('eiru_pos.allow_change_date', 'False')),
+            'allow_pricelist': safe_eval(ir_config.get_param('eiru_pos.allow_pricelist', 'False')),
             'currency_ids': safe_eval(ir_config.get_param('eiru_pos.currency_ids', '[]'))
         }

+ 21 - 0
src/components/steps/Payment.vue

@@ -22,9 +22,19 @@
                 select.form-input.input-only(v-model='paymentTermId')
                     option(
                         :value='term.id' 
+                        :key='term.id'
                         v-for='term in paymentTerms'
                         v-if="term.lines.length > 0 && (term.lines[0].days !== 0 || term.lines[0].value !==  'balance')"
                     ) {{ term.name }}
+            //- input para listado de precios de clientes
+            .form-item(v-show='settings.allowPricelist')
+                label.form-label Tarifa de precios
+                select.form-input(v-model='pricelistId')
+                    option(
+                        :value='p.id'
+                        :key='p.id'
+                        v-for='p in pricelists'
+                    ) {{ p.name }}
             //- input para monto de pago
             .form-item
                 label.form-label Monto a Pagar
@@ -114,6 +124,14 @@
                     }
                 }
             },
+            pricelistId: {
+                get() {
+                    return (this.customerPricelist && this.customerPricelist.id) || -1
+                },
+                set(value) {
+                    this.selectCustomerPricelist(value)
+                }
+            },
             ...mapGetters([
                 'companyName',
                 'amountToPay',
@@ -126,12 +144,14 @@
                 'paymentTerm',
                 'paymentMethod',
                 'currencySymbol',
+                'customerPricelist',
                 'showBankPayment',
                 'hasBankJournalSelected',
                 'selectedCustomerName',
                 'selectedCurrency',
                 'selectedJournal',
                 'selectedBankPaymentType',
+                'pricelists',
                 'selectedChequeType',
                 'currencies',
                 'currencySymbols',
@@ -180,6 +200,7 @@
                 'changeCurrency',
                 'selectPaymentTerm',
                 'selectJournal',
+                'selectCustomerPricelist',
                 'changePaymentType',
                 'changePaymentMethod',
                 'changeBankPaymentType',

+ 51 - 0
src/store/modules/pricelist.js

@@ -1,6 +1,7 @@
 const state = {
     loadingPricelists: false,
     pricelists: [],
+    customerPricelist: null,
     showPricelists: false
 }
 
@@ -11,6 +12,9 @@ const getters = {
     pricelists(state) {
         return state.pricelists
     },
+    customerPricelist(state) {
+        return state.customerPricelist
+    },
     pricelistsForProduct(state, getters) {
         let product = getters.itemToDiscount
 
@@ -49,6 +53,29 @@ const getters = {
 
         return pricelists
     },
+    pricelistsForCustomer(state, getters) {
+        let customer = getters.selectedCustomer
+
+        if (!customer) {
+            return []
+        }
+        
+        let pricelists = []
+
+        for (let p of state.pricelists) {
+            if (p.type !== 'sale') {
+                continue
+            }
+
+            if (p.id !== customer.pricelistId) {
+                continue
+            }
+
+            pricelists.push(p)
+        }
+
+        return pricelists
+    },
     showPricelists(state) {
         return state.showPricelists
     }
@@ -61,6 +88,25 @@ const mutations = {
     setPricelists(state, pricelists) {
         state.pricelists = pricelists
     },
+    setCustomerPricelist(state, pricelistId) {
+        let pricelist = null
+
+        for (let p of state.pricelists) {
+            if (p.id === pricelistId) {
+                pricelist = p
+                break
+            }
+        }
+
+        state.customerPricelist = pricelist
+    },
+    autoselectPricelist(state) {
+        if (state.pricelists.length === 0) {
+            return
+        }
+
+        state.customerPricelist = state.pricelists[0]
+    },
     togglePricelists(state) {
         state.showPricelists = !state.showPricelists
     }
@@ -69,11 +115,16 @@ const mutations = {
 const actions = {
     initPricelists({ commit }, pricelists) {
         commit('setPricelists', pricelists)
+        commit('autoselectPricelist')
         commit('setLoadingPricelists')
     },
     togglePricelists({ commit }) {
         commit('togglePricelists')
     },
+    selectCustomerPricelist({ commit }, pricelistId) {
+        console.log(pricelistId)
+        commit('setCustomerPricelist', pricelistId)
+    },
     resetPricelist({ commit }) {
         commit('setLoadingPricelists', true)
         commit('setPricelists', [])

+ 1 - 0
templates.xml

@@ -63,6 +63,7 @@
                                 <field name="currency_ids" widget="many2many_tags" options="{'no_create_edit': True}" />
                                 <field name="allow_change_user" />
                                 <field name="allow_change_date" />
+                                <field name="allow_pricelist" />
                             </group>
                         </group>
                     </div>