Browse Source

[ADD] Agregado buscar por referencia interna y por EAN13

Rodney Enciso Arias 7 năm trước cách đây
mục cha
commit
7c5a05e7ea
3 tập tin đã thay đổi với 39 bổ sung16 xóa
  1. 6 1
      __openerp__.py
  2. 32 14
      static/src/js/sale_order_curve.js
  3. 1 1
      static/src/xml/sale_order_curve.xml

+ 6 - 1
__openerp__.py

@@ -6,7 +6,12 @@
     """,
     'author' : 'Eiru',
     'category' : 'sale',
-    'depends' : ['sale'],
+    'depends' : [
+        'sale',
+        'product_variant_search_by_attribute',
+        'product_curve',
+        'website_sale_add_curve'
+    ],
     'data' : [
         'views/template.xml',
         'views/sale_order_search_box.xml',

+ 32 - 14
static/src/js/sale_order_curve.js

@@ -67,7 +67,7 @@ openerp.eiru_sale_order = function (instance, local) {
 
         fetchProductProduct: function () {
             var defer = $.Deferred();
-            var fields=['id','name','product_tmpl_id','attribute_str'];
+            var fields=['id','name','product_tmpl_id','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){
@@ -76,6 +76,14 @@ openerp.eiru_sale_order = function (instance, local) {
             return defer;
         },
 
+        valorNull:function(dato){
+            var valor ="";
+            if (dato){
+                valor=dato;
+            }
+            return valor;
+        },
+
         getTemplate : function(id){
             var self = this;
             return _.filter(self.ProductTemplate, function(item){
@@ -111,15 +119,15 @@ openerp.eiru_sale_order = function (instance, local) {
                 });
                 self.$('#productSearch').autocomplete({
                     source: results,
-                    minLength:3,
-                    // response: function (e, ui){
-                    //     if (ui.content instanceof Array && ui.content.length === 1) {
-                    //         selectProduct = ui.content[0];    
-                    //         $(this).autocomplete("close");
-                    //         $(this).val('');
-                    //         self.factInsert(selectProduct);
-                    //     }                
-                    // },
+                    minLength:4,
+                    response: function (e, ui){
+                        if (ui.content instanceof Array && ui.content.length === 1) {
+                            selectProduct = ui.content[0];    
+                            $(this).autocomplete("close");
+                            $(this).val('');
+                            self.factInsert(selectProduct);
+                        }                
+                    },
                     select: function (e, ui) {
                         $(this).val('');
                         selectProduct = ui.item;
@@ -131,13 +139,22 @@ openerp.eiru_sale_order = function (instance, local) {
                 var results = self.ProductProduct;
                 results = _.map(results, function (item) {
                 return {
-                        label: item.name + ' (' + item.attribute_str + ')',
-                        value: item.id + ' - '+ item.name + '-' + item.attribute_str
-                }
+                        label: '[ ' + self.valorNull(item.default_code) + ' - ' + self.valorNull(item.ean13) + ' ] ' + item.name + ' (' + self.valorNull(item.attribute_str) + ')',
+                        value: item.id + ' - '+ item.name + ' (' + item.attribute_str + ')'
+                    }
                 });
-                self.$('#productSearch').autocomplete({
+                $('#productSearch').autocomplete({
                     source: results,
                     minLength: 3,
+                    response: function (e, ui){
+                        if (ui.content instanceof Array && ui.content.length === 1) {
+                            selectProduct = ui.content[0];    
+                            $(this).autocomplete("close");
+                            $(this).val('');
+                            self.factInsertProduct(selectProduct);
+                            return false;
+                        }                
+                    },
                     select: function (e, ui) {
                         $(this).val('');
                         selectProduct = ui.item;
@@ -172,6 +189,7 @@ openerp.eiru_sale_order = function (instance, local) {
 
         factInsertProduct:function(selectProduct){
             var self = this;
+            console.log(selectProduct);
             var product = selectProduct.value.split('-');
             var variant = self.getProductProduct(product[0]);
             var qty = 1;

+ 1 - 1
static/src/xml/sale_order_curve.xml

@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <template xml:space="preserve">
     <t t-name="eiru_sale_order.SaleOrderCurve">
-        <div class="ui-widget col-md-6 col-md-offset-3">
+        <div class="ui-widget col-md-8 col-md-offset-2">
         	<div class="form-group">
         		<label for="productSearch">Buscar: </label>
 		  		<input id="productSearch" class="form-control"/>