Browse Source

[ADD] fetch periods, journals and terms

Gogs 7 years ago
parent
commit
2094215e0b

+ 11 - 2
models/account_journal.py

@@ -5,6 +5,15 @@ class AccountJournal(models.Model):
 
     @api.model
     def get_journals(self):
-        journal = self.env['account.journal']
+        domain = [('active', '=', True), ('type', 'in', ['bank', 'cash'])]
+        journals = []
 
-        print journal
+        for journal in self.env['account.journal'].search(domain):
+            journals.append({
+                'id': journal.id,
+                'name': journal.name,
+                'display_name': journal.display_name,
+                'code': journal.code
+            })
+
+        return journals

+ 24 - 1
models/account_payment_term.py

@@ -5,4 +5,27 @@ class AccountPaymentTerm(models.Model):
 
     @api.model
     def get_account_payment_terms(self):
-        pass
+        domain = [('active', '=', True)]
+        terms = []
+
+        for term in self.env['account.payment.term'].search(domain):
+            print term.name
+
+            lines = []
+
+            for line in term.line_ids:
+                lines.append({
+                    'id': line.id,
+                    'display_name': line.display_name,
+                    'days': line.days,
+                    'value_amount': line.value_amount
+                })
+
+            terms.append({
+                'id': term.id,
+                'name': term.name,
+                'display_name': term.display_name,
+                'lines': lines
+            })
+
+        return terms

+ 12 - 1
models/account_period.py

@@ -5,4 +5,15 @@ class AccountPeriod(models.Model):
 
     @api.model
     def get_periods(self):
-        pass
+        domain = []
+        periods = []
+
+        for period in self.env['account.period'].search(domain):
+            periods.append({
+                'id': period.id,
+                'name': period.name,
+                'display_name': period.display_name,
+                'state': period.state
+            })
+
+        return periods

+ 4 - 2
src/App.vue

@@ -13,7 +13,7 @@
                 customer-searcher
                 customers-grid
             tab-content(title="Vea un resumen de su operación")
-                summary-display
+                payment
         loader
 </template>
 
@@ -30,6 +30,7 @@
     import CustomerSearcher from '@/components/CustomerSearcher'
     import CustomersGrid from '@/components/CustomersGrid'
     import SummaryDisplay from '@/components/SummaryDisplay'
+    import Payment from '@/components/Payment'
 
     import { mapActions, mapGetters } from 'vuex'
     import Vuex from 'vuex'
@@ -46,7 +47,8 @@
             'cart-item': CartItem,
             'customer-searcher': CustomerSearcher,
             'customers-grid': CustomersGrid,
