Browse Source

[ADD] Unlink Statement

adrielso 6 years ago
parent
commit
afc432a201

+ 71 - 0
models/account_bank_statement_utility.py

@@ -672,3 +672,74 @@ class AccountBankStatementUtility(models.Model):
     @api.multi
     def button_open(self):
         return super(AccountBankStatementUtility, self).button_open()
+
+
+    '''
+          _   _       _ _       _      ____  _        _                            _
+         | | | |_ __ | (_)_ __ | | __ / ___|| |_ __ _| |_ ___ _ __ ___   ___ _ __ | |_
+         | | | | '_ \| | | '_ \| |/ / \___ \| __/ _` | __/ _ \ '_ ` _ \ / _ \ '_ \| __|
+         | |_| | | | | | | | | |   <   ___) | || (_| | ||  __/ | | | | |  __/ | | | |_
+          \___/|_| |_|_|_|_| |_|_|\_\ |____/ \__\__,_|\__\___|_| |_| |_|\___|_| |_|\__|
+    '''
+    '''
+        Get Statement
+    '''
+    @api.model
+    def eiru_get_bank_statement_unlink(self, id):
+        return [{
+            'id': statement.id,
+            'name': statement.name,
+            'state': statement.state,
+            'currencystatement': {
+                'id': statement.currency.id,
+                'symbol': statement.currency.symbol,
+                'rate': statement.currency.rate,
+                'thousandsSeparator': statement.currency.thousands_separator,
+                'decimalSeparator': statement.currency.decimal_separator,
+                'decimalPlaces': statement.currency.decimal_places,
+                'position': statement.currency.position,
+            },
+            'lineStatement': [{
+                'id': line.id,
+                'name': line.name,
+                'ref': line.ref,
+                'amount': line.amount,
+                'date': line.date,
+                'casBoxTransfer': [{
+                    'id': transfer.id,
+                    'name': transfer.name,
+                    'amount': transfer.amount,
+                    'ref': transfer.ref,
+                    'date': transfer.date,
+                    'inputStatement': transfer.input_statement.id,
+                    'outputStatement': transfer.output_statement.id,
+                    'inputStatementState': transfer.input_statement.state,
+                    'outputStatementState': transfer.output_statement.state
+                }for transfer in self.env['cash.box.transfer'].search(['|',('input_line.id', '=', line.id), ('output_line.id', '=', line.id)])],
+                'casBoxIn': [{
+                    'id': boxIn.id,
+                    'name': boxIn.name,
+                    'amount': boxIn.amount,
+                    'ref': boxIn.ref,
+                    'date': boxIn.date,
+                    'active': boxIn.active
+                }for boxIn in self.env['cash.box.in'].search([('line_id.id', '=', line.id)])],
+                'casBoxOut': [{
+                    'id': boxOut.id,
+                    'name': boxOut.name,
+                    'amount': boxOut.amount,
+                    'ref': boxOut.ref,
+                    'date': boxOut.date,
+                    'active': boxOut.active
+                }for boxOut in self.env['cash.box.out'].search([('line_id.id', '=', line.id)])]
+            }for line in statement.line_ids]
+        }for statement in self.env['account.bank.statement'].browse(id)]
+
+    '''
+        Unlink Statement
+    '''
+    @api.model
+    def eiru_unlink_statement(self, id):
+        # print("\n\neiru_unlink_statement\n\n")
+
+        # import web_pdb; web_pdb.set_trace()

+ 3 - 3
models/cashbox_statement_confirm.py

@@ -87,7 +87,7 @@ class cashbox_statement_confirm(models.Model):
             'userConfirmLogin': casBox.user_confirm.login,
             'amountStatement': casBox.amount_statement,
             'amountReal': casBox.amount_real,
-            'amountDifference': casBox.amount_difference if (casBox.amount_real >= casBox.amount_statement) else (-casBox.amount_difference),
+            'amountDifference': casBox.amount_difference,
             'amountNextOpen': casBox.amount_next_open,
             'transferCasBox': [{
                 'id': confirm.id,
@@ -225,10 +225,10 @@ class AccountBankStatementConfirm(models.Model):
             'amount_statement': amountStatement,
             'amount_real': values['amountReal'],
             'line_difference': lineBalance.id if (lineBalance) else '',
-            'amount_difference': abs(lineBalance.amount) if (lineBalance) else 0.0,
+            'amount_difference': lineBalance.amount if (lineBalance) else 0.0,
             'line_next_open': lineNextOpen.id if(lineNextOpen) else '',
             'amount_next_open': abs(lineNextOpen.amount) if(lineNextOpen) else 0.0,
-            'state_avaliable': True if(lineNextOpen) else False,
+            'state_avaliable': True if(lineNextOpen and lineNextOpen.amount > 0) else False,
         }
 
 

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

@@ -15,6 +15,10 @@
     width: auto;
     float: left;
 }
