Browse Source

[ADD] add more modules and fetch simplifications

Gogs 7 years ago
parent
commit
bf9a433b12

+ 2 - 1
__init__.py

@@ -1 +1,2 @@
-# -*- coding: utf-8 -*-
+# -*- coding: utf-8 -*
+import eiru_pos

+ 2 - 2
__openerp__.py

@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 {
-    'name': "Eiru Pos",
+    'name': "Eiru POS",
     'author': "Robert Gauto",
     'category': 'Uncategorized',
     'version': '0.1',
@@ -8,4 +8,4 @@
     'data': [
         'templates.xml',
     ]
-}
+}

+ 151 - 0
eiru_pos.py

@@ -0,0 +1,151 @@
+# -*- coding: utf-8 -*-
+import logging
+from openerp import api, fields, models
+_logger = logging.getLogger(__name__)
+
+class eiru_pos(models.Model):
+    _name = 'eiru.pos'
+
+    # Get company
+    @api.model
+    def get_company(self):
+        user = self.env.user
+
+        return {
+            'id': user.company_id.id,
+            'name': user.company_id.name,
+            # 'store': {
+            #     'id': user.company_id.store_id.id,
+            #     'name': user.company_id.store_id.name
+            # }
+        }
+
+    # Get all products
+    @api.model
+    def get_products(self):
+        domain = [('sale_ok', '=', True), ('active', '=', True)]
+        products = []
+
+        for product in self.env['product.template'].search(domain):
+            variants = []
+
+            for variant in product.product_variant_ids:
+                if not variant.active:
+                    continue
+
+                attributes = []
+
+                for attribute_line in variant.attribute_line_ids:
+                    values = []
+
+                    for value in attribute_line.value_ids:
+                        values.append({
+                            'id': value.id,
+                            'display_name': value.display_name,
+                            'name': value.name,
+                            'price_extra': value.price_extra
+                        })
+
+                    attributes.append({
+                        'id': attribute_line.id,
+                        'attribute': {
+                            'id': attribute_line.attribute_id.id,
+                            'name': attribute_line.attribute_id.name
+                        },
+                        'values': values
+                    })
+                
+                variants.append({
+                    'id': variant.id,
+                    'display_name': variant.display_name,
+                    'ean13': variant.ean13,
+                    'image_medium': variant.image_medium,
+                    'list_price': variant.list_price,
+                    'name': variant.name,
+                    'qty_available': variant.qty_available,
+                    'attributes': attributes
+                })
+
+            products.append({
+                'id': product.id,
+                'display_name': product.display_name,
+                'ean13': product.ean13,
+                'image_medium': product.image_medium,
+                'list_price': product.list_price,
+                'name': product.name,
+                'qty_available': product.qty_available,
+                'category': {
+                    'id': product.categ_id.id,
+                    'display_name': product.categ_id.display_name,
+                    'name': product.categ_id.name,
+                    'account_journal': {
+                        'id': product.categ_id.property_stock_journal.id,
+                        'code': product.categ_id.property_stock_journal.code,
+                        'company': {
+                            'id': product.categ_id.property_stock_journal.company_id.id,
+                            'name': product.categ_id.property_stock_journal.company_id.name,
+                            'currency': {
+                                'id': product.categ_id.property_stock_journal.company_id.currency_id.id,
+                                'name': product.categ_id.property_stock_journal.company_id.currency_id.name
+                            }
+                        },
+                        'currency': {
+                            'id': product.categ_id.property_stock_journal.currency.id,
+                            'name': product.categ_id.property_stock_journal.currency.name
+                        },
+                        'display_name': product.categ_id.property_stock_journal.display_name,
+                        'name': product.categ_id.property_stock_journal.name,
+                    }
+                },
+                'uom': {
+                    'id': product.uom_id.id,
+                    'name': product.uom_id.name
+                },
+                'uos': {
+                    'id': product.uos_id.id,
+                    'name': product.uos_id.name
+                },
+                'variant_count': product.product_variant_count,
+                'variants': variants
+            })
+
+        return products
+
+    # Get all currencies
+    @api.model
+    def get_currencies(self):
+        domain = [('active', '=', True)]
+        currencies = []
+        
+        # if self.env.user.store_id:
+        #     domain.append(('company_id', '=', self.env.user.store_id.company_id.id))
+        # else:
+        #     domain.append(('company_id', '=', self.env.user.company_id.id))
+
+        # print domain
+
+        for currency in self.env['res.currency'].search(domain):
+            currencies.append({
+                'id': currency.id,
+                'name': currency.name,
+                'display_name': currency.display_name,
+                'accuracy': currency.accuracy,
+                'base': currency.base,
+                'position': currency.position,
+                'rate': currency.rate,
+                'rounding': currency.rounding,
+                'symbol': currency.symbol,
+                'company': {
+                    'id': currency.company_id.id,
+                    'name': currency.company_id.name
+                }
+            })
+
+        return currencies
+
+class eiru_pos_session(models.Model):
+    _name = 'eiru.pos.session'
+
+    # Get all sessions
+    def get_sessions(self):
+        pass

