|
@@ -0,0 +1,345 @@
|
|
|
+(function() {
|
|
|
+ // EiruStockPicking
|
|
|
+ openerp.widgetInstanceEiruStockPicking = null;
|
|
|
+ openerp.parentInstanceEiruStockPicking = {};
|
|
|
+ var QWeb = openerp.web.qweb;
|
|
|
+ var instanceWeb = openerp.web;
|
|
|
+
|
|
|
+ openerp.EiruStockPicking = openerp.Widget.extend({
|
|
|
+ template: 'EiruStockPicking.Returned',
|
|
|
+ id: undefined,
|
|
|
+ model: undefined,
|
|
|
+ buttons: undefined,
|
|
|
+ stockPicking: [],
|
|
|
+
|
|
|
+ /* init */
|
|
|
+ init: function(parent) {
|
|
|
+ this._super(parent);
|
|
|
+ this.buttons = parent.$buttons;
|
|
|
+ },
|
|
|
+
|
|
|
+ /* start */
|
|
|
+ start: function () {
|
|
|
+ var self = this;
|
|
|
+ this.$el.click(function(){
|
|
|
+ self.fetchInitial();
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /* Check state*/
|
|
|
+ updateId: function(id, model) {
|
|
|
+ var self = this;
|
|
|
+ self.id = id;
|
|
|
+ self.model = model;
|
|
|
+ self.$el.css('display','flex');
|
|
|
+ if (!self.id)
|
|
|
+ self.$el.css('display','none');
|
|
|
+ },
|
|
|
+
|
|
|
+ /* Reload Page*/
|
|
|
+ reloadPage: function() {
|
|
|
+ openerp.parentInstanceEiruStockPicking.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.fetchStockPickingOrder(self.id, self.model).then(function(stockPicking) {
|
|
|
+ return stockPicking;
|
|
|
+ }).then(function(stockPicking) {
|
|
|
+ if (!stockPicking.state) {
|
|
|
+ instanceWeb.notification.do_warn("Atencion", stockPicking.message);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ self.stockPicking = stockPicking.pickingOrder;
|
|
|
+ return self.showModalReturned();
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /* Get account.interest */
|
|
|
+ fetchStockPickingOrder: function(id, model) {
|
|
|
+ var pickingOrder = new instanceWeb.Model('stock.return.picking');
|
|
|
+ return pickingOrder.call('eiru_get_stock_picking_order', [id, model], {
|
|
|
+ context: new instanceWeb.CompoundContext()
|
|
|
+ });
|
|
|
+ },
|
|
|
+ /* Format Quantity */
|
|
|
+ pickingFormatline: function(line, format){
|
|
|
+ var self = this;
|
|
|
+ _.each(line, function(item) {
|
|
|
+ item.qty_order_format = self.formatQty(item.qty_order, format)
|
|
|
+ item.qty_return_format = self.formatQty(item.qty_return, format)
|
|
|
+ item.qty_format = self.formatQty(item.qty, format)
|
|
|
+ })
|
|
|
+ return line;
|
|
|
+ },
|
|
|
+ /* Modal */
|
|
|
+ showModalReturned: function() {
|
|
|
+ var self = this;
|
|
|
+ var results = true;
|
|
|
+ var defer =$.Deferred();
|
|
|
+ var stockPicking = self.stockPicking[0];
|
|
|
+ var order = stockPicking.order[0];
|
|
|
+ var picking = stockPicking.picking[0];
|
|
|
+ var productoFormat = picking.productFormat;
|
|
|
+ var lines = self.pickingFormatline(picking.lines,productoFormat);
|
|
|
+ var productSelect = [];
|
|
|
+ /*Modal Init */
|
|
|
+ var modal = QWeb.render('EiruStockPicking.ModalReturned',{
|
|
|
+ 'line': lines
|
|
|
+ });
|
|
|
+ $('.openerp_webclient_container').after(modal);
|
|
|
+ $('.expired-account-modal').modal();
|
|
|
+
|
|
|
+ /* Variable */
|
|
|
+ var selectPickingAll = $('.expired-account-modal').find('.select-stock-picking-all');
|
|
|
+ var tableRow = $('.expired-account-modal').find('.table-tbody').find('tr');
|
|
|
+ var lableOrde = $('.expired-account-modal').find('.sale-lable-table');
|
|
|
+ /* Facturar */
|
|
|
+ var stockInvoiced = $('.expired-account-modal').find('.stock-return-invoiced')
|
|
|
+ /* button Crear Factura */
|
|
|
+ var buttonAccept = $('.expired-account-modal').find('.button-accept');
|
|
|
+
|
|
|
+ lableOrde.text(self.model === 'sale.order' ? 'Entregado' : 'Recibido')
|
|
|
+
|
|
|
+ /* Verify Qty */
|
|
|
+ _.each(tableRow, function(tr) {
|
|
|
+ if (self.unformatQty($($(tr).children()[6]).find('.picking-sale').val()) === 0) {
|
|
|
+ ($($(tr).children()[2]).find('.select-stock-picking-retuned'))[0].checked = false;
|
|
|
+ ($($(tr).children()[2]).find('.select-stock-picking-retuned')).attr("disabled", true);
|
|
|
+ $(tr).css('color','red');
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ /* click Select all */
|
|
|
+ selectPickingAll.click(function(e) {
|
|
|
+ var check = e.target.checked;
|
|
|
+ productSelect = [];
|
|
|
+
|
|
|
+ _.each(tableRow, function(tr) {
|
|
|
+ if (parseInt($($(tr).children()[6]).find('.picking-sale').val()) === 0)
|
|
|
+ return false;
|
|
|
+
|
|
|
+ ($($(tr).children()[2]).find('.select-stock-picking-retuned'))[0].checked = check;
|
|
|
+ $(tr).removeClass('selected-product');
|
|
|
+
|
|
|
+ var productQty = ($($(tr).children()[7]).find('.picking-return'));
|
|
|
+ productQty.removeClass('picking-qty');
|
|
|
+ productQty.attr("disabled", true);
|
|
|
+
|
|
|
+ if (check) {
|
|
|
+ moveId = parseInt(($(tr).children()[0].textContent).trim());
|
|
|
+ productId = parseInt(($(tr).children()[1].textContent).trim());
|
|
|
+
|
|
|
+ productQty.addClass('picking-qty')
|
|
|
+ productQty.removeAttr("disabled");
|
|
|
+ $(tr).addClass('selected-product');
|
|
|
+
|
|
|
+ productSelect.push({
|
|
|
+ 'productId': productId,
|
|
|
+ 'moveID': moveId,
|
|
|
+ 'qty': self.unformatQty(productQty.val())
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ /* Select Prodcut */
|
|
|
+ tableRow.click(function(e) {
|
|
|
+ if (($(e.target).index() !== 0) ||(($(e.target).index() === 0) && ($(e.target)[0].className !== 'select-stock-picking-retuned')))
|
|
|
+ return false;
|
|
|
+
|
|
|
+ /* Desmarcar todo*/
|
|
|
+ selectPickingAll[0].checked = false;
|
|
|
+ idRow = parseInt(($(e.target).closest('tr').children()[0].textContent).trim());
|
|
|
+ var productId = parseInt(($(e.target).closest('tr').children()[1].textContent).trim());
|
|
|
+ var productQty = ($($(e.target).closest('tr').children()[7]).find('.picking-return'));
|
|
|
+ var pickingSale = $($(e.target).closest('tr').children()[6]).find('.picking-sale');
|
|
|
+
|
|
|
+ if (e.target.checked === true) {
|
|
|
+ $(e.target).closest('tr').addClass('selected-product');
|
|
|
+ productQty.addClass('picking-qty')
|
|
|
+ productQty.removeAttr("disabled");
|
|
|
+ productSelect.push({
|
|
|
+ 'productId': productId,
|
|
|
+ 'moveID': idRow,
|
|
|
+ 'qty': self.unformatQty(productQty.val())
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ $(e.target).closest('tr').removeClass('selected-product');
|
|
|
+ productQty.removeClass('picking-qty')
|
|
|
+ productQty.attr("disabled", true);
|
|
|
+ var indexSplice = undefined;
|
|
|
+
|
|
|
+ _.each(productSelect, function(item, index){
|
|
|
+ if (item.moveID === idRow) {
|
|
|
+ indexSplice = index
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ if (indexSplice !== undefined)
|
|
|
+ productSelect.splice(indexSplice,1);
|
|
|
+
|
|
|
+ productQty.val(parseInt(pickingSale.val()))
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ tableRow.keyup(function(e) {
|
|
|
+ if (($(e.target).index() !== 0) ||(($(e.target).index() === 0) && (!_.contains(($(e.target)[0].className).split(' '), 'picking-return')) ))
|
|
|
+ return false;
|
|
|
+
|
|
|
+ var productQty = ($($(e.target).closest('tr').children()[7]).find('.picking-return'));
|
|
|
+ if (e.key === productoFormat.decimalSeparator && productoFormat.decimalPlaces > 0)
|
|
|
+ return false ;
|
|
|
+
|
|
|
+ value = self.unformatQty(productQty.val());
|
|
|
+ productQty.val(self.formatQty(value, productoFormat, true));
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ /*Validate focus */
|
|
|
+ tableRow.focusout(function(e) {
|
|
|
+ if (($(e.target).index() !== 0) ||(($(e.target).index() === 0) && ($(e.target)[0].className === 'picking-return')))
|
|
|
+ return false;
|
|
|
+
|
|
|
+ var moveId = parseInt(($(e.target).closest('tr').children()[0].textContent).trim());
|
|
|
+ var pickingSale = $($(e.target).closest('tr').children()[6]).find('.picking-sale');
|
|
|
+ var pickingReturn = $($(e.target).closest('tr').children()[7]).find('.picking-return');
|
|
|
+
|
|
|
+ var qtySale = self.unformatQty(pickingSale.val());
|
|
|
+ var qtyReturn = self.unformatQty(pickingReturn.val())
|
|
|
+
|
|
|
+ if (qtyReturn > qtySale ) {
|
|
|
+ instanceWeb.notification.do_warn("Atencion", "La cantidad del movimiento supera la cantidad disponible.");
|
|
|
+ buttonAccept.attr("disabled", true);
|
|
|
+ pickingReturn.focus();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (qtyReturn <= 0) {
|
|
|
+ instanceWeb.notification.do_warn("Atencion", "La cantidad del movimiento debe ser mayor que 0");
|
|
|
+ buttonAccept.attr("disabled", true);
|
|
|
+ pickingReturn.focus();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ value = self.unformatQty(pickingReturn.val());
|
|
|
+ pickingReturn.val(self.formatQty(value,productoFormat, false));
|
|
|
+
|
|
|
+ _.each(productSelect, function(item, index) {
|
|
|
+ if (item.moveID === moveId) {
|
|
|
+ item.qty = qtyReturn
|
|
|
+ }
|
|
|
+ })
|
|
|
+ buttonAccept.removeAttr("disabled");
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ /* Accept*/
|
|
|
+ buttonAccept.click(function(e) {
|
|
|
+ if (!productSelect.length) {
|
|
|
+ instanceWeb.notification.do_warn("Atencion", "Debes seleccionar al menos un producto para generar la transferencia.");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (!!_.contains(_.map(productSelect,function(item){return item.qty}), 0)) {
|
|
|
+ instanceWeb.notification.do_warn("Atencion", "Existe producto seleccionado con cantidad 0");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ var newPicking = {
|
|
|
+ 'orderID': order.id,
|
|
|
+ 'model': self.model,
|
|
|
+ 'pickingId': picking.id,
|
|
|
+ 'invoiced': stockInvoiced[0].checked,
|
|
|
+ 'move': productSelect
|
|
|
+ }
|
|
|
+
|
|
|
+ $('.expired-account-modal').find('.widget-content.widget-loading-picking-invoice').css('display','flex');
|
|
|
+ self.createReturnPicking(newPicking).then(function(resultsInvoice) {
|
|
|
+ return resultsInvoice;
|
|
|
+ }).then(function(resultsInvoice) {
|
|
|
+ $('.expired-account-modal').find('.widget-content.widget-loading-picking-invoice').css('display','none');
|
|
|
+ instanceWeb.notification.do_warn("Atencion", resultsInvoice.message);
|
|
|
+ self.reloadPage();
|
|
|
+ self.removeModal(e);
|
|
|
+ });
|
|
|
+
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+
|
|
|
+ /* Cerrar */
|
|
|
+ $('.expired-account-modal').on('hidden.bs.modal', function(e) {
|
|
|
+ results = false;
|
|
|
+ defer.resolve(results);
|
|
|
+ self.removeModal(e);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+ /* Unformat Quantity */
|
|
|
+ unformatQty: function(value){
|
|
|
+ value = value.replace(/[\.|,](\d{0,3}$)/, '?$1').split(/\?/);
|
|
|
+ value[0] = value[0].replace(/[^0-9]/g, '');
|
|
|
+ value = Number.parseFloat(value.join('.')) || 0;
|
|
|
+ return value;
|
|
|
+ },
|
|
|
+ /* Format Quantity */
|
|
|
+ formatQty: function(value, productoFormat, edit) {
|
|
|
+ value = value.toString();
|
|
|
+ value = value.split('.');
|
|
|
+
|
|
|
+ value[0] = value[0].replace(/(\d)(?=(\d\d\d)+(?!\d))/g, `$1${productoFormat.thousandsSeparator}`);
|
|
|
+ if (!!value[1]) {
|
|
|
+ var decimalPlaces = value[1].length < productoFormat.decimalPlaces && edit ?value[1].length :productoFormat.decimalPlaces;
|
|
|
+ value[1] = Number.parseFloat(`1.${value[1]}e${decimalPlaces}`);
|
|
|
+ value[1] = Math.round(value[1]).toString().replace(/^1/, '');
|
|
|
+ }
|
|
|
+
|
|
|
+ value = productoFormat.decimalPlaces === 0 ?value[0] :value.join(productoFormat.decimalSeparator);
|
|
|
+ return value;
|
|
|
+ },
|
|
|
+ /*createI Invoice */
|
|
|
+ createReturnPicking: function(newPicking){
|
|
|
+ var self = this;
|
|
|
+ var stockReturn = new instanceWeb.Model('stock.return.picking');
|
|
|
+ return stockReturn.call('eiru_create_stock_return_picking',[newPicking],{
|
|
|
+ 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 !== 'sale.order' && this.model !== 'purchase.order')
|
|
|
+ return;
|
|
|
+
|
|
|
+ openerp.parentInstanceEiruStockPicking = this;
|
|
|
+
|
|
|
+ if (openerp.widgetInstanceEiruStockPicking) {
|
|
|
+ openerp.widgetInstanceEiruStockPicking.updateId(record.id, this.model);
|
|
|
+ if (this.$el.find('.button-stock-picking-returned').length !== 0)
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.$el.find('.button-stock-picking-returned').length !== 0)
|
|
|
+ return;
|
|
|
+
|
|
|
+ openerp.widgetInstanceEiruStockPicking = new openerp.EiruStockPicking(this);
|
|
|
+ var element =this.$el.find('.oe_form').find('.eiru-stock-picking-return');
|
|
|
+
|
|
|
+ openerp.widgetInstanceEiruStockPicking.appendTo(element[0]);
|
|
|
+ openerp.widgetInstanceEiruStockPicking.updateId(record.id, this.model);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+})();
|