Explorar o código

[ADD] add customer from customer selection step

Gogs %!s(int64=7) %!d(string=hai) anos
pai
achega
9143b1d183

+ 4 - 0
models/res_partner.py

@@ -3,6 +3,10 @@ from openerp import api, fields, models
 class ResPartner(models.Model):
     _inherit = 'res.partner'
 
+    @api.model
+    def create_from_pos(self, values):
+        return self.create(values).id
+
     @api.model
     def get_customers(self):
         domain = [('customer', '=', True), ('active', '=', True)]

+ 39 - 0
src/components/customer/CustomerAdd.vue

@@ -0,0 +1,39 @@
+<template lang="pug">
+    .customer-add(@click="addCustomer()")
+        i.fa.fa-plus(aria-hidden="true")
+</template>
+
+<script>
+    import { mapActions } from 'vuex'
+
+    export default {
+        methods: mapActions([
+            'addCustomer'
+        ])
+    }
+</script>
+
+<style lang="sass">
+    .customer-add
+        width: 130px
+        height: 160px
+        margin: 5px
+        border: 1px solid #d3d3d3
+        display: inline-block
+        position: relative
+
+        &:hover
+            cursor: pointer
+
+        i
+            font-size: 36pt
+            margin: 0
+            border: none
+            position: absolute;
+            top: 50%
+            left: 50%
+            margin-right: -50%
+            transform: translate(-50%, -50%)
+            color: #0288d1
+            
+</style>

+ 99 - 0
src/components/customer/CustomerForm.vue

@@ -0,0 +1,99 @@
+<template lang="pug">
+    modal(name="customer-modal" transition="nice-modal-fade" @before-close="beforeClose" :classes="['v--modal', 'customer-modal']")
+        h2 Nuevo cliente
+        hr
+        form.customer-form
+            .customer-form-item
+                label.customer-form-label Nombre
+                input.customer-form-input(v-model="customer.name" autofocus)
+            .customer-form-item
+                label.customer-form-label R.U.C/C.I.N
+                input.customer-form-input(v-model="customer.ruc")
+            .customer-form-item
+                label.customer-form-label Teléfono
+                input.customer-form-input(v-model="customer.phone")
+        .customer-form-options
+            button.customer-button(@click="saveCustomer(customer)") Aceptar
+            button.customer-button(@click="saveCustomer()") Cancelar
+</template>
+
+<script>
+    import { mapGetters, mapActions } from 'vuex'
+
+    export default {
+        data() {
+            return {
+                customer: {
+                    name: '',
+                    ruc: '',
+                    phone: ''    
+                }
+            }
+        },
+        computed: mapGetters([
+            'addCustomer'
+        ]),
+        watch: {
+            addCustomer(value) {
+                if (value) {
+                    this.$modal.show('customer-modal')
+
+                    this.customer.name = ''
+                    this.customer.ruc = ''
+                    this.phone = ''
+                } else {
+                    this.$modal.hide('customer-modal')
+                }
+            }
+        },
+        methods: {
+            beforeClose(e) {
+                if (this.addCustomer) {
+                    e.stop()
+                }                    
+            },
+            ...mapActions([
+                'saveCustomer'
+            ])
+        }
+    }
+</script>
+
+<style lang="sass">
+    .customer-modal
+        h2
+            font-size: 10pt
+            color: #d3d3d3
+            margin-left: 15px
+        hr
+            margin: 0 15px
+        .customer-form
+            width: 100%
+            height: 200px
+            padding: 15px
+            .customer-form-item
+                width: 100%
+                height: 45px
+                margin-bottom: 10px
+                .customer-form-label
+                    width: 30%
+                    height: 45px
+                    font-size: 14pt
+                .customer-form-input
+                    width: 70%
+                    height: 45px
+                    font-size: 18pt
+                    border-radius: 0
+        .customer-form-options
+            float: right
+            .customer-button
+                width: 160px
+                height: 40px
+                border: none
+                box-shadow: none
+                border-radius: 0
+                margin-right: 5px
+                background: #0288d1
+                color: #fff
+</style>
+

+ 7 - 1
src/components/customer/CustomersGrid.vue

@@ -1,16 +1,22 @@
 <template lang="pug">
     .customers-grid-wrapper
         .customers-grid
+            customer-add
             customer-card(v-for="customer in customers" :key="customer" :item="customer")
+        customer-form
 </template>
 
 <script>
     import { mapGetters } from 'vuex'
+    import CustomerAdd from '@/components/customer/CustomerAdd'
     import CustomerCard from '@/components/customer/CustomerCard'
+    import CustomerForm from '@/components/customer/CustomerForm'
 
     export default {
         components: {
-            CustomerCard
+            CustomerAdd,
+            CustomerCard,
+            CustomerForm
         },
         computed: mapGetters([
             'customers'

+ 0 - 4
src/store/modules/cart.js

@@ -51,8 +51,6 @@ const mutations = {
             sum = sum + ((item.price || item.list_price) * (item.qty || 1))
         })
 
-        console.log(sum)
-
         state.total = sum
     }
 }
@@ -96,8 +94,6 @@ const actions = {
         if(payload.apply) {
             let product = getters.productToDiscount
 
-            console.log(product.discount)
-
             if (product.discount < product.minimum_price || product.discount > product.maximum_price) {
                 dispatch('notify', 'No se puede aplicar este descuento')
                 return

+ 35 - 5
src/store/modules/customers.js

@@ -1,7 +1,8 @@
 const state = {
     customers: [],
     filtered: [],
-    selectedCustomer: null
+    selectedCustomer: null,
+    addCustomer: false
 }
 
 const getters = {
@@ -13,18 +14,24 @@ const getters = {
     },
     selectedCustomer(state) {
         return state.selectedCustomer
+    },
+    addCustomer(state) {
+        return state.addCustomer
     }
 }
 
 const mutations = {
     pushCustomers(state, payload) {
-        state.customers = [...payload.customers]
+        state.customers = [...payload, ...state.customers]
     },
     selectCustomer(state, payload) {
         state.selectedCustomer = payload.customer
     },
     applyCustomersFilter(state, payload) {
         state.filtered = payload
+    },
+    addCustomer(state) {
+        state.addCustomer = !state.addCustomer
     }
 }
 
@@ -36,9 +43,7 @@ const actions = {
             ResPartner.call('get_customers', {
                 context: new openerp.web.CompoundContext()
             }).then(response => {
-                commit('pushCustomers', {
-                    customers: response
-                })
+                commit('pushCustomers', response)
 
                 dispatch('loaded', 'customers')
 
@@ -56,6 +61,31 @@ const actions = {
     },
     filterCustomers({ commit }, payload) {
         commit('applyCustomersFilter', payload)
+    },
+    addCustomer({ commit })  {
+        commit('addCustomer')
+    },
+    saveCustomer({ commit, dispatch }, payload) {
+        if (payload) {
+            if (!payload.name || !payload.ruc || !payload.phone) {
+                dispatch('notify', 'Complete los datos para guardar')
+                return
+            }
+            
+            let ResPartner = new openerp.web.Model('res.partner')
+            ResPartner.call('create_from_pos', [
+                payload
+            ], { 
+                context: new openerp.web.CompoundContext()
+            }).then(id => {
+                commit('pushCustomers', [{
+                    id,
+                    ...payload
+                }])
+            })
+        }
+
+        commit('addCustomer')
     }
 }