+ 15 - 0
src/App.vue

@@ -23,6 +23,8 @@
     import CartItem from '@/components/CartItem'
     import CustomersGrid from '@/components/CustomersGrid'
     import 'vue-form-wizard/dist/vue-form-wizard.min.css'
+    import { mapActions } from 'vuex'
+    import Vuex from 'vuex'
 
     export default {
         components: {
@@ -34,6 +36,19 @@
             'cart-items': CartItems,
             'cart-item': CartItem,
             'customers-grid': CustomersGrid
+        },
+        methods: mapActions([
+            'fetchCompany',
+            'fetchProducts',
+            'fetchCustomers',
+            'fetchCurrencies',
+            'fetchRates'
+        ]),
+        mounted() {
+            this.fetchCompany()
+            this.fetchProducts()
+            this.fetchCustomers()
+            this.fetchCurrencies()
         }
     }
 </script>

+ 0 - 4
src/components/ProductsGrid.vue

@@ -16,12 +16,8 @@
             products: 'getProducts'
         }),
         methods: mapActions([
-            'fetchProducts',
             'selectProduct'
         ]),
-        mounted() {
-            this.fetchProducts()
-        }
     }
 </script>
 

+ 5 - 0
src/store/actions.js

@@ -0,0 +1,5 @@
+const actions = {
+    getData({ commit }) {
+
+    }
+}

+ 2 - 0
src/store/index.js

@@ -1,6 +1,7 @@
 import Vue from 'vue'
 import Vuex from 'vuex'
 
+import company from '@/store/modules/company'
 import currencies from '@/store/modules/currencies'
 import products from '@/store/modules/products'
 import cart from '@/store/modules/cart'
@@ -10,6 +11,7 @@ Vue.use(Vuex)
 
 const Store = new Vuex.Store({
     modules: {
+        company,
         currencies,
         products,
         cart,

+ 36 - 0
src/store/modules/company.js

@@ -0,0 +1,36 @@
+const state = {
+    company: null
+}
+
+const getters = {
+    getCompany(state) {
+        return state.company
+    }
+}
+
+const mutations = {
+    setCompany(state, payload) {
+        state.company = payload.company
+    }
+}
+
+const actions = {
+    fetchCompany({ commit }) {
+        let pos = new openerp.web.Model('eiru.pos')
+        pos.call('get_company').then(response => {
+            console.log(response)
+            commit('setCompany', {
+                company: response
+            })
+        }).fail(error => {
+            console.log(error)
+        })
+    }
+}
+
+export default {
+    state,
+    getters,
+    mutations,
+    actions
+}

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

@@ -5,6 +5,9 @@ const state = {
 const getters = {
     getCurrencies(state) {
         return state.currencies
+    },
+    getRates(state) {
+        return state.rates
     }
 }
 
@@ -16,8 +19,8 @@ const mutations = {
 
 const actions = {
     fetchCurrencies({ commit }) {
-        let currency = new openerp.web.Model('res.currency')
-        currency.query('name', 'display_name').filter([['active', '=', true]]).all().then(response => {
+        let pos = new openerp.web.Model('eiru.pos')
+        pos.call('get_currencies').then(response => {
             commit('pushCurrencies', {
                 currencies: response
             })

+ 3 - 7
src/store/modules/products.js

@@ -1,14 +1,10 @@
 const state = {
-    products: [],
-    selectedProducts: []
+    products: []
 }
 
 const getters = {
     getProducts (state) {
         return state.products
-    },
-    hasSelectedProducts (state) {
-        return state.selectedProducts.length !== 0
     }
 }
 
@@ -20,8 +16,8 @@ const mutations = {
 
 const actions = {
     fetchProducts ({ commit }) {
-        let product = new openerp.web.Model('product.product')
-        product.query(['name', 'display_name', 'list_price', 'image_medium']).filter([['active', '=', true]]).all().then(response => {
+        let pos = new openerp.web.Model('eiru.pos')
+        pos.call('get_products').then(response => {
             commit('pushProducts', {
                 products: response
             })

+ 21 - 0
src/store/modules/sessions.js

@@ -0,0 +1,21 @@
+const state = {
+    sessions: {}
+}
+
+const getters = {
+    getSessions(state) {
+        return state.sessions
+    }
+}
+
+const mutations = {
+    pushSessions(state, payload) {
+
+    }
+}
+
+const actions = {
+    fetchSessions({ commit }, payload) {
+        
+    }
+}

+ 14 - 0
src/store/state.js

@@ -0,0 +1,14 @@
+const state = {
+    loading: false
+}
+
+const getters = {
+    isLoading(state) {
+        return state.loading
+    }
+}
+
+export default {
+    state,
+    getters
+}