adrielso преди 7 години
родител
ревизия
b506b41887
променени са 5 файла, в които са добавени 259 реда и са изтрити 0 реда
  1. 1 0
      __init__.py
  2. 2 0
      controllers/__init__.py
  3. 236 0
      controllers/main.py
  4. 1 0
      package.json
  5. 19 0
      yarn.lock

+ 1 - 0
__init__.py

@@ -3,3 +3,4 @@ from models import payment_journal
 from models import res_partner
 from models import account_voucher
 from models import res_company
+import controllers

+ 2 - 0
controllers/__init__.py

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

+ 236 - 0
controllers/main.py

@@ -0,0 +1,236 @@
+# -*- coding: utf-8 -*-
+from openerp import http
+from openerp.http import request
+from werkzeug.wrappers import Response
+from werkzeug.datastructures import Headers
+from datetime import datetime
+from StringIO import StringIO
+from gzip import GzipFile
+from StringIO import StringIO as IO
+import simplejson as json
+import gzip
+import logging
+
+LOGGER = logging.getLogger(__name__)
+
+class PaymentsSales(http.Controller):
+    '''
+        Get server date
+    '''
+    def get_server_date(self):
+        return datetime.now().strftime('%y-%m-%d')
+
+    '''
+        Get partner customer
+    '''
+    def get_user(self):
+        user = request.env.user
+
+        return {
+            'id': user.id,
+            'name': user.name,
+            'displayName': user.display_name,
+            'company': {
+                '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,
+                    'displayName': user.company_id.currency_id.display_name,
+                    'symbol': user.company_id.currency_id.symbol
+            }
+        }
+
+    '''
+        Get partner customer
+    '''
+    def get_customers(self):
+        domain = [('customer', '=', True), ('active', '=', True), ('credit', '>', 0)]
+        partners = []
+
+        for customer in request.env['res.partner'].search(domain):
+            invoices = []
+            partner_invoice = []
+
+            for invoice_ids in customer.invoice_ids:
+                if invoice_ids.state == 'open':
+                    partner_invoice.append(invoice_ids.id)
+
+            if customer.is_company == True:
+                for child in customer.child_ids:
+                    for invoice_ids in child.invoice_ids:
+                        if invoice_ids.state == 'open':
+                            partner_invoice.append(invoice_ids.id)
+
+            # for invoice in request.env['account.invoice'].browse(partner_invoice):
+            for invoice in request.env['account.invoice'].search([('id', 'in', partner_invoice),('state', '=', 'open')]):
+                movelines = []
+                moves = []
+                currency_symbol = ""
+
+                for move in invoice.move_id:
+                    for moveline in move.line_id:
+                        if moveline.amount_residual > 0 and moveline.state != "draft" and moveline.credit <= 0:
+                            movelines.append({
+                                'id': moveline.id,
+                                'amountResidual': moveline.amount_residual,
+                                'credit': moveline.credit,
+                                'debit': moveline.debit,
+                                'dateMaturity': moveline.date_maturity,
+                                'invoice': invoice.id
+                            })
+
+                invoices.append({
+                    'id': invoice.id,
+                    'number': invoice.number,
+                    'dateInvoice': invoice.date_invoice,
+                    'amountTotal': invoice.amount_total,
+                    'residual': invoice.residual,
+                    'moveLines': movelines,
+                    'currency' : {
+                        'id': invoice.currency_id.id,
+                        'name': invoice.currency_id.name,
+                        'displayName': invoice.currency_id.display_name,
+                        'symbol': invoice.currency_id.symbol,
+                        'rateSilent': invoice.currency_id.rate_silent,
+                        'thousandsSeparator': invoice.currency_id.thousands_separator,
+                        'decimalSeparator': invoice.currency_id.decimal_separator,
+                        'decimalPlaces': invoice.currency_id.decimal_places
+                    }
+                })
+
+            partners.append({
+                'id': customer.id,
+                'name': customer.name,
+                'displayName': customer.display_name,
+                'ruc': customer.ruc,
+                'imageMedium': customer.image_medium,
+                'phone': customer.phone,
+                'mobile': customer.mobile,
+                'email': customer.email,
+                'credit': customer.credit,
+                'creditLimit': customer.credit_limit,
+                'invoices': invoices
+            })
+
+        return partners
+
+    '''
+        Get Journal
+    '''
+    def get_journals(self):
+        domain =[('active', '=', True),('type', 'in',['bank', 'cash'])]
+        paymentsJournals = []
+
+        for journal in request.env['account.journal'].search(domain, order="id"):
+            if not (journal.store_ids >= request.env.user.store_ids):
+                continue
+
+            paymentsJournals.append({
+                'id': journal.id,
+                'name': journal.name,
+                'displayName': journal.display_name,
+                'code': journal.code,
+                'cashControl': journal.cash_control,
+                'type': journal.type,
+                'currency': {
+                    'id': journal.currency.id,
+                    'name': journal.currency.name,
+                    'displayName': journal.currency.display_name,
+                    'symbol': journal.currency.symbol,
+                    'rateSilent': journal.currency.rate_silent
+                },
+                'defaultCreditAccount':{
+                    'id': journal.default_credit_account_id.id,
+                    'name': journal.default_credit_account_id.name,
+                    'displayName': journal.default_credit_account_id.display_name,
+                    'code': journal.default_credit_account_id.code,
+                    'exchangeRate': journal.default_credit_account_id.exchange_rate,
+                    'foreignBalance': journal.default_credit_account_id.foreign_balance,
+                    'reconcile': journal.default_credit_account_id.reconcile,
+                    'debit': journal.default_credit_account_id.debit,
+                    'credit': journal.default_credit_account_id.credit,
+                    'currencyMode': journal.default_credit_account_id.currency_mode,
+                    'companyCurrency':{
+                        'id': journal.default_credit_account_id.company_currency_id.id,
+                        'name': journal.default_credit_account_id.company_currency_id.name,
+                        'displayName': journal.default_credit_account_id.company_currency_id.display_name,
+                        'symbol': journal.default_credit_account_id.company_currency_id.symbol,
+                        'rateSilent': journal.default_credit_account_id.company_currency_id.rate_silent
+                    },
+                    'currency':{
+                        'id': journal.default_credit_account_id.currency_id.id,
+                        'name': journal.default_credit_account_id.currency_id.name,
+                        'displayName': journal.default_credit_account_id.currency_id.display_name,
+                        'symbol': journal.default_credit_account_id.currency_id.symbol,
+                        'rateSilent': journal.default_credit_account_id.currency_id.rate_silent
+                    },
+                }
+            })
+
+        return paymentsJournals
+    '''
+        Get Currency
+    '''
+    def get_currency(self):
+        return [{
+            'id': currency.id,
+            'name': currency.name,
+            'displayName': currency.display_name,
+            'base': currency.base,
+            'accuracy': currency.accuracy,
+            'rateSilent': currency.rate_silent,
+            'rounding': currency.rounding,
+            'symbol': currency.symbol,
+            'position': currency.position,
+            'thousandsSeparator': currency.thousands_separator,
+            'decimalSeparator': currency.decimal_separator,
+            'decimalPlaces': currency.decimal_places
+        } for currency in request.env['res.currency'].search([('active', '=', True)])]
+
+
+    '''
+        Make JSON response
+    '''
+    def make_json_response(self, data=None, status=200):
+        return Response(json.dumps(data), status=status, content_type='application/json')
+
+    '''
+        Make GZIP to JSON response
+    '''
+    def make_gzip_response(self, data=None, status=200):
+        gzip_buffer = IO()
+        with GzipFile(mode='wb', compresslevel=9, fileobj=gzip_buffer) as gzip_file:
+            gzip_file.write(json.dumps(data))
+
+        contents = gzip_buffer.getvalue()
+        gzip_buffer.close()
+
+        headers = Headers()
+        headers.add('Content-Encoding', 'gzip')
+        headers.add('Vary', 'Accept-Encoding')
+        headers.add('Content-Length', len(contents))
+
+        return Response(contents, status=status, headers=headers, content_type='application/json')
+
+    '''
+        Logger Info
+    '''
+    def make_info_log(self, log):
+        LOGGER.info(log)
+
+    '''
+        New Payments resource router
+    '''
+    @http.route('/eiru_payments/init', auth='user', methods=['GET'], cors='*')
+    def init_payments(self, **kw):
+        self.make_info_log('Sending JSON response')
+
+        return self.make_gzip_response({
+            'date': self.get_server_date(),
+            'user': self.get_user(),
+            'customers': self.get_customers(),
+            'journals': self.get_journals(),
+            'currencies': self.get_currency()
+        })