+.eiru-statement-unlink {
+    width: auto;
+    float: left;
+}
 .eiru-statement-utility-cancel {
     width: auto;
     float: left;
@@ -500,3 +504,82 @@
     font-size: 14pt;
     font-weight: bold;
 }
+
+
+.line-unlink-messege {
+    display: none;
+    margin-top: 5px;
+    margin-left: 20px;
+    color: red;
+}
+
+.unlink-statement-table {
+    margin-top: 0px !important;
+    margin-bottom: 0px !important;
+}
+.expired-account-modal .modal-head-wrapper-statement-unlink {
+    width: 100%;
+}
+.expired-account-modal .modal-item-statement-unlink {
+    width: 100%;
+    height: 212px;
+    overflow-y: auto;
+}
+.expired-account-modal .unlink-statement-table table tbody tr {
+    height: 35px;
+}
+.expired-account-modal .unlink-statement-table table thead tr {
+    height: 40px !important;
+}
+/*id*/
+.expired-account-modal .unlink-statement-table table tbody tr td:nth-child(1){
+    display: none;
+}
+.expired-account-modal .unlink-statement-table table thead tr th:nth-child(1){
+    display: none;
+}
+/* Date */
+.expired-account-modal .unlink-statement-table table tbody tr td:nth-child(2){
+    width: 120px ;
+    font-size: 12pt;
+    text-align: left;
+    padding-left: 10px;
+    padding-top: 8px;
+}
+.expired-account-modal .unlink-statement-table table thead tr th:nth-child(2){
+    width: 120px;
+    padding-right: 10px;
+    text-align: left;
+    font-size: 14pt;
+    font-weight: bold;
+}
+/* Referencia */
+.expired-account-modal .unlink-statement-table table tbody tr td:nth-child(3){
+    width: 500px ;
+    padding-right: 10px;
+    text-align: left;
+    font-size: 12pt;
+    padding-top: 8px;
+}
+.expired-account-modal .unlink-statement-table table thead tr th:nth-child(3){
+    width: 500px;
+    padding-right: 10px;
+    text-align: left;
+    font-size: 14pt;
+    font-weight: bold;
+}
+/* amount */
+.expired-account-modal .unlink-statement-table table tbody tr td:nth-child(4){
+    width: 200px;
+    padding-right: 20px;
+    text-align: right;
+    font-size: 12pt;
+    padding-top: 8px;
+}
+.expired-account-modal .unlink-statement-table table thead tr th:nth-child(4){
+    width: 217px;
+    padding-right: 20px;
+    text-align: center;
+    font-size: 14pt;
+    font-weight: bold;
+}

+ 245 - 0
static/src/js/eiru_statement_unlink.js

