|
@@ -2,19 +2,22 @@ openerp.eiru_sale_order = function (instance, local) {
|
|
|
local.widgetInstance = null;
|
|
|
local.parentInstance = null;
|
|
|
|
|
|
- local.SaleOrderWidget = instance.Widget.extend({
|
|
|
- template : "eiru_sale_order.SaleOrder",
|
|
|
+ local.SaleOrderCurveWidget = instance.Widget.extend({
|
|
|
+ template : "eiru_sale_order.SaleOrderCurve",
|
|
|
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;
|
|
|
this.$el.click(function () {
|
|
@@ -39,7 +42,7 @@ openerp.eiru_sale_order = function (instance, local) {
|
|
|
});
|
|
|
return false;
|
|
|
},
|
|
|
-
|
|
|
+
|
|
|
fecthSale: function(id){
|
|
|
var defer = $.Deferred();
|
|
|
var fields=['id','name','partner_id','state'];
|
|
@@ -63,13 +66,9 @@ openerp.eiru_sale_order = function (instance, local) {
|
|
|
},
|
|
|
|
|
|
fetchProductProduct: function () {
|
|
|
- var self = this;
|
|
|
var defer = $.Deferred();
|
|
|
var fields=['id','name','product_tmpl_id','attribute_str'];
|
|
|
- var product_tmpl_id = _.flatten(_.map(self.ProductTemplate,function(map){
|
|
|
- return map.id;
|
|
|
- }));
|
|
|
- var domain=[['active','=', true],['product_tmpl_id','=', product_tmpl_id]];
|
|
|
+ var domain=[['active','=', true]];
|
|
|
var ProductProduct = new instance.web.Model('product.product');
|
|
|
ProductProduct.query(fields).filter(domain).order_by('id').all().then(function(results){
|
|
|
defer.resolve(results);
|
|
@@ -83,6 +82,7 @@ openerp.eiru_sale_order = function (instance, local) {
|
|
|
return item.id == id;
|
|
|
});
|
|
|
},
|
|
|
+
|
|
|
getProduct : function(product_tmpl_id){
|
|
|
var self = this;
|
|
|
return _.filter(self.ProductProduct, function(item){
|
|
@@ -90,32 +90,67 @@ openerp.eiru_sale_order = function (instance, local) {
|
|
|
});
|
|
|
},
|
|
|
|
|
|
+ getProductProduct : function(id){
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.ProductProduct, function(item){
|
|
|
+ return item.id == id;
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
inicializarBuscador: function () {
|
|
|
var self = this;
|
|
|
- var results = self.ProductTemplate;
|
|
|
- results = _.map(results, function (item) {
|
|
|
+ var selectProduct;
|
|
|
+ var searchType = $('#SearchByCurve').is(":checked");
|
|
|
+ if(searchType){
|
|
|
+ var results = self.ProductTemplate;
|
|
|
+ results = _.map(results, function (item) {
|
|
|
return {
|
|
|
- label: item.id + '-'+ item.name,
|
|
|
+ label: item.name,
|
|
|
value: item.id + '-'+ item.name
|
|
|
- }
|
|
|
- });
|
|
|
- self.$('#productSearch').autocomplete({
|
|
|
- source: results,
|
|
|
- minLength:3,
|
|
|
- search: function() {
|
|
|
- if (!(self.$('#productSearch').val())){
|
|
|
- self.factInsert();
|
|
|
}
|
|
|
- },
|
|
|
- select: function() {
|
|
|
- self.factInsert();
|
|
|
+ });
|
|
|
+ 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);
|
|
|
+ // }
|
|
|
+ // },
|
|
|
+ select: function (e, ui) {
|
|
|
+ $(this).val('');
|
|
|
+ selectProduct = ui.item;
|
|
|
+ self.factInsert(selectProduct);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ var results = self.ProductProduct;
|
|
|
+ results = _.map(results, function (item) {
|
|
|
+ return {
|
|
|
+ label: item.name + ' (' + item.attribute_str + ')',
|
|
|
+ value: item.id + ' - '+ item.name + '-' + item.attribute_str
|
|
|
}
|
|
|
- });
|
|
|
+ });
|
|
|
+ self.$('#productSearch').autocomplete({
|
|
|
+ source: results,
|
|
|
+ minLength: 3,
|
|
|
+ select: function (e, ui) {
|
|
|
+ $(this).val('');
|
|
|
+ selectProduct = ui.item;
|
|
|
+ self.factInsertProduct(selectProduct);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
- factInsert:function(){
|
|
|
+ factInsert:function(selectProduct){
|
|
|
var self = this;
|
|
|
- var product = this.$el.find('#productSearch').val().split('-');
|
|
|
+ var product = selectProduct.value.split('-');
|
|
|
var template = self.getTemplate(product[0]);
|
|
|
var variant = self.getProduct(product[0]);
|
|
|
template = template[0].curva.split(',');
|
|
@@ -135,6 +170,18 @@ openerp.eiru_sale_order = function (instance, local) {
|
|
|
}
|
|
|
},
|
|
|
|
|
|
+ factInsertProduct:function(selectProduct){
|
|
|
+ var self = this;
|
|
|
+ var product = selectProduct.value.split('-');
|
|
|
+ var variant = self.getProductProduct(product[0]);
|
|
|
+ var qty = 1;
|
|
|
+ self.joinSaleLine(variant[0].id, qty).then(function(results) {
|
|
|
+ return results;
|
|
|
+ }).then(function(){
|
|
|
+ self.reloadLine();
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
joinSaleLine: function(product_id, qty) {
|
|
|
var self = this;
|
|
|
var defer = $.Deferred();
|
|
@@ -150,11 +197,10 @@ openerp.eiru_sale_order = function (instance, local) {
|
|
|
}).then(function(results) {
|
|
|
defer.resolve(results);
|
|
|
});
|
|
|
-
|
|
|
return defer;
|
|
|
},
|
|
|
-
|
|
|
});
|
|
|
+
|
|
|
if (instance.web && instance.web.FormView) {
|
|
|
instance.web.FormView.include({
|
|
|
load_form: function (record) {
|
|
@@ -164,7 +210,7 @@ openerp.eiru_sale_order = function (instance, local) {
|
|
|
if (local.widgetInstance) {
|
|
|
local.widgetInstance.updateId(record.id);
|
|
|
}
|
|
|
- local.widgetInstance = new local.SaleOrderWidget(this);
|
|
|
+ local.widgetInstance = new local.SaleOrderCurveWidget(this);
|
|
|
var elemento = this.$el.find('.oe_form_sheet.oe_form_sheet_width');
|
|
|
elemento = elemento.find('.product_search_box');
|
|
|
local.widgetInstance.appendTo(elemento);
|