Prechádzať zdrojové kódy

[ADD] Commit initial

Adrielso 7 rokov pred
commit
911bf1d5ca

+ 1 - 0
__init__.py

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

+ 22 - 0
__openerp__.py

@@ -0,0 +1,22 @@
+# -*- coding ;utf-8 -*-
+{
+    'name': 'Account bank payslip import',
+    'author':  'Adrielso Kunert',
+    'version': '8.0.1.1.0',
+    'category': 'hr',
+    'description': "Importar nominas de funcionarios en registro de caja.",
+    'depends':[
+                'hr',
+                'account',
+                'eiru_assets'
+              ],
+    'data':   [
+                'views/payslip_import.xml',
+                'views/template.xml',
+              ],
+    'qweb':   [
+                'static/src/xml/*.xml'
+              ],
+
+    'installable': True,
+}

BIN
static/description/icon.png


+ 252 - 0
static/src/js/account_bank_payslip_import.js

@@ -0,0 +1,252 @@
+openerp.account_bank_payslip_import = function (instance, local) {
+    local.widgetInstance = null;
+    local.parentInstance = null;
+
+    local.PayslipImportWidget = instance.Widget.extend({
+        template: 'account_bank_payslip_import.PayslipImport',
+        id : undefined,
+        hrPaylslip : [],
+        hrPaylslipLine : [],
+        payslipImport : [],
+        hrEmployee : [],
+        statementLine:[],
+
+        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.fetchHrPayslip(statementLine);
+            }).then(function(hrPaylslip){
+                self.hrPaylslip = hrPaylslip;
+                return self.fetchHrPayslipLine(hrPaylslip);
+            }).then(function(hrPaylslipLine){
+                self.hrPaylslipLine = hrPaylslipLine;
+                return self.fetchEmployee();
+            }).then(function(hrEmployee){
+                self.hrEmployee=hrEmployee;
+                return self.fetchJoinPayslip();
+            }).then(function(payslipImport){
+                self.payslipImport = payslipImport;
+                return self.insertBankStatementLine();
+            }).then(function(bankLine){
+                local.parentInstance.reload();
+                if (bankLine){
+                    instance.web.notification.do_notify("Felicitación","Las nóminas han sido importado con éxito.");
+                }else{
+                    instance.web.notification.do_warn("Atención ","No hay nóminas para ser importadas.");
+                }
+            });
+        },
+        // linea de Caja
+        fetchBankStatementLine : function(){
+            var self = this;
+            var defer = $.Deferred();
+
+            var fields=['id','ref'];
+            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;
+        },
+        // consulta Nomina
+        fetchHrPayslip : function(statementLine){
+            var self = this;
+            var defer =$.Deferred();
+
+            var ref = _.flatten(_.map(statementLine,function(map){
+                return map.ref;
+            }));
+
+            var fields =['id','number','employee_id','state'];
+            var domain =[['state','=','done'],['number','not in',ref]];
+            var hrPaylslip = new instance.web.Model('hr.payslip');
+
+            hrPaylslip.query(fields).filter(domain).all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        // consulta Lineas de Nomina
+        fetchHrPayslipLine : function(hrPaylsli){
+            var self = this;
+            var defer =$.Deferred();
+            payslip = _.flatten(_.map(hrPaylsli,function(map){
+                return map.id;
+            }));
+
+            var fields =['id','slip_id','code','amount','name'];
+            var domain =[['code','=','NET'],['slip_id','in',payslip]];
+            var hrPaylslip = new instance.web.Model('hr.payslip.line');
+
+            hrPaylslip.query(fields).filter(domain).all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        // consultar employee
+        fetchEmployee : function(){
+            var self = this;
+            var defer = $.Deferred();
+            var id_employee =_.flatten(_.map(self.hrPaylslip, function(map){
+                return map.employee_id[0];
+            }));
+
+            var fields=['id','name','address_home_id'];
+            var domain=[['id','in',id_employee]];
+
+            var hrEmployee= new instance.web.Model('hr.employee');
+
+            hrEmployee.query(fields).filter(domain).all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        // Generar Objeto principal
+        fetchJoinPayslip:function(){
+            var self = this;
+            var defer = $.Deferred();
+            var itemPayslip;
+            var itemLine;
+            var payslipImport=[];
+            var employee;
+
+            for (var i = 0; i < self.hrPaylslip.length; i++) {
+                itemPayslip = self.hrPaylslip[i];
+                itemLine = self.getPayslipLine(itemPayslip.id);
+                employee = self.getEmployee(itemPayslip.employee_id[0]);
+
+                if (itemLine){
+                    payslipImport.push({
+                                        statement_id: this.id,
+                                        name : itemLine.slip_id[1],
+                                        ref :itemPayslip.number,
+                                        partner_id :employee.address_home_id[0],
+                                        amount : itemLine.amount*-1
+                                    });
+                }
+            }
+
+            defer.resolve(payslipImport);
+            return defer;
+        },
+        // Obtener Payslip Linea
+        getPayslipLine : function(id_slip){
+            var self = this;
+            return _.filter(self.hrPaylslipLine,function(item){
+                return item.slip_id[0] === id_slip;
+            }).shift();
+        },
+        // obtener partner
+        getEmployee : function(employee_id){
+            var self = this;
+            return _.filter(self.hrEmployee,function(item){
+                return item.id === employee_id;
+            }).shift();
+        },
+        // insertar la Linea
+        insertBankStatementLine : function(){
+            var self =this;
+            var defer = $.Deferred();
+            var accountBanckStatementLine = new instance.web.Model('account.bank.statement.line');
+
+            self.asyncLoopFactory(self.payslipImport.length, function (loop) {
+                var objeto = self.payslipImport[loop.iteration()];
+
+                accountBanckStatementLine.call('create',[objeto], {
+                    context: new instance.web.CompoundContext()
+                }).then(function (results) {
+                    loop.next();
+               });
+             }, function () {
+                defer.resolve(self.payslipImport.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_payslip').length != 0) return;
+
+                local.widgetInstance = new local.PayslipImportWidget(this);
+
+                var elemento = this.$el.find('.oe_form_sheet.oe_form_sheet_width');
+                elemento =  elemento.find('.oe_right.oe_button_box.payslip_import');
+
+                local.widgetInstance.appendTo(elemento);
+                local.widgetInstance.updateId(record.id);
+            }
+        });
+    }
+
+}

+ 10 - 0
static/src/xml/account_bank_payslip_import.xml

@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<templates xml:space="preserve">
+    <t t-name="account_bank_payslip_import.PayslipImport">
+        <button class="import_payslip oe_button oe_form_button_save oe_highlight">
+          <i class="fa fa-exchange" aria-hidden="true"></i>
+          Nómina
+        </button>
+  </t>
+</templates>

+ 15 - 0
views/payslip_import.xml

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<openerp>
+	<data>
+        <record id="views_account_bank_payslip_import" model="ir.ui.view">
+            <field name="name">account.bank.statement.import.payslip</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 payslip_import" attrs="{'invisible': [('state','!=','open')]} "  groups="base.group_hr_manager"></div>
+                </label>
+            </field>
+        </record>
+	</data>
+</openerp>

+ 10 - 0
views/template.xml

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