|
@@ -2,13 +2,12 @@ openerp.barcode_sale_order = function (instance, local) {
|
|
|
local.widgetInstance = null;
|
|
|
local.parentInstance = null;
|
|
|
|
|
|
+ var model = openerp;
|
|
|
+ var Qweb = openerp.web.qweb;
|
|
|
+
|
|
|
local.SaleOrderSearchWidget = instance.Widget.extend({
|
|
|
template : "barcode_sale_order.SaleOrderSearch",
|
|
|
|
|
|
- // events:{
|
|
|
- // 'click .activate_barcode' : 'showSearch',
|
|
|
- // },
|
|
|
-
|
|
|
init:function(parent){
|
|
|
this._super(parent);
|
|
|
this.buttons = parent.$buttons;
|
|
@@ -25,9 +24,14 @@ openerp.barcode_sale_order = function (instance, local) {
|
|
|
|
|
|
start: function () {
|
|
|
var self = this;
|
|
|
- this.$el.click(function () {
|
|
|
- self.fecthInitial();
|
|
|
+ $("#productSearch").keypress(function(e) {
|
|
|
+ var product_code = $('#productSearch').val().trim();
|
|
|
+ var code = (e.keyCode ? e.keyCode : e.which);
|
|
|
+ if(code==13 && product_code.length >= 9){
|
|
|
+ self.Initial();
|
|
|
+ };
|
|
|
});
|
|
|
+
|
|
|
},
|
|
|
|
|
|
showMensaje: function(mensaje){
|
|
@@ -58,104 +62,57 @@ openerp.barcode_sale_order = function (instance, local) {
|
|
|
return
|
|
|
},
|
|
|
|
|
|
- fecthInitial: function(){
|
|
|
- var id = openerp.webclient._current_state.id;
|
|
|
+ Initial: function(){
|
|
|
var self = this;
|
|
|
- self.fecthSale(id).then(function(sale){
|
|
|
- return sale;
|
|
|
- }).then(function(sale){
|
|
|
- self.sale = sale;
|
|
|
- return self.fetchProductProduct();
|
|
|
+ var id = openerp.webclient._current_state.id;
|
|
|
+ var product_code = $('#productSearch').val().trim();
|
|
|
+ self.fetchProductProduct(product_code).then(function(ProductProduct){
|
|
|
+ return ProductProduct;
|
|
|
}).then(function(ProductProduct){
|
|
|
self.ProductProduct = ProductProduct;
|
|
|
- self.inicializarBuscador();
|
|
|
- });
|
|
|
- return false;
|
|
|
- },
|
|
|
-
|
|
|
- fecthSale: function(id){
|
|
|
- var defer = $.Deferred();
|
|
|
- var fields=['id','name','partner_id','state'];
|
|
|
- var domain=[['id','=', id]];
|
|
|
- var Sale = new instance.web.Model('sale.order');
|
|
|
- Sale.query(fields).filter(domain).order_by('id').all().then(function(results){
|
|
|
- defer.resolve(results);
|
|
|
- });
|
|
|
- return defer;
|
|
|
- },
|
|
|
-
|
|
|
- fetchProductProduct: function () {
|
|
|
- var defer = $.Deferred();
|
|
|
- var fields=['id','name','attribute_str','default_code','ean13'];
|
|
|
- var domain=[['active','=', true],['sale_ok','=', true]];
|
|
|
- var ProductProduct = new instance.web.Model('product.product');
|
|
|
- ProductProduct.query(fields).filter(domain).order_by('id').all().then(function(results){
|
|
|
- defer.resolve(results);
|
|
|
- });
|
|
|
- return defer;
|
|
|
- },
|
|
|
-
|
|
|
- getProductProduct : function(id){
|
|
|
- var self = this;
|
|
|
- return _.filter(self.ProductProduct, function(item){
|
|
|
- return item.id == id;
|
|
|
+ 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('');
|
|
|
+ };
|
|
|
});
|
|
|
},
|
|
|
|
|
|
- inicializarBuscador: function () {
|
|
|
- var self = this;
|
|
|
- var selectProduct;
|
|
|
- $("#productSearch").keypress(function(e) {
|
|
|
- id = openerp.webclient._current_state.id;
|
|
|
- if(id == undefined){
|
|
|
- self.showMensaje('Debe guardar el documento antes de continuar.');
|
|
|
- self.$el.find('#productSearch').val('');
|
|
|
- }
|
|
|
- var product = [];
|
|
|
- var ean13 = $('#productSearch').val().trim();
|
|
|
- var code = (e.keyCode ? e.keyCode : e.which);
|
|
|
- if(code==13 && ean13.length >= 9){
|
|
|
- product = _.filter(self.ProductProduct,function (item) {
|
|
|
- return item.ean13 == ean13;
|
|
|
- })
|
|
|
- if(product.length > 0){
|
|
|
- self.factInsertProduct(product);
|
|
|
- }else{
|
|
|
- product = _.filter(self.ProductProduct,function (item) {
|
|
|
- var dato = item.ean13;
|
|
|
- if(dato){
|
|
|
- dato = dato.substring(0,9);
|
|
|
- }
|
|
|
- return dato == ean13;
|
|
|
- })
|
|
|
- if(product.length > 0){
|
|
|
- self.factInsertProduct(product);
|
|
|
- }else{
|
|
|
- self.showMensaje('Producto no encontrado.');
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ 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('getProductProduct',[domain], {
|
|
|
+ context: new model.web.CompoundContext()
|
|
|
});
|
|
|
},
|
|
|
|
|
|
- factInsertProduct:function(product){
|
|
|
+ InsertProduct:function(id){
|
|
|
var self = this;
|
|
|
- var prod = product[0].id;
|
|
|
var qty = 1;
|
|
|
- self.fetchInsert(prod, qty).then(function(results) {
|
|
|
+ self.Insert(parseInt(id), qty).then(function(results) {
|
|
|
return results;
|
|
|
}).then(function(){
|
|
|
self.reloadLine();
|
|
|
});
|
|
|
},
|
|
|
|
|
|
- fetchInsert: function(product_id, qty) {
|
|
|
+ Insert: function(product_id, qty) {
|
|
|
var self = this;
|
|
|
var defer = $.Deferred();
|
|
|
+ var id = openerp.webclient._current_state.id;
|
|
|
var sale = new openerp.web.Model('sale.order');
|
|
|
sale.call('sale_insert_lines_by_eiru_original',[
|
|
|
{
|
|
|
- id: self.sale[0].id,
|
|
|
+ id: parseInt(id),
|
|
|
product_id: product_id,
|
|
|
}
|
|
|
], {
|
|
@@ -166,8 +123,64 @@ openerp.barcode_sale_order = function (instance, local) {
|
|
|
self.$el.find('#productSearch').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) {
|