Browse Source

[ADD] Método para abrir caja + configuración

adrielso 6 years ago
parent
commit
dafca61231

+ 2 - 1
models/account_bank_statement_config.py

@@ -26,4 +26,5 @@ class accountBankStatementConfig(models.Model):
     output_cash_box_statement_ids = fields.Many2many('account.bank.statement.type', 'statement_config_output_statement', 'account_bank_statement_config_id', 'account_bank_statement_type_id', string="statement_config_output_statement")
     output_negative_amount = fields.Boolean('output_negative_amount', default=False, help="Permitir sacar dinero sin saldo en caja")
     delete_output_user_ids = fields.Many2many('res.users', 'statement_config_deleted_output_user', 'account_bank_statement_config_id','res_users_id', string='statement_delete_output_user')
-    ## Importar Cajas
+    ## Abrir Cajas
+    statement_open_config = fields.Boolean('statement_open_config', default=False, help="Permitir abrir mas de una caja(por usuario, por diario, por tipo de caja)")

+ 37 - 0
models/account_bank_statement_utility.py

@@ -591,3 +591,40 @@ class AccountBankStatementUtility(models.Model):
         return { 'state': True,
                 'message': 'Operación realizada con éxito'
         }
+
+    '''
+          ____  _        _                            _      ___
+         / ___|| |_ __ _| |_ ___ _ __ ___   ___ _ __ | |_   / _ \ _ __   ___ _ __
+         \___ \| __/ _` | __/ _ \ '_ ` _ \ / _ \ '_ \| __| | | | | '_ \ / _ \ '_ \
+          ___) | || (_| | ||  __/ | | | | |  __/ | | | |_  | |_| | |_) |  __/ | | |
+         |____/ \__\__,_|\__\___|_| |_| |_|\___|_| |_|\__|  \___/| .__/ \___|_| |_|
+                                                                 |_|
+    '''
+    '''
+        Get Statement Open
+    '''
+    @api.model
+    def account_bank_statement_open(self,id):
+        statement = self._get_statement_transfer(id)
+        if (not statement):
+            return False
+
+        return [{
+            'id': open.id,
+            'name': open.name
+        } for open in self.env['account.bank.statement'].search([('journal_id.id', '=',statement.journal_id.id),('type_statement.id', '=', statement.type_statement.id),('user_id.id', '=', statement.user_id.id),('state', '=', 'open')])]
+
+    '''
+        Open CashBox
+    '''
+    @api.model
+    def account_bank_statement_open_cashbox(self, id):
+        statement = self._get_statement_transfer(id)
+        return statement.button_open()
+
+    '''
+        method Open CashBox
+    '''
+    @api.multi
+    def button_open(self):
+        return super(AccountBankStatementUtility, self).button_open()

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

@@ -7,6 +7,10 @@
     width: auto;
     float: left;
 }
