|
@@ -0,0 +1,122 @@
|
|
|
+(function() {
|
|
|
+ openerp.widgetInstanceStatementImport = null;
|
|
|
+ openerp.parentInstanceStatementImport = {};
|
|
|
+
|
|
|
+ var QWeb = openerp.web.qweb;
|
|
|
+ var instanceWeb = openerp.web;
|
|
|
+
|
|
|
+ openerp.EiruStatementImport = openerp.Widget.extend({
|
|
|
+ template: 'EiruImport.Statement',
|
|
|
+ id: undefined,
|
|
|
+ buttons: undefined,
|
|
|
+ bankStatement: [],
|
|
|
+ /* Init */
|
|
|
+ init: function (parent) {
|
|
|
+ this._super(parent);
|
|
|
+ this.buttons = parent.$buttons;
|
|
|
+ },
|
|
|
+ /* Actualizar id del Objeto */
|
|
|
+ updateId: function(id, type) {
|
|
|
+ var self = this;
|
|
|
+ self.id = id;
|
|
|
+ this.$el.css('display','flex');
|
|
|
+ if (type === 'normal'){
|
|
|
+ this.$el.css('display','none');
|
|
|
+ }
|
|
|
+ },
|
|
|
+ /* 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');
|
|
|
+ });
|
|
|
+ },
|
|
|
+ /* Iniciar */
|
|
|
+ fetchInitial: function() {
|
|
|
+ var self = this;
|
|
|
+ self.$el.attr("disabled", true);
|
|
|
+ self.fetchBankStatement(self.id).then(function(bankStatement) {
|
|
|
+ return bankStatement;
|
|
|
+ }).then(function(bankStatement) {
|
|
|
+ self.bankStatement = bankStatement;
|
|
|
+ if (!!self.bankStatement.length && self.bankStatement[0].type_statement === 'normal'){
|
|
|
+ instanceWeb.notification.do_notify("Atención","Esta opción solo esta disponible para la caja general.");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return self.fetchStatementPointOfSale(self.id).then(function(statementPoinOfSale){
|
|
|
+ return statementPoinOfSale;
|
|
|
+ }).then(function(statementPoinOfSale){
|
|
|
+ self.statementPoinOfSale = statementPoinOfSale;
|
|
|
+ if (!!statementPoinOfSale) {
|
|
|
+ instanceWeb.notification.do_notify("Atención"," "+statementPoinOfSale+" caja/s fueron importada .");
|
|
|
+ return
|
|
|
+ }
|
|
|
+ instanceWeb.notification.do_notify("Atención","Nada que hacer.");
|
|
|
+ });
|
|
|
+ }).then(function() {
|
|
|
+ self.$el.removeAttr("disabled");
|
|
|
+ return self.reloadPage();
|
|
|
+ });
|
|
|
+ },
|
|
|
+ /* Reload Page*/
|
|
|
+ reloadPage: function() {
|
|
|
+ openerp.parentInstanceStatementTransfer.reload();
|
|
|
+ },
|
|
|
+ /* Registro de Caja */
|
|
|
+ fetchBankStatement: function(id) {
|
|
|
+ var fields = ['id', 'journal_id', 'pos_session_id', 'date'];
|
|
|
+ var domain = [['id', '=', id]];
|
|
|
+ var statement = new instanceWeb.Model('account.bank.statement');
|
|
|
+ return statement.query(fields).filter(domain).all();
|
|
|
+ },
|
|
|
+ /* Get Statement Point of Sale*/
|
|
|
+ fetchStatementPointOfSale: function(id) {
|
|
|
+ var invoiceMoveLine = new instanceWeb.Model('account.bank.statement');
|
|
|
+ return invoiceMoveLine.call('get_statement_point_of_sale',[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.parentInstanceStatementImport = this;
|
|
|
+
|
|
|
+ if (openerp.widgetInstanceStatementImport) {
|
|
|
+ openerp.widgetInstanceStatementImport.updateId(record.id);
|
|
|
+ if (this.$el.find('.button-import-statement').length !== 0 )
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.$el.find('.button-import-statement').length !== 0 )
|
|
|
+ return;
|
|
|
+
|
|
|
+ openerp.widgetInstanceStatementImport = new openerp.EiruStatementImport(this);
|
|
|
+ var element =this.$el.find('.oe_form').find('.import-statement');
|
|
|
+
|
|
|
+ openerp.widgetInstanceStatementImport.appendTo(element[0]);
|
|
|
+ openerp.widgetInstanceStatementImport.updateId(record.id);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+})();
|