@@ -0,0 +1,245 @@
+(function() {
+    openerp.widgetInstanceStatementUnlink = null;
+    openerp.parentInstanceStatementUnlink = {};
+    var QWeb = openerp.web.qweb;
+    var instanceWeb = openerp.web;
+    // Abrir caja
+    openerp.EiruStatementUnlink = openerp.Widget.extend({
+        template: 'EiruStatementUtility.Unlink',
+        id: undefined,
+        buttons: undefined,
+        bankStatement: [],
+        resUser: [],
+        statementConfig: [],
+        /* init */
+        init: function(parent) {
+            this._super(parent);
+            this.buttons = parent.$buttons;
+        },
+        /* start */
+        start: function () {
+            var self = this
+            this.$el.click(function() {
+                self.fetchInitial();
+            });
+            self.buttons.click(function(e) {
+                /* C (Crear) */
+                if (e.target.accessKey === 'C')
+                    self.$el.css('display','none');
+                /* E (Editar) */
+                if (e.target.accessKey === 'E')
+                    self.$el.css('display','none');
+                /* S (Guarrdar) */
+                if (e.target.accessKey === 'S')
+                    self.$el.css('display','flex');
+                /* D (Cancelar) */
+                if (e.target.accessKey === 'D')
+                    self.$el.css('display','flex');
+            });
+        },
+        /* Actualizar Id de la visat actual  */
+        updateId: function(id) {
+            var self = this;
+            self.id = id;
+        },
+        /* Reload Page*/
+        reloadPage: function() {
+             openerp.parentInstanceStatementUnlink.reload();
+        },
+        /* Description: Función para remover el modal */
+        removeModal: function() {
+            $('.expired-account-modal').remove();
+            $('.modal-backdrop').remove();
+        },
+        /* Método inicial */
+        fetchInitial: function() {
+            var self = this;
+            self.fetchBankStatementUnlink(self.id).then(function(bankStatement) {
+                return bankStatement;
+            }).then(function(bankStatement) {
+                self.bankStatement = bankStatement;
+
+        //         return self.fetchGetUserLogin();
+        //     }).then(function(resUser){
+        //         self.resUser = resUser;
+        //         return self.fetchStatementConfigTransfer();
+        //     }).then(function(statementConfig){
+        //         self.statementConfig = statementConfig;
+        //         /* Verificar el usuario */
+        //         if (!self.resUser.length){
+        //             instanceWeb.notification.do_warn("Atencion", "No estas autorizado a realizar esta operación.");
+        //             return  false;
+        //         }
+        //         /* Verificar si existe configuracion */
+        //         if (!self.statementConfig.length){
+        //             instanceWeb.notification.do_warn("Atencion", "No estas autorizado a realizar esta operación, no existe configuración de caja.");
+        //             return  false;
+        //         }
+        //         /* Verificar si el usuario tiene autorización para cerrar la caja */
+        //         if (!(_.contains(self.statementConfig[0].statement_cancel_user, self.resUser[0].id))){
+        //             instanceWeb.notification.do_warn("Atencion", "El usuario no tiene autorización para cancelar la caja.");
+        //             return false;
+        //         }
+
+                return self.showModal();
+            });
+        },
+        /* Get Account bank Statement */
+        fetchBankStatementUnlink: function(id) {
+            var bankStatement = new instanceWeb.Model('account.bank.statement');
+            return bankStatement.call('eiru_get_bank_statement_unlink',[parseInt(id)], {
+                context: new instanceWeb.CompoundContext()
+            });
+        },
+        /* Get state  Object*/
+        getStatementState: function(statement, state){
+            return _.filter(statement,function(item){
+                return item.state === state;
+            });
+        },
+        /* Filter Object Id*/
+        getStateTransfer: function(statement, id) {
+            return _.filter(statement, function(item){
+                return item.id === id;
+            });
+        },
+        /* filter line statement */
+        filterStatementLine: function() {
+            var self= this;
+            var statement = self.bankStatement[0];
+            var currency = statement.currencystatement;
+            var lineStatement = [];
+
+            _.each(statement.lineStatement, function(line){
+                var state = statement.state
+
+                if (!!line.casBoxTransfer.length){
+                    if (line.casBoxTransfer[0].inputStatementState !== statement.state)
+                        state = line.casBoxTransfer[0].inputStatementState
+
+                    if (line.casBoxTransfer[0].outputStatementState !== statement.state)
+                        state = line.casBoxTransfer[0].outputStatementState
+                }
+
+                lineStatement.push({
+                    'id': line.id,
+                    'date': moment(line.date).format("DD-MM-YYYY"),
+                    'name': line.name,
+                    'amount': accounting.formatNumber(line.amount, currency.decimalPlaces, currency.thousandsSeparator, currency.decimalSeparator),
+                    'state': state
+                });
+            });
+            return lineStatement;
+        },
+        // /*Modal  */
+        showModal: function() {
+            var self = this;
+            var defer =$.Deferred();
+            var results = true;
+            var lineStatement = self.filterStatementLine();
+
+            var modal = QWeb.render('ModalStatementUtility.Unlink',{
+                'statementLine': lineStatement
+            });
+
+            $('.openerp_webclient_container').after(modal);
+            $('.expired-account-modal').modal();
+
+            /* Transferencia */
+            var lineMessege = $('.expired-account-modal').find('.line-unlink-messege');
+            var table = $('.expired-account-modal').find('.table-tbody').find('tr');
+            var buttonSave = $('.expired-account-modal').find('.button-save');
+
+            if (!lineStatement.length)
+                $('.expired-account-modal').find('.statement-line').css('display', 'none');
+
+            _.each(table, function(tr) {
+                var idLine  = (($(tr).children()[0]).textContent).trim();
+                var stateStatement = self.getStateTransfer(lineStatement, parseInt(idLine));
+                if (!stateStatement.length)
+                    return false;
+
+                if (stateStatement[0].state === 'confirm'){
+                    $(tr).css('color','red')
+                }
+            });
+
+            /* Caja Cerrada */
+            stateStatement = self.getStatementState(lineStatement, 'confirm');
+            lineMessege.css('display','none');
+            lineMessege.text("");
+            if (stateStatement.length)
+                lineMessege.css('display','flex');
+                lineMessege.text("Existe "+stateStatement.length+" caja relacionada que ya están cerrada.");
+
+            /*Click buttonSave*/
+            buttonSave.click(function(e) {
+                stateStatement = self.getStatementState(lineStatement, 'confirm');
+                if (stateStatement.length) {
+                    instanceWeb.notification.do_warn("Atencion", "No se puede eliminar la caja, porque tiene relación con cajas cerradas.");
+                    return false;
+                }
+
+
+                self.unlinkStatement(self.id).then(function(resultsUnlink) {
+                    return resultsUnlink;
+                }).then(function(resultsUnlink) {
+                    if (!resultsUnlink.state)
+                        instanceWeb.notification.do_warn("Atencion", resultsUnlink.messege);
+
+                    self.reloadPage();
+                    self.removeModal(e);
+
+                    if (!resultsCancel)
+                        results = false;
+                });
+
+                defer.resolve(results);
+            });
+
+            /* Click Cerrar */
+            $('.expired-account-modal').on('hidden.bs.modal', function(e) {
+                results = false;
+                defer.resolve(results);
+                self.removeModal(e);
+            });
+
+            return defer;
+        },
+
+        unlinkStatement: function(id){
+            var bankStatementUser = new instanceWeb.Model('account.bank.statement');
+            return bankStatementUser.call('eiru_unlink_statement',[id], {
+                context: new instanceWeb.CompoundContext()
+            });
+        }
+    });
+
+    if (openerp.web && openerp.web.FormView) {
+        openerp.web.FormView.include({
+            load_record: function(record) {
+                this._super.apply(this, arguments);
+
+                if (this.model !== 'account.bank.statement')
+                    return;
+
+                openerp.parentInstanceStatementUnlink = this;
+
+                if (openerp.widgetInstanceStatementUnlink) {
+                    openerp.widgetInstanceStatementUnlink.updateId(record.id);
+                    if (this.$el.find('.button-statement-unlink').length !== 0 )
+                        return ;
+                }
+
+                if (this.$el.find('.button-statement-unlink').length !== 0 )
+                    return;
+
+                openerp.widgetInstanceStatementUnlink = new openerp.EiruStatementUnlink(this);
+                var element =this.$el.find('.oe_form').find('.eiru-statement-unlink');
+
+                openerp.widgetInstanceStatementUnlink.appendTo(element[0]);
+                openerp.widgetInstanceStatementUnlink.updateId(record.id);
+            }
+        });
+    }
+})();

