Browse Source

[FIX] total currency format

Gogs 7 years ago
parent
commit
58362701fc
9 changed files with 62 additions and 10 deletions
  1. 2 1
      __init__.py
  2. 1 1
      __openerp__.py
  3. 1 0
      models/__init__.py
  4. 8 0
      models/eiru_pos.py
  5. 8 0
      models/res_currency.py
  6. 6 2
      src/App.vue
  7. 32 5
      src/components/CartTotal.vue
  8. 3 0
      src/store/modules/company.js
  9. 1 1
      templates.xml

+ 2 - 1
__init__.py

@@ -1,2 +1,3 @@
 # -*- coding: utf-8 -*
-import eiru_pos
+from models import eiru_pos
+from models import res_currency

+ 1 - 1
__openerp__.py

@@ -6,6 +6,6 @@
     'version': '0.1',
     'depends': ['base'],
     'data': [
-        'templates.xml',
+        'templates.xml'
     ]
 }

+ 1 - 0
models/__init__.py

@@ -0,0 +1 @@
+# -*- coding: utf-8 -*

+ 8 - 0
eiru_pos.py → models/eiru_pos.py

@@ -14,6 +14,13 @@ class eiru_pos(models.Model):
         return {
             'id': user.company_id.id,
             'name': user.company_id.name,
+            'currency': {
+                'id': user.company_id.currency_id.id,
+                'name': user.company_id.currency_id.name,
+                'display_name': user.company_id.currency_id.display_name,
+                'symbol': user.company_id.currency_id.symbol,
+                'format': user.company_id.currency_id.format
+            }
             # 'store': {
             #     'id': user.company_id.store_id.id,
             #     'name': user.company_id.store_id.name
@@ -135,6 +142,7 @@ class eiru_pos(models.Model):
                 'rate': currency.rate,
                 'rounding': currency.rounding,
                 'symbol': currency.symbol,
+                'format': currency.format,
                 'company': {
                     'id': currency.company_id.id,
                     'name': currency.company_id.name

+ 8 - 0
models/res_currency.py

@@ -0,0 +1,8 @@
+# -*- coding: utf-8 -*-
+from openerp import api, fields, models
+
+class res_currency(models.Model):
+    _name = 'res.currency'
+    _inherit = 'res.currency'
+
+    format = fields.Char('Currency Format', size=15, default='#,#.##')

+ 6 - 2
src/App.vue

@@ -6,7 +6,7 @@
                     products-searcher
                     products-grid
                 .cart-container
-                    cart-total
+                    cart-total(:total="total" :symbol="currency.symbol" :decimals="2")
                     cart-items
         tab-content(title="Seleccione un cliente")
             customer-searcher
@@ -28,7 +28,7 @@
     import CustomersGrid from '@/components/CustomersGrid'
     import SummaryDisplay from '@/components/SummaryDisplay'
 
-    import { mapActions } from 'vuex'
+    import { mapActions, mapGetters } from 'vuex'
     import Vuex from 'vuex'
 
     export default {
@@ -44,6 +44,10 @@
             'customers-grid': CustomersGrid,
             'summary-display': SummaryDisplay
         },
+        computed: mapGetters({
+            total: 'getTotal',
+            currency: 'getDefaultCurrency'
+        }),
         methods: mapActions([
             'fetchCompany',
             'fetchProducts',

+ 32 - 5
src/components/CartTotal.vue

@@ -1,18 +1,45 @@
 <template lang="pug">
     .cart-total
         h2
-            small.cart-total-currency Gs
+            small.cart-total-currency {{ getSymbol() }}
             |
-            | {{ total }}
+            | {{ getTotal() }}
 </template>
 
 <script>
     import { mapGetters } from 'vuex'
 
     export default {
-        computed: mapGetters({
-            total: 'getTotal'
-        })
+        props: {
+            total: {
+                type: Number,
+                required: true
+            },
+            symbol: {
+                type: String,
+                required: true,
+                default: '$'
+            },
+            separator: {
+                type: String,
+                default: '.'
+            },
+            decimals: {
+                type: Number,
+                default: 0
+            }
+        },
+        methods: {
+            getTotal() {
+                return accounting.format(this.total, 2, '.', ',')
+            },
+            getSymbol() {
+                return this.symbol
+            }
+        },
+        mounted() {
+            console.log(this)
+        }
     }
 
 </script>

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

@@ -5,6 +5,9 @@ const state = {
 const getters = {
     getCompany(state) {
         return state.company
+    },
+    getDefaultCurrency(state) {
+        return state.company ? state.company.currency : ''
     }
 }
 

+ 1 - 1
templates.xml

@@ -1,6 +1,6 @@
 <openerp>
     <data>
-        <template id="eiru_pos.assets" name="Eiru Pos Assets" inherit_id="web.assets_backend">
+        <template id="eiru_pos.assets" name="Eiru Pos Assets" inherit_id="eiru_assets.assets">
             <xpath expr="." position="inside">
                 <script src="http://localhost:35729/livereload.js"></script>
                 <script type="text/javascript" src="/eiru_pos/static/src/main.js"></script>