Bladeren bron

commit inicial

Rodney Elpidio Enciso Arias 6 jaren geleden
commit
59b3d01aed

+ 2 - 0
__init__.py

@@ -0,0 +1,2 @@
+# -*- coding: utf-8 -*-
+from model import stock_picking

BIN
__init__.pyc


+ 19 - 0
__openerp__.py

@@ -0,0 +1,19 @@
+# -*- coding: utf-8 -*-
+{
+    'name' : 'Barcode Stock',
+    'version' : '1.0',
+    'description' : """
+    """,
+    'author' : 'Eiru',
+    'category' : 'stock',
+    'depends' : [
+        'stock',
+    ],
+    'data' : [
+        'views/template.xml',
+        'views/stock_search_box.xml',
+    ],
+    'qweb' : ['static/src/xml/*.xml',],
+    'installable' : True,
+    'auto_install' : False,
+}

+ 0 - 0
model/__init__.py


BIN
model/__init__.pyc


+ 38 - 0
model/stock_picking.py

@@ -0,0 +1,38 @@
+# -*- coding: utf-8 -*-
+
+from openerp import api, fields, models
+from openerp.exceptions import except_orm
+
+class StockPickingInsert(models.Model):
+	_inherit = 'stock.picking'
+
+	origin_location = fields.Many2one('stock.location', 'Ubicacion de Origen', compute="get_origin_location")
+	destination_location = fields.Many2one('stock.location', 'Ubicacion de destino', domain="[('usage','<>','view')]")
+
+	@api.one
+	def get_origin_location(self):
+		self.origin_location = self.picking_type_id.default_location_src_id.id
+		# if self.picking_type_id.code <> 'internal':
+		# 	self.destination_location = self.picking_type_id.default_location_dest_id.id
+
+	@api.model
+	def stock_insert_lines(self, values):
+		stock_lines = self.env['stock.move']
+		lines = stock_lines.search([
+			('picking_id', '=', values['id']),
+			('product_id', '=', values['product_id']),
+		])
+		if len(lines) == 0:
+			lines = {
+				'picking_id' : values['id'],
+				'name' : values['name'],
+				'product_id': values['product_id'],
+				'product_uom': values['product_uom'],
+				'location_id': values['location_id'],
+				'location_dest_id': values['location_dest_id'],
+			}
+			stock_lines.create(lines);
+		if len(lines) == 1:
+			lines.write({
+				'product_uom_qty': lines.product_uom_qty + 1,
+			})

BIN
model/stock_picking.pyc


BIN
static/description/icon.png


+ 195 - 0
static/src/js/stock.js

@@ -0,0 +1,195 @@
+openerp.barcode_stock = function (instance, local) {
+    local.widgetInstance = null;
+    local.parentInstance = null;
+
+    local.StockSearchWidget = instance.Widget.extend({
+        template : "barcode_stock.StockSearch",
+
+        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 () {
+                self.fecthInitial();
+            });
+        },
+
+        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
+        },
+
+        fecthInitial: function(){
+            var id = openerp.webclient._current_state.id;
+            var self = this;
+            self.fecthStock(id).then(function(stock){
+                return stock;
+            }).then(function(stock){
+                self.stock = stock;
+                return self.fetchProductProduct();
+            }).then(function(ProductProduct){
+                self.ProductProduct = ProductProduct;
+                self.inicializarBuscador();
+            });
+            return false;
+        },
+
+        fecthStock: function(id){
+            var defer = $.Deferred();
+            var fields=['id','name','origin_location','destination_location'];
+            var domain=[['id','=', id]];
+            var Stock = new instance.web.Model('stock.picking');
+            Stock.query(fields).filter(domain).all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+
+        fetchProductProduct: function () {
+            var defer = $.Deferred();
+            var fields=['id','name','ean13','uom_id'];
+            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;
+            });
+        },
+
+        inicializarBuscador: function () {
+            var self = this;
+            var selectProduct;
+            $("#productSearch").keypress(function(e) {
+                var 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.');
+                        }
+                    }
+                }
+            });
+        },
+
+        factInsertProduct:function(product){
+            var self = this;
+            var prod = product[0];
+            var uom_id = product[0].uom_id[0];
+            var origin = self.stock[0].origin_location[0];
+            var destination = self.stock[0].destination_location[0];
+            if(destination == undefined){
+                self.showMensaje('Elegir destino de los productos.');
+                self.$el.find('#productSearch').val('');
+                return false;
+            }
+            self.fetchInsert(prod, uom_id, origin, destination).then(function(results) {
+                return results;
+            }).then(function(){
+                self.reloadLine();
+            });
+        },
+
+        fetchInsert: function(product, uom_id, origin, destination) {
+            var self = this;
+            var defer = $.Deferred();
+            var stock = new openerp.web.Model('stock.picking');
+            stock.call('stock_insert_lines',[
+                {
+                    id: self.stock[0].id,
+                    product_id: product.id,
+                    name: product.name,
+                    product_uom: uom_id,
+                    location_id: origin,
+                    location_dest_id: destination,
+                }
+            ],{
+                context: new openerp.web.CompoundContext()
+            }).then(function(results) {
+                defer.resolve(results);
+            });
+            self.$el.find('#productSearch').val('');
+            return defer;
+        },
+    });
+
+    if (instance.web && instance.web.FormView) {
+        instance.web.FormView.include({
+            load_form: function (record) {
+                this._super.apply(this, arguments);
+                if (this.model !== 'stock.picking') return;
+                local.parentInstance = this;
+                if (local.widgetInstance) {
+                    local.widgetInstance.updateId(record.id);
+                }
+                local.widgetInstance = new local.StockSearchWidget(this);
+                var elemento = this.$el.find('.oe_form_sheet.oe_form_sheet_width');
+                elemento =  elemento.find('.stock_product_search_box');
+                local.widgetInstance.appendTo(elemento);
+                local.widgetInstance.updateId(record.id);
+            }
+        });
+    }
+}

+ 12 - 0
static/src/xml/search.xml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<template xml:space="preserve">
+    <t t-name="barcode_stock.StockSearch">
+        <div class="ui-widget col-md-8 col-md-offset-2">
+        	<div class="form-group search">
+        		<label for="productSearch">Buscar: </label>
+		  		<input id="productSearch" class="form-control"/>
+        	</div>
+            <div id="dialog"></div>
+		</div>
+    </t>
+</template>

+ 19 - 0
views/stock_search_box.xml

@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<openerp>
+	<data>
+        <record id="stock_product_search_view" model="ir.ui.view">
+            <field name="name">stock.product.search.view</field>
+            <field name="model">stock.picking</field>
+            <field name="inherit_id" ref="stock.view_picking_form"/>
+            <field name="arch" type="xml">
+                <field name="move_lines" position="before">
+					<group colspan="4" col="6" attrs="{'invisible': [('state','not in',['draft'])]}">
+                        <field name="origin_location"/>
+                        <field name="destination_location"/>
+                    </group>
+					<div class="stock_product_search_box" attrs="{'invisible': [('state','not in',['draft'])]}"></div>
+                </field>
+            </field>
+        </record>
+	</data>
+</openerp>

+ 9 - 0
views/template.xml

@@ -0,0 +1,9 @@
+<openerp>
+    <data>
+        <template id="barcode_stock.assets_backend" name="barcode_stock_assets" inherit_id="eiru_assets.assets">
+            <xpath expr="." position="inside">
+                <script type="text/javascript" src="/barcode_stock/static/src/js/stock.js"/>
+            </xpath>
+        </template>
+    </data>
+</openerp>