+ 1 - 0
package.json

@@ -27,6 +27,7 @@
 		"webpack-livereload-plugin": "^0.11.0"
 	},
 	"dependencies": {
+		"axios": "^0.17.0",
 		"fuse.js": "^3.0.5",
 		"vue": "^2.4.1",
 		"vue-form-wizard": "^0.6.1",

+ 19 - 0
yarn.lock

@@ -193,6 +193,13 @@ aws4@^1.2.1:
   version "1.6.0"
   resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.6.0.tgz#83ef5ca860b2b32e4a0deedee8c771b9db57471e"
 
+axios@^0.17.0:
+  version "0.17.0"
+  resolved "https://registry.yarnpkg.com/axios/-/axios-0.17.0.tgz#7da747916db803f761651d6091d708789b953c6a"
+  dependencies:
+    follow-redirects "^1.2.3"
+    is-buffer "^1.1.5"
+
 babel-code-frame@^6.11.0, babel-code-frame@^6.22.0:
   version "6.22.0"
   resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.22.0.tgz#027620bee567a88c32561574e7fd0801d33118e4"
@@ -1371,6 +1378,12 @@ debug@^2.1.1, debug@^2.2.0:
   dependencies:
     ms "2.0.0"
 
+debug@^2.6.9:
+  version "2.6.9"
+  resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"
+  dependencies:
+    ms "2.0.0"
+
 debug@~2.2.0:
   version "2.2.0"
   resolved "https://registry.yarnpkg.com/debug/-/debug-2.2.0.tgz#f87057e995b1a1f6ae6a4960664137bc56f039da"
@@ -1701,6 +1714,12 @@ flatten@^1.0.2:
   version "1.0.2"
   resolved "https://registry.yarnpkg.com/flatten/-/flatten-1.0.2.tgz#dae46a9d78fbe25292258cc1e780a41d95c03782"
 
+follow-redirects@^1.2.3:
+  version "1.2.5"
+  resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.2.5.tgz#ffd3e14cbdd5eaa72f61b6368c1f68516c2a26cc"
+  dependencies:
+    debug "^2.6.9"
+
 for-in@^0.1.3:
   version "0.1.8"
   resolved "https://registry.yarnpkg.com/for-in/-/for-in-0.1.8.tgz#d8773908e31256109952b1fdb9b3fa867d2775e1"