+.eiru-statement-utility-open {
+    width: auto;
+    float: left;
+}
 .eiru-statement-utility {
     width: auto;
     float: left;

+ 120 - 0
static/src/js/eiru_statement_open.js

@@ -0,0 +1,120 @@
+(function() {
+    openerp.widgetInstanceStatementOpen = null;
+    openerp.parentInstanceStatementOpen = {};
+    var QWeb = openerp.web.qweb;
+    var instanceWeb = openerp.web;
+    // Abrir caja
+    openerp.EiruStatementOpen = openerp.Widget.extend({
+        template: 'EiruStatementUtility.Open',
+        id: undefined,
+        buttons: undefined,
+        bankStatement: [],
+        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.parentInstanceStatementOpen.reload();
+        },
+        /* Método inicial */
+        fetchInitial: function() {
+            var self = this;
+            self.fetchBankStatement(self.id).then(function(bankStatement) {
+                return bankStatement;
+            }).then(function(bankStatement) {
+                self.bankStatement = bankStatement;
+                return self.fetchStatementConfig();
+            }).then(function(statementConfig) {
+                self.statementConfig = statementConfig;
+
+                if (!!self.statementConfig.length && !!self.bankStatement.length) {
+                    if(!self.statementConfig[0].statement_open_config) {
+                        instanceWeb.notification.do_warn("Atencion", "Ya existe caja abierta.");
+                        return  false;
+                    }
+                }
+                return self.statementOpenCashbox(self.id);
+            }).then(function() {
+                self.reloadPage();
+            });
+        },
+        /* Account bank Statement  Open*/
+        fetchBankStatement: function(id) {
+            var bankStatement = new instanceWeb.Model('account.bank.statement');
+            return bankStatement.call('account_bank_statement_open',[id], {
+                context: new instanceWeb.CompoundContext()
+            });
+        },
+        /* statement Config */
+        fetchStatementConfig: function() {
+            var fields = ['id','name','statement_open_config'];
+            var domain = [['active', '=', true]];
+            var statementConfig = new openerp.web.Model('account.bank.statement.config');
+            return statementConfig.query(fields).filter(domain).all();
+        },
+        /* Open cashBox */
+        statementOpenCashbox: function(id) {
+            var bankStatement = new instanceWeb.Model('account.bank.statement');
+            return bankStatement.call('account_bank_statement_open_cashbox',[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.parentInstanceStatementOpen = this;
+
+                if (openerp.widgetInstanceStatementOpen) {
+                    openerp.widgetInstanceStatementOpen.updateId(record.id);
+                    if (this.$el.find('.button-statement-open').length !== 0 )
+                        return ;
+                }
+
+                if (this.$el.find('.button-statement-open').length !== 0 )
+                    return;
+
+                openerp.widgetInstanceStatementOpen = new openerp.EiruStatementOpen(this);
+                var element =this.$el.find('.oe_form').find('.eiru-statement-utility-open');
+
+                openerp.widgetInstanceStatementOpen.appendTo(element[0]);
+                openerp.widgetInstanceStatementOpen.updateId(record.id);
+            }
+        });
+    }
+})();

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

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

+ 15 - 0
views/account_bank_statemente_config.xml

@@ -122,6 +122,21 @@
                                 </group>
                             </group>
                         </page>
+
+                        <!-- open -confirm statement -->
+                        <page string="Abrir &amp; cerrar caja">
+                            <separator string="forma de abrir y cerrar caja "/>
+
+                            <div class="openerp oe_form oe_form_field">
+                                <span class="oe_form_text_content"></span>
+                            </div>
+
+                            <group style="margin: 0px">
+                                <label for="statement_open_config" string="Permitir abrir mas de una caja" style="width: 200px"></label>
+                                <field name="statement_open_config"  style="width: 200px" nolabel="1" />
+                            </group>
+                        </page>
+
                     </notebook>
                 </form>
             </field>

+ 3 - 0
views/eiru_statement_utility.xml

@@ -10,6 +10,9 @@
 				<field name='state' position="before">
 					<div class="eiru-statement-utility" attrs="{'invisible': [('state','!=','open')]}"></div>
 				</field>
+				<xpath expr="//button[@name='button_open']" position="replace">
+					<div class="eiru-statement-utility-open" states="draft"> </div>
+				</xpath>
             </field>
         </record>
 		<!-- Extractos bancarios -->

+ 6 - 1
views/template.xml

@@ -10,8 +10,13 @@
                 <script type="text/javascript" src="/eiru_account_bank_statement_utility/static/src/js/eiru_statement_cashbox_input.js"/>
                 <!-- Sacar dinero  -->
                 <script type="text/javascript" src="/eiru_account_bank_statement_utility/static/src/js/eiru_statement_cashbox_output.js"/>
+                <!-- unlink -->
                 <script type="text/javascript" src="/eiru_account_bank_statement_utility/static/src/js/eiru_statement_cashbox_deleted.js"/>
-
+                <!-- Abrir caja -->
+                <script type="text/javascript" src="/eiru_account_bank_statement_utility/static/src/js/eiru_statement_open.js"/>
+                <!-- Cerrar caja  -->
+                <!-- <script type="text/javascript" src="/eiru_account_bank_statement_utility/static/src/js/"/> -->
+                <!-- Importar Cajas -->
                 <!-- <script type="text/javascript" src="/eiru_account_bank_statement_utility/static/src/js/import_statement.js"/> -->
             </xpath>
         </template>