Browse Source

commit inicial

Rodney Elpidio Enciso Arias 6 years ago
commit
48b46cd579

+ 3 - 0
__init__.py

@@ -0,0 +1,3 @@
+# -*- coding: utf-8 -*-
+from model import stock_inventory
+from model import product

BIN
__init__.pyc


+ 20 - 0
__openerp__.py

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

+ 0 - 0
model/__init__.py


BIN
model/__init__.pyc


+ 25 - 0
model/product.py

@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+
+from openerp import models, fields, api
+
+class ProductProduct(models.Model):
+	_inherit = 'product.product'
+
+	############################################################
+	#	PRODUCT PRODUCT
+	############################################################
+
+	@api.model
+	def getProductProductSearch(self,domain):
+		ProductProduct = self.env['product.product'].search(domain)
+		values = []
+		for product in ProductProduct:
+
+			values.append({
+				'id': product.id,
+				'display_name': product.display_name,
+				'ean13': product.ean13,
+				'default_code': product.default_code,
+			})
+
+		return values

BIN
model/product.pyc


+ 28 - 0
model/stock_inventory.py

@@ -0,0 +1,28 @@
+# -*- coding: utf-8 -*-
+
+from openerp import api, fields, models
+from openerp.exceptions import except_orm
+
+class StockInventoryInsert(models.Model):
+	_inherit = 'stock.inventory'
+
+	@api.model
+	def insert_stock_inventory_line(self, values):
+		stock_inventory = self.env['stock.inventory'].search([('id','=',values['id'])])
+		stock_inventory_line = self.env['stock.inventory.line']
+		lines = stock_inventory_line.search([
+			('inventory_id', '=', values['id']),
+			('product_id', '=', values['product_id']),
+		])
+		if len(lines) == 0:
+			lines = {
+				'inventory_id' : values['id'],
+				'product_id': values['product_id'],
+				'product_qty': 1,
+				'location_id': stock_inventory.location_id.id,
+			}
+			stock_inventory_line.create(lines);
+		if len(lines) == 1:
+			lines.write({
+				'product_qty': lines.product_qty + 1,
+			})

BIN
model/stock_inventory.pyc


BIN
static/description/icon.png


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

@@ -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);
+            }
+        });
+    }
+};

+ 40 - 0
static/src/xml/modal.xml

@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<template xml:space="preserve">
+    <t t-name="StockInventoryProductModal">
+        <div class="modal in product-search-modal" tabindex="-1" role="dialog">
+            <div class="modal-dialog modal-lg" role="document">
+                <div class="modal-content openerp">
+                    <!-- title  -->
+                    <div class="modal-header">
+                        <button type="button" class="close" data-dismiss="modal" aria-label="Close" aria-hidden="true">x</button>
+                        <h3 class="modal-title" t-foreach="modalTitle" t-as="title">
+                            <t t-esc="title_value.title"/>
+                        </h3>
+                    </div>
+                    <!-- table -->
+                    <div class="oe_view_manager_body table-model">
+                        <div class="modal-items-wrapper">
+                            <table class="oe_list_content">
+                                <thead >
+                                    <tr class="oe_list_header_columns" >
+                                        <th t-foreach="dataThead" t-as="head" class="oe_list_header_char oe_sortable">
+                                            <t t-esc="head_value.title"/>
+                                        </th>
+                                    </tr>
+                                </thead>
+                                <tbody class="table-tbody">
+                                    <tr t-foreach="data" t-as="field">
+                                        <td style="display:none;"><t t-esc="field_value.id"/></td>
+                                        <td><t t-esc="field_value.display_name"/></td>
+                                        <td><t t-esc="field_value.default_code"/></td>
+                                        <td><t t-esc="field_value.ean13"/></td>
+                                    </tr>
+                                </tbody>
+                            </table>
+                        </div>
+                    </div>
+                </div>
+            </div>
+        </div>
+    </t>
+</template>

+ 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_inventory.StockInventoryProductSearch">
+        <div class="ui-widget col-md-8 col-md-offset-2">
+        	<div class="form-group search">
+        		<label for="StockInventoryProductSearch">Buscar: </label>
+		  		<input id="StockInventoryProductSearch" class="form-control"/>
+        	</div>
+            <div id="dialog"></div>
+		</div>
+    </t>
+</template>

+ 15 - 0
views/stock_inventory_product_search_box.xml

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<openerp>
+	<data>
+        <record id="stock_inventory_product_search_view" model="ir.ui.view">
+            <field name="name">stock.inventory.product.search.view</field>
+            <field name="model">stock.inventory</field>
+            <field name="inherit_id" ref="stock.view_inventory_form"/>
+            <field name="arch" type="xml">
+                <field name="line_ids" position="before">
+                    <div class="stock_inventory_product_search_box" attrs="{'invisible': [('state','not in',['confirm'])]}"></div>
+                </field>
+            </field>
+        </record>
+	</data>
+</openerp>

+ 9 - 0
views/template.xml

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