Browse Source

commit inicial

Rodney Enciso Arias 7 years ago
commit
e003a057be

+ 1 - 0
__init__.py

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

BIN
__init__.pyc


+ 22 - 0
__openerp__.py

@@ -0,0 +1,22 @@
+# -*- coding ;utf-8 -*-
+{
+    'name': 'Account bank statement voucher import',
+    'author':  'Eiru Software / Adrielso Kunert - Rodney Enciso',
+    'version': '8.0.1.1.0',
+    'category': 'account',
+    'description': "Importar pagos en registro de caja.",
+    'depends':[
+                'account_bank_voucher',
+                'account',
+                'eiru_assets'
+              ],
+    'data':   [
+                'views/voucher_import.xml',
+                'views/template.xml',
+              ],
+    'qweb':   [
+                'static/src/xml/*.xml'
+              ],
+
+    'installable': True,
+}

BIN
account.pyc


BIN
static/description/icon.png


+ 8 - 0
static/src/css/style.css

@@ -0,0 +1,8 @@
+/*.oe_right.oe_button_box.payslip_import{
+    width: auto;
+    height:auto;
+}*/
+.oe_right.oe_button_box{
+    width: auto;
+    height:auto;
+}

+ 230 - 0
static/src/js/account_bank_statement_voucher_import.js