+ 1 - 1
static/src/xml/eiru_statement_cancel.xml

@@ -2,7 +2,7 @@
 <templates xml:space="preserve">
     <t t-name="EiruStatementUtility.Cancel">
         <button class="button-statement-cancel eiru-statement-button oe_button oe_form_button oe_highlight">
-            <span>Cancelar caja Eiru</span>
+            <span>Cancelar caja</span>
         </button>
   </t>
 </templates>

+ 8 - 0
static/src/xml/eiru_statement_unlink.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<templates xml:space="preserve">
+    <t t-name="EiruStatementUtility.Unlink">
+        <button class="button-statement-unlink eiru-statement-button oe_button oe_form_button oe_highlight">
+            <span>Eliminar Caja</span>
+        </button>
+  </t>
+</templates>

+ 62 - 0
static/src/xml/modal/modal_statement_unlink.xml

@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<template xml:space="preserve">
+    <t t-name="ModalStatementUtility.Unlink">
+        <div class="modal in expired-account-modal" tabindex="-1" role="dialog">
+            <div class="modal-dialog modal-lg" role="document">
+                <div class="modal-content openerp">
+                    <div class="modal-header paymnets-invoice-header">
+                        <button type="button" class="close" data-dismiss="modal" aria-label="Close" aria-hidden="true">×</button>
+                        <h3 class="modal-title">Eliminar caja</h3>
+                    </div>
+                    <!-- Body -->
+                    <div class="modal-body">
+                        <div class="row statement-line">
+                            <label class="confirm-title" style="padding-left: 30px">Movimiento</label>
+                        </div>
+                        <!-- table -->
+                        <div class=" oe_view_manager_body unlink-statement-table statement-line">
+                            <div class="modal-head-wrapper-statement-unlink">
+                                <table class="oe_list_content">
+                                    <thead >
+                                        <tr class="oe_list_header_columns"  >
+                                            <th class="oe_list_header_char oe_sortable"></th>
+                                            <th class="oe_list_header_char oe_sortable">Fecha</th>
+                                            <th class="oe_list_header_char oe_sortable">Referencia</th>
+                                            <th class="oe_list_header_char oe_sortable">Valor</th>
+                                        </tr>
+                                    </thead>
+                                </table>
+                            </div>
+                            <div class="modal-item-statement-unlink">
+                                <table class="oe_list_content">
+                                    <tbody class="table-tbody">
+                                        <tr t-foreach="statementLine" t-as="line">
+                                            <td>
+                                                <t t-esc="line_value.id"/>
+                                            </td>
+                                            <td>
+                                                <t t-esc="line_value.date"/>
+                                            </td>
+                                            <td>
+                                                <t t-esc="line_value.name"/>
+                                            </td>
+                                            <td>
+                                                <t t-esc="line_value.amount"/>
+                                            </td>
+                                        </tr>
+                                    </tbody>
+                                </table>
+                            </div>
+                        </div>
+                        <div class="line-unlink-messege"></div>
+                    </div>
+                    <!-- footer -->
+                    <div class="modal-footer statement-utility-footer">
+                        <button type="button" class="oe_button oe_form_button oe_highlight statement-utility-button button-save">Aceptar</button>
+                        <button type="button" class="oe_button oe_form_button oe_link dismmis-modal statement-utility-button" data-dismiss="modal">Salir</button>
+                    </div>
+                </div>
+            </div>
+        </div>
+    </t>
+</template>

