Parcourir la source

commit inicial

Rodney Elpidio Enciso Arias il y a 6 ans
commit
ee81afe4db

+ 2 - 0
__init__.py

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

BIN
__init__.pyc


+ 20 - 0
__openerp__.py

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

+ 0 - 0
model/__init__.py


BIN
model/__init__.pyc


+ 46 - 0
model/purchase_order.py

@@ -0,0 +1,46 @@
+# -*- coding: utf-8 -*-
+
+from openerp import api, fields, models
+from openerp.exceptions import except_orm
+from datetime import datetime
+DATE_FORMAT = '%Y-%m-%d'
+
+class PurchaseOrderInsert(models.Model):
+	_inherit = 'purchase.order'
+
+	# amount_untaxed = fields.Float( compute='_compute_amount_all')
+	# amount_tax = fields.Float( compute='_compute_amount_all')
+	# amount_total = fields.Float( compute='_compute_amount_all')
+
+	@api.model
+	def purchase_insert_lines_by_eiru_original(self, values):
+		purchase_lines_eiru = self.env['purchase.order.line']
+		lines = purchase_lines_eiru.search([
+			('order_id', '=', values['id']),
+			('product_id', '=', values['product_id']),
+		])
+		if len(lines) == 0:
+			lines = {
+				'order_id' : values['id'],
+				'name' : values['name'],
+				'product_id': values['product_id'],
+				'price_unit': values['price_unit'],
+				'date_planned': datetime.now().strftime(DATE_FORMAT)
+			}
+			purchase_lines_eiru.create(lines);
+		if len(lines) == 1:
+			lines.write({
+				'product_qty': lines.product_qty + 1,
+			})
+
+	# @api.depends('order_line.price_subtotal')
+	# def _compute_amount_all(self):
+	# 	for order in self:
+	# 		amount_tax = amount_untaxed = 0.0
+	# 		currency = order.currency_id.with_context(date=order.date_order or fields.Date.context_today(order))
+	# 		for line in order.order_line:
+	# 			amount_untaxed += line.price_subtotal
+	# 			amount_tax += (line.product_uom_qty * line.price_unit) - line.price_subtotal
+	# 		order.amount_tax = currency.round(amount_tax)
+	# 		order.amount_untaxed = currency.round(amount_untaxed)
+	# 		order.amount_total = currency.round(amount_tax + amount_untaxed)

BIN
model/purchase_order.pyc


BIN
static/description/icon.png


+ 184 - 0
static/src/js/purchase.js

@@ -0,0 +1,184 @@
+openerp.barcode_purchase_order = function (instance, local) {
+    local.widgetInstance = null;
+    local.parentInstance = null;
+
+    local.PurchaseOrderSearchWidget = instance.Widget.extend({
+        template : "barcode_purchase_order.PurchaseOrderSearch",
+
+        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.fecthPurchase(id).then(function(purchase){
+                return purchase;
+            }).then(function(purchase){
+                self.purchase = purchase;
+                return self.fetchProductProduct();
+            }).then(function(ProductProduct){
+                self.ProductProduct = ProductProduct;
+                self.inicializarBuscador();
+            });
+            return false;
+        },
+
+        fecthPurchase: function(id){
+            var defer = $.Deferred();
+            var fields=['id','name'];
+            var domain=[['id','=', id]];
+            var Purchase = new instance.web.Model('purchase.order');
+            Purchase.query(fields).filter(domain).all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+
+        fetchProductProduct: function () {
+            var defer = $.Deferred();
+            var fields=['id','name','attribute_str','default_code','ean13','standard_price'];
+            var domain=[['active','=', true],['purchase_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) {
+                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();
+                var code = (e.keyCode ? e.keyCode : e.which);
+                if(code==13){
+                    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;
+            self.fetchInsert(product, 1).then(function(results) {
+                return results;
+            }).then(function(){
+                self.reloadLine();
+            });
+        },
+
+        fetchInsert: function(product, qty) {
+            var self = this;
+            var defer = $.Deferred();
+            var purchase = new openerp.web.Model('purchase.order');
+            purchase.call('purchase_insert_lines_by_eiru_original',[
+                {
+                    id: self.purchase[0].id,
+                    product_id: product[0].id,
+                    name: product[0].name,
+                    price_unit: product[0].standard_price,
+                }
+            ], {
+                    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 !== 'purchase.order') return;
+                local.parentInstance = this;
+                if (local.widgetInstance) {
+                    local.widgetInstance.updateId(record.id);
+                }
+                local.widgetInstance = new local.PurchaseOrderSearchWidget(this);
+                var elemento = this.$el.find('.oe_form_sheet.oe_form_sheet_width');
+                elemento =  elemento.find('.purchase_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_purchase_order.PurchaseOrderSearch">
+        <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>

+ 15 - 0
views/purchase_order_search_box.xml

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<openerp>
+	<data>
+        <record id="purchase_order_product_search_view" model="ir.ui.view">
+            <field name="name">purchase.order.product.search.view</field>
+            <field name="model">purchase.order</field>
+            <field name="inherit_id" ref="purchase.purchase_order_form"/>
+            <field name="arch" type="xml">
+                <field name="order_line" position="before">
+                    <div class="purchase_product_search_box" attrs="{'invisible': [('state','not in',['draft','sent'])]}"></div>
+                </field>
+            </field>
+        </record>
+	</data>
+</openerp>

+ 9 - 0
views/template.xml

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