|
@@ -0,0 +1,205 @@
|
|
|
+openerp.barcode_stock_inventory = function (instance, local) {
|
|
|
+ local.widgetInstance = null;
|
|
|
+ local.parentInstance = null;
|
|
|
+
|
|
|
+ var model = openerp;
|
|
|
+ var Qweb = openerp.web.qweb;
|
|
|
+
|
|
|
+ local.StockInventoryProductSearch = instance.Widget.extend({
|
|
|
+ template : "barcode_stock_inventory.StockInventoryProductSearch",
|
|
|
+
|
|
|
+ init:function(parent){
|
|
|
+ this._super(parent);
|
|
|
+ this.buttons = parent.$buttons;
|
|
|
+ },
|
|
|
+
|
|
|
+ updateId : function(id){
|
|
|
+ var self = this;
|
|
|
+ self.id=id;
|
|
|
+ },
|
|
|
+
|
|
|
+ reloadLine: function() {
|
|
|
+ local.parentInstance.reload();
|
|
|
+ },
|
|
|
+
|
|
|
+ start: function () {
|
|
|
+ var self = this;
|
|
|
+ $("#StockInventoryProductSearch").keypress(function(e) {
|
|
|
+ var product_code = $('#StockInventoryProductSearch').val().trim();
|
|
|
+ var code = (e.keyCode ? e.keyCode : e.which);
|
|
|
+ if(code==13 && product_code.length >= 9){
|
|
|
+ self.Initial();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ showMensaje: function(mensaje){
|
|
|
+ var self = this;
|
|
|
+ $("#dialog" ).dialog({
|
|
|
+ autoOpen: true,
|
|
|
+ resizable: false,
|
|
|
+ modal: true,
|
|
|
+ title: 'Atención',
|
|
|
+ width: 500,
|
|
|
+ open: function() {
|
|
|
+ $(this).html(mensaje);
|
|
|
+ },
|
|
|
+ show: {
|
|
|
+ effect: "fade",
|
|
|
+ duration: 200
|
|
|
+ },
|
|
|
+ hide: {
|
|
|
+ effect: "fade",
|
|
|
+ duration: 200
|
|
|
+ },
|
|
|
+ buttons: {
|
|
|
+ Aceptar: function() {
|
|
|
+ $(this).dialog('close');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ },
|
|
|
+
|
|
|
+ Initial: function(){
|
|
|
+ var self = this;
|
|
|
+ var id = openerp.webclient._current_state.id;
|
|
|
+ var product_code = $('#StockInventoryProductSearch').val().trim();
|
|
|
+ self.fetchProductProduct(product_code).then(function(ProductProduct){
|
|
|
+ return ProductProduct;
|
|
|
+ }).then(function(ProductProduct){
|
|
|
+ self.ProductProduct = ProductProduct;
|
|
|
+ if(id != undefined){
|
|
|
+ if(ProductProduct.length == 1){
|
|
|
+ self.InsertProduct(ProductProduct[0].id);
|
|
|
+ }else{
|
|
|
+ if(ProductProduct.length == 0){
|
|
|
+ self.showMensaje('Producto no encontrado (codigo: ' + product_code + ').');
|
|
|
+ }else{
|
|
|
+ self.showModal(product_code);
|
|
|
+ }
|
|
|
+ self.$el.find('#productSearch').val('');
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ self.showMensaje('Es necesario guardar la orden antes de continuar.');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchProductProduct: function (product_code) {
|
|
|
+ var domain = [
|
|
|
+ ['active','=',true],
|
|
|
+ ['sale_ok','=',true],
|
|
|
+ '|',['ean13','like',product_code],['default_code','like',product_code],
|
|
|
+ ];
|
|
|
+ var ProductProduct = new model.web.Model('product.product');
|
|
|
+ return ProductProduct.call('getProductProductSearch',[domain], {
|
|
|
+ context: new model.web.CompoundContext()
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ InsertProduct:function(id){
|
|
|
+ var self = this;
|
|
|
+ var qty = 1;
|
|
|
+ self.Insert(parseInt(id), qty).then(function(results) {
|
|
|
+ return results;
|
|
|
+ }).then(function(){
|
|
|
+ self.reloadLine();
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ Insert: function(product_id, qty) {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var id = openerp.webclient._current_state.id;
|
|
|
+ var sale = new openerp.web.Model('stock.inventory');
|
|
|
+ sale.call('insert_stock_inventory_line',[
|
|
|
+ {
|
|
|
+ id: parseInt(id),
|
|
|
+ product_id: product_id,
|
|
|
+ }
|
|
|
+ ], {
|
|
|
+ context: new openerp.web.CompoundContext()
|
|
|
+ }).then(function(results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ self.$el.find('#StockInventoryProductSearch').val('');
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ ========================================================================
|
|
|
+ MODAL
|
|
|
+ ========================================================================
|
|
|
+ */
|
|
|
+ showModal: function (product_code) {
|
|
|
+ var self = this;
|
|
|
+ var titleData = [
|
|
|
+ {
|
|
|
+ title: "Productos encontrados con el codigo (" + product_code + ')'
|
|
|
+ }
|
|
|
+ ];
|
|
|
+ var headerModal = [
|
|
|
+ {
|
|
|
+ title: "Producto"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: "Referencia"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: "ean13"
|
|
|
+ }
|
|
|
+ ];
|
|
|
+
|
|
|
+ var modal = Qweb.render('SaleProductModal', {
|
|
|
+ data: self.ProductProduct,
|
|
|
+ dataThead: headerModal,
|
|
|
+ modalTitle: titleData
|
|
|
+ });
|
|
|
+
|
|
|
+ $('.openerp_webclient_container').after(modal);
|
|
|
+ $('.product-search-modal').modal();
|
|
|
+ $('.product-search-modal').on('hidden.bs.modal', function (e) {
|
|
|
+ self.removeModal(e);
|
|
|
+ });
|
|
|
+
|
|
|
+ var contenido = $('.product-search-modal').find('.table-tbody');
|
|
|
+ contenido.click(function (e) {
|
|
|
+ $(contenido).find('tr').removeClass('table-row-select');
|
|
|
+ $(e.target).closest('tr').addClass('table-row-select');
|
|
|
+ var children_id = $(e.target).closest('tr').children()[0].textContent;
|
|
|
+ self.InsertProduct(children_id);
|
|
|
+ self.removeModal();
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ removeModal: function (e) {
|
|
|
+ $('.product-search-modal').remove();
|
|
|
+ $('.modal-backdrop').remove();
|
|
|
+ },
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ ========================================================================
|
|
|
+ INSERTAR ELEMENTO
|
|
|
+ ========================================================================
|
|
|
+ */
|
|
|
+ if (instance.web && instance.web.FormView) {
|
|
|
+ instance.web.FormView.include({
|
|
|
+ load_form: function (record) {
|
|
|
+ this._super.apply(this, arguments);
|
|
|
+ if (this.model !== 'stock.inventory') return;
|
|
|
+ local.parentInstance = this;
|
|
|
+ if (local.widgetInstance) {
|
|
|
+ local.widgetInstance.updateId(record.id);
|
|
|
+ }
|
|
|
+ local.widgetInstance = new local.StockInventoryProductSearch(this);
|
|
|
+ var elemento = this.$el.find('.oe_form_sheet.oe_form_sheet_width');
|
|
|
+ elemento = elemento.find('.stock_inventory_product_search_box');
|
|
|
+ local.widgetInstance.appendTo(elemento);
|
|
|
+ local.widgetInstance.updateId(record.id);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+};
|