@@ -0,0 +1,230 @@
+openerp.account_bank_statement_voucher_import = function (instance, local) {
+    local.widgetInstance = null;
+    local.parentInstance = null;
+
+    local.VoucherImportWidget = instance.Widget.extend({
+        template: 'account_bank_statement_voucher_import.VoucherImport',
+        id : undefined,
+        voucherImport : [],
+        statementLine: [],
+        accountVoucher: [],
+        statement: [],
+
+        init: function (parent) {
+            this._super(parent);
+        },
+        // Actualizar id del Objeto
+        updateId : function(id){
+            var self = this;
+            self.id=id;
+        },
+        start: function () {
+            var self = this;
+            this.$el.click(function (e){
+                self.fetchInitial();
+            });
+        },
+        // Iniciar
+        fetchInitial: function(){
+            var self= this;
+            self.fetchBankStatementLine().then(function(statementLine){
+                return statementLine;
+            }).then(function(statementLine){
+                self.statementLine = statementLine;
+                return self.fetchBankStatement();      
+            }).then(function(statement){
+                self.statement = statement;
+                return self.fetchAcVoucher();
+            }).then(function(accountVoucher){
+                self.accountVoucher = accountVoucher;
+                return self.fetchJoinVoucher();
+            }).then(function(voucherImport){
+                self.voucherImport = voucherImport;
+                return self.insertBankStatementLine();
+            }).then(function(bankLine){
+                local.parentInstance.reload();
+                if (bankLine){
+                    instance.web.notification.do_notify("Felicitaciones", "Los pagos han sido importados con éxito.");
+                }else{
+                    instance.web.notification.do_warn("Atención ","No hay pagos para ser importados.");
+                }
+            });
+        },
+
+        // linea de Caja
+        fetchBankStatementLine : function(){
+            var self = this;
+            var defer = $.Deferred();
+
+            var fields=['id','ref','name','statement_id'];
+            var domain=[['statement_id','=',self.id]];
+
+            var statementLine = new instance.web.Model('account.bank.statement.line');
+
+            statementLine.query(fields).filter(domain).all().then(function (results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+
+        // Caja
+        fetchBankStatement : function(){
+            var self = this;
+            var defer = $.Deferred();
+
+            var fields=['id','journal_id'];
+            var domain=[['id','=',self.id]];
+
+            var statement = new instance.web.Model('account.bank.statement');
+
+            statement.query(fields).filter(domain).all().then(function (results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+
+        // consultar pagos
+        fetchAcVoucher : function(){
+            var self = this;
+            var defer =$.Deferred();
+
+            var name = _.flatten(_.map(self.statementLine,function(map){
+                return map.name;
+            }));
+            var journal_id = _.flatten(_.map(self.statement,function(map){
+                return map.journal_id[0];
+            }));
+            var fields =['id','reference','partner_id','state','amount','journal_id','type','bank_statement_line_ids','move_id','account_id'];
+            var domain =[['state','=','posted'],['reference','not in',name],['bank_statement_line_ids', '=', false],['journal_id','=',journal_id]];
+            var accountVoucher = new instance.web.Model('account.voucher');
+
+            accountVoucher.query(fields).filter(domain).all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        
+        // Generar Objeto principal
+        fetchJoinVoucher:function(){
+            var self = this;
+            var defer = $.Deferred();
+            var voucherImport=[];
+            var journal;
+            for (var i = 0; i < self.accountVoucher.length; i++) {
+                voucher = self.accountVoucher[i];
+                if(voucher.type=='receipt'){
+                    voucherImport.push({
+                        name : voucher.reference,
+                        amount : voucher.amount,
+                        type : voucher.type,
+                        partner_id : voucher.partner_id[0],
+                        account_id : voucher.account_id[0],
+                        statement_id: this.id,
+                        ref : voucher.name,
+                        voucher_id : voucher.id,
+                        journal_entry_id : voucher.move_id[0] 
+                    });
+                } else {
+                    voucherImport.push({
+                        name : voucher.reference,
+                        amount : voucher.amount*-1,
+                        type : voucher.type,
+                        partner_id : voucher.partner_id[0],
+                        account_id : voucher.account_id[0],
+                        statement_id: this.id,
+                        ref : voucher.name,
+                        voucher_id : voucher.id,
+                        journal_entry_id : voucher.move_id[0]
+                    }); 
+                }         
+            }
+            defer.resolve(voucherImport);
+            return defer;
+        },
+
+        // insertar la Linea
+
+        insertBankStatementLine : function(){
+            var self =this;
+            var defer = $.Deferred();
+            var accountBanckStatementLine = new instance.web.Model('account.bank.statement.line');
+
+            self.asyncLoopFactory(self.voucherImport.length, function (loop) {
+                var objeto = self.voucherImport[loop.iteration()];
+
+                accountBanckStatementLine.call('create',[objeto], {
+                    context: new instance.web.CompoundContext()
+                }).then(function (results) {
+                    loop.next();
+                });
+            }, function () {
+                defer.resolve(self.voucherImport.length);
+            });
+
+            return defer;
+        },
+        /* ---------------------------------------------------------------------
+        * Description: Async loop util v2 written by Robert Gauto.
+        * --------------------------------------------------------------------*/
+        asyncLoopFactory : function (iterations, func, callback) {
+            var index = 0;
+            var done = false;
+            var loop = {
+                next: function () {
+                    if (done) {
+                        return;
+                    }
+
+                    if (index < iterations) {
+                        index++;
+                        func(loop);
+
+                    } else {
+                        done = true;
+                        callback();
+                    }
+                },
+
+                iteration: function () {
+                    return index - 1;
+                },
+
+                break: function () {
+                    done = true;
+                    callback();
+                }
+            };
+
+            loop.next();
+            return loop;
+        },
+
+    });
+
+if (instance.web && instance.web.FormView) {
+    instance.web.FormView.include({
+        load_record: function (record) {
+            this._super.apply(this, arguments);
+
+            if (this.model !== 'account.bank.statement') return;
+
+            local.parentInstance = this;
+
+            if (local.widgetInstance) {
+                local.widgetInstance.updateId(record.id);
+            }
+
+            if (this.$el.find('.import_voucher').length != 0) return;
+
+            local.widgetInstance = new local.VoucherImportWidget(this);
+
+            var elemento = this.$el.find('.oe_form_sheet.oe_form_sheet_width');
+            elemento =  elemento.find('.oe_right.oe_button_box.voucher_import');
+
+            local.widgetInstance.appendTo(elemento);
+            local.widgetInstance.updateId(record.id);
+        }
+    });
+}
+
+}

+ 9 - 0
static/src/xml/account_bank_voucher_import.xml

@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<templates xml:space="preserve">
+	<t t-name="account_bank_statement_voucher_import.VoucherImport">
+		<button class="import_voucher oe_stat_button btn btn-default oe_inline">
+			<div class="stat_button_icon fa fa-list"></div>
+			<div>Pagos</div>
+		</button>
+	</t>
+</templates>

+ 10 - 0
views/template.xml

@@ -0,0 +1,10 @@
+<openerp>
+    <data>
+        <template id="account_bank_statement_voucher_import.eiru_assets" name="account_bank_statement_voucher_import_assets" inherit_id="eiru_assets.assets">
+            <xpath expr="." position="inside">
+                <link rel="stylesheet" href="/account_bank_statement_voucher_import/static/src/css/style.css"/>
+                <script type="text/javascript" src="/account_bank_statement_voucher_import/static/src/js/account_bank_statement_voucher_import.js"/>
+            </xpath>
+        </template>
+    </data>
+</openerp>

+ 25 - 0
views/voucher_import.xml

@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<openerp>
+	<data>
+        <record id="views_account_bank_voucher_import2" model="ir.ui.view">
+            <field name="name">account.bank.statement.voucher.import2</field>
+            <field name="model">account.bank.statement</field>
+            <field name="inherit_id" ref="account.view_bank_statement_form2"/>
+            <field name="arch" type="xml">
+                <label for="name" position="before">
+                    <div class="oe_right oe_button_box voucher_import" attrs="{'invisible': [('state','!=','open')]} "></div>
+                </label>
+            </field>
+        </record>
+        <record id="views_account_bank_voucher_import" model="ir.ui.view">
+            <field name="name">account.bank.statement.voucher.import</field>
+            <field name="model">account.bank.statement</field>
+            <field name="inherit_id" ref="account.view_bank_statement_form"/>
+            <field name="arch" type="xml">
+                <label for="name" position="before">
+                    <div class="oe_right oe_button_box voucher_import" attrs="{'invisible': [('state','!=','draft')]}"></div>
+                </label>
+            </field>
+        </record>
+	</data>
+</openerp>