-            'summary-display': SummaryDisplay
+            'summary-display': SummaryDisplay,
+            'payment': Payment
         },
         computed: mapGetters({
             total: 'getTotal',

+ 24 - 0
src/components/Payment.vue

@@ -0,0 +1,24 @@
+<template lang="pug">
+    .payment
+        h2 This is a payment
+</template>
+
+<script>
+    import { mapActions, mapGetters } from 'vuex'
+
+    export default {
+        components: {
+
+        },
+        methods: {
+
+        },
+        data() {
+            
+        }
+    }
+</script>
+
+<style lang="sass">
+
+</style>

+ 4 - 1
src/store/actions.js

@@ -9,7 +9,10 @@ const actions = {
             dispatch('fetchCompany'),
             dispatch('fetchCurrencies'),
             dispatch('fetchProducts'),
-            dispatch('fetchCustomers')
+            dispatch('fetchCustomers'),
+            dispatch('fetchJournals'),
+            dispatch('fetchPeriods'),
+            dispatch('fetchPaymentTerms')
         ]
 
         Promise.all(promises).then(() => {

+ 3 - 1
src/store/index.js

@@ -12,6 +12,7 @@ import currencies from '@/store/modules/currencies'
 import products from '@/store/modules/products'
 import cart from '@/store/modules/cart'
 import customers from '@/store/modules/customers'
+import account from '@/store/modules/account'
 
 Vue.use(Vuex)
 
@@ -26,7 +27,8 @@ const Store = new Vuex.Store({
         currencies,
         products,
         cart,
-        customers
+        customers,
+        account
     }
 })
 

+ 90 - 0
src/store/modules/account.js

@@ -0,0 +1,90 @@
+const state = {
+    journals: [],
+    periods: [],
+    paymentTerms: []
+}
+
+const getters = {
+    getJournals(state) {
+        return state.journals
+    },
+    getPeriods(state) {
+        return state.periods
+    },
+    getPaymentTerms(state) {
+        return state.paymentTerms
+    }
+}
+
+const mutations = {
+    setJournals(state, payload) {
+        state.journals = payload
+    },
+    setPeriods(state, payload) {
+        state.periods = payload
+    },
+    setPaymentTerms(state, payload) {
+        state.paymentTerms = payload
+    }
+}
+
+const actions = {
+    fetchJournals({ commit, dispatch }) {
+        return new Promise((resolve, reject) => {
+            let AccountJournal = new openerp.web.Model('account.journal')
+
+            AccountJournal.call('get_journals', {
+                context: new openerp.web.CompoundContext()
+            }).then(response => {
+                commit('setJournals', response)
+                dispatch('loaded', 'journals')
+
+                resolve()
+            }).fail(error => {
+                console.log(error)
+                reject(error)
+            })
+        })
+    },
+    fetchPeriods({ commit, dispatch }) {
+        return new Promise((resolve, reject) => {
+            let AccountPeriod = new openerp.web.Model('account.period')
+
+            AccountPeriod.call('get_periods', {
+                context: new openerp.web.CompoundContext()
+            }).then(response => {
+                commit('setPeriods', response)
+                dispatch('loaded', 'periods')
+
+                resolve()
+            }).fail(error => {
+                console.log(error)
+                reject(error)
+            })
+        })
+    },
+    fetchPaymentTerms({ commit, dispatch }) {
+        return new Promise((resolve, reject) => {
+            let AccountPaymentTerm = new openerp.web.Model('account.payment.term')
+
+            AccountPaymentTerm.call('get_account_payment_terms', {
+                context: new openerp.web.CompoundContext()
+            }).then(response => {
+                commit('setPaymentTerms', response)
+                dispatch('loaded', 'paymentTerms')
+
+                resolve()
+            }).fail(error => {
+                console.log(error)
+                reject(error)
+            })
+        })
+    }
+}
+
+export default {
+    state,
+    getters,
+    mutations,
+    actions
+}

+ 4 - 4
src/store/modules/company.js

@@ -25,14 +25,14 @@ const actions = {
         return new Promise((resolve, reject) => {
             let ResCompany = new openerp.web.Model('res.company')
 
-            pos.call('get_company').then(response => {
+            ResCompany.call('get_company', {
+                context: new openerp.web.CompoundContext()
+            }).then(response => {
                 commit('setCompany', {
                     company: response
                 })
 
-                dispatch('loaded', {
-                    module: 'company'
-                })
+                dispatch('loaded', 'company')
                 
                 resolve()
             }).fail(error => {

+ 5 - 6
src/store/modules/currencies.js

@@ -17,16 +17,15 @@ const mutations = {
 const actions = {
     fetchCurrencies({ commit, dispatch }) {
         return new Promise((resolve, reject) => {
-            let pos = new openerp.web.Model('res.currency')
+            let ResCurrency = new openerp.web.Model('res.currency')
 
-            ResCurrency.call('get_currencies').then(response => {
+            ResCurrency.call('get_currencies', {
+                context: new openerp.web.CompoundContext()
+            }).then(response => {
                 commit('pushCurrencies', {
                     currencies: response
                 })
-
-                dispatch('loaded', {
-                    module: 'currencies'
-                })
+                dispatch('loaded', 'currencies')
 
                 resolve()
             }).fail(error => {

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

@@ -31,16 +31,16 @@ const mutations = {
 const actions = {
     fetchCustomers({ commit, dispatch }) {
         return new Promise((resolve, reject) => {
-            let pos = new openerp.web.Model('res.partner')
+            let ResPartner = new openerp.web.Model('res.partner')
 
-            ResPartner.call('get_customers').then(response => {
+            ResPartner.call('get_customers', {
+                context: new openerp.web.CompoundContext()
+            }).then(response => {
                 commit('pushCustomers', {
                     customers: response
                 })
 
-                dispatch('loaded', {
-                    module: 'customers'
-                })
+                dispatch('loaded', 'customers')
 
                 resolve()
             }).fail(error => {

+ 11 - 2
src/store/modules/loader.js

@@ -4,6 +4,9 @@ const state = {
         currencies: false,
         customers: false,
         products: false,
+        journals: false,
+        periods: false,
+        paymentTerms: false
     },
     messages: [
         'Cargando compañía',
@@ -18,13 +21,19 @@ const getters = {
         return state.messages
     },
     isLoaded(state) {
-        return state.loaded.company && state.loaded.currencies && state.loaded.customers && state.loaded.products
+        return state.loaded.company && 
+               state.loaded.currencies && 
+               state.loaded.customers && 
+               state.loaded.products &&
+               state.loaded.journals &&
+               state.loaded.periods &&
+               state.loaded.paymentTerms
     }
 }
 
 const mutations = {
     setLoaded(state, payload) {
-        state.loaded[payload.module] = true
+        state.loaded[payload] = true
     },
     setUnloaded(state) {
         for (let module in state.loaded) {

+ 5 - 5
src/store/modules/products.js

@@ -40,16 +40,16 @@ const mutations = {
 const actions = {
     fetchProducts ({ commit, dispatch }) {
         return new Promise((resolve, reject) => {
-            let pos = new openerp.web.Model('product.template')
+            let ProductTemplate = new openerp.web.Model('product.template')
 
-            ProductTemplate.call('get_products').then(response => {
+            ProductTemplate.call('get_products', {
+                context: new openerp.web.CompoundContext()
+            }).then(response => {
                 commit('pushProducts', {
                     products: response
                 })
 
-                dispatch('loaded', {
-                    module: 'products'
-                })
+                dispatch('loaded', 'products')
                 
                 resolve()
             }).fail(error => {