+ 15 - 10
views/eiru_statement_utility.xml

@@ -10,25 +10,19 @@
 				<field name='state' position="before">
 					<div class="eiru-statement-utility" attrs="{'invisible': [('state','!=','open')]}"></div>
 				</field>
-
-				<!-- <field name='state' position="before">
-					<div class="eiru-statement-utility" attrs="{'invisible': [('state','!=','open')]}"></div>
-				</field> -->
-
+				<field name='state' position="before">
+					<div class="eiru-statement-unlink" attrs="{'invisible': [('state','==','confirm')]}"></div>
+				</field>
 				<!-- open -->
 				<xpath expr="//button[@name='button_open']" position="replace">
 					<div class="eiru-statement-utility-open" states="draft"> </div>
 				</xpath>
-
 				<!-- confirm -->
 				<xpath expr="//button[@name='button_confirm_cash']" position="replace"></xpath>
-
 				<!-- Cancel  -->
-				<xpath expr="//button[@name='button_cancel']" position="before">
+				<xpath expr="//button[@name='button_cancel']" position="replace">
 					<div class="eiru-statement-utility-cancel" attrs="{'invisible': [('state','!=','confirm')]}"></div>
-					<!-- <button name="button_cancel" states="open" string="Cancel CashBox" type="object"/> -->
 				</xpath>
-
 				<!-- print -->
 				<field name='state' position="before">
 					<div class="eiru-statement-print" attrs="{'invisible': [('state','!=','confirm')]}"></div>
@@ -36,6 +30,17 @@
 
             </field>
         </record>
+
+		<!-- button_draft  -->
+		<record id="eiru_statement_utility_cash_cancel" model="ir.ui.view">
+            <field name="name">eiru.statement.utility.cash.cancel</field>
+            <field name="model">account.bank.statement</field>
+            <field name="inherit_id" ref="account_cancel.bank_statement_draft_form_inherit2"/>
+            <field name="arch" type="xml">
+				<xpath expr="//button[@name='button_draft']" position="replace"></xpath>
+            </field>
+        </record>
+
 		<!-- Extractos bancarios -->
 		<record id="eiru_statement_utility_bank" model="ir.ui.view">
             <field name="name">eiru.statement.utility.bank</field>

+ 2 - 0
views/template.xml

@@ -20,6 +20,8 @@
                 <script type="text/javascript" src="/eiru_account_bank_statement_utility/static/src/js/eiru_statement_confirm_print.js"/>
                 <!-- cancel statement -->
                 <script type="text/javascript" src="/eiru_account_bank_statement_utility/static/src/js/eiru_statement_cancel.js"/>
+                <!-- Suprimir Caja  -->
+                <script type="text/javascript" src="/eiru_account_bank_statement_utility/static/src/js/eiru_statement_unlink.js"/>
                 <!-- Importar Cajas -->
                 <!-- <script type="text/javascript" src="/eiru_account_bank_statement_utility/static/src/js/import_statement.js"/> -->
             </xpath>