Adrielso пре 8 година
комит
c42e6dd6d9

+ 2 - 0
__init__.py

@@ -0,0 +1,2 @@
+# -*- coding: utf-8 -*-
+from . import models


+ 17 - 0
__openerp__.py

@@ -0,0 +1,17 @@
+# -*- coding: utf-8 -*-
+{   'name': 'Search_Barcode_Purchase',
+    'version': '8.0.0.1.0',
+    'category': 'Sales & Purchases',
+    'description': """
+Buscar Productos por código de barra (EAN 13 o Referencia de fábrica )
+=====================================================================
+Este módulo añade un botón "Activar Lector" en las órdenes de compra que  llama a un asistente
+que permite la búsqueda de producto por códigos (EAN 13 o Referencia de fábrica)    """,
+    'author':  'Adrielso kunert ',
+    'license': 'AGPL-3',
+    'depends': [ 'purchase', ],
+    'data': [ 'wizard/purchase_add_multiple.xml', 'purchase_view.xml' ],
+    'installable': True,
+    'auto_install': False,
+    'application': False,
+}

+ 2 - 0
models/__init__.py

@@ -0,0 +1,2 @@
+# -*- coding: utf-8 -*-
+from . import search_barcode_purchase

BIN
models/__init__.pyc


+ 76 - 0
models/search_barcode_purchase.py

@@ -0,0 +1,76 @@
+# -*- coding: utf-8 -*-
+
+from openerp import models, fields, api, _
+from openerp.exceptions import Warning as UserError
+
+class Search_Barcode_Purchase(models.TransientModel):
+    _name = 'search.barcode.purchase'
+    _description = 'Buscar Producto por Codigo de Barra en Compras'
+
+    quantity = fields.Float('Quantity', default='1.0')
+    products_ids = fields.Many2many( 'product.product',
+                                      string='Products',
+                                      domain=[('sale_ok', '=', True)], )
+    product_code = fields.Char( string='Codigo de Barra EAN13 ',
+                                help="Este campo está diseñado para ser llenado con un lector de código de barras")
+
+    @api.onchange('product_code')
+    def product_code_change(self):
+        if self.product_code:
+            products = self.env['product.product'].search([
+                                '|', ('ean13', '=', self.product_code), ('default_code', '=ilike', self.product_code)])
+
+            if len(products) == 1:
+                self.products_ids += products[0]
+                self.product_code =None
+
+            elif len(products) > 1:
+                self.product_code =None
+                return {'warning': {
+                    'title': _('Error'),
+                    'message': _(
+                        'Varios productos se han encontrado con el código (EAN 13) ingresado,'
+                        '\nDebe seleccionar el producto manualmente.')}}
+            else:
+                self.product_code =None
+                return {'warning': {
+                    'title': _('Error'),
+                    'message': _(
+                        'Ningún producto encontrado con el  código (EAN 13) ingresado, Debe seleccionar el producto manualmente')}}
+
+    @api.one
+    def add_multiple(self):
+        active_id = self._context['active_id']
+        purchase = self.env['purchase.order'].browse(active_id)
+
+        x=0
+        if purchase.order_line:
+            seq =purchase.order_line[len(purchase.order_line) - 1]
+            x=seq.sequence
+
+        for product_id in self.products_ids:
+            xxproducts = self.env['product.product'].search([('id', '=', product_id.id)])
+            orde_line_datos = self.env['purchase.order.line'].search([('order_id', '=', purchase.id), ('product_id', "=", xxproducts.id)])
+            x += 1
+            product = self.env['purchase.order.line'].product_id_change(
+                purchase.pricelist_id.id,
+                product_id.id,
+                qty=self.quantity,
+                uom_id=product_id.uom_po_id.id,
+                partner_id=purchase.partner_id.id)
+
+            if orde_line_datos:
+                orde_line_datos.write({ 'product_qty' : (orde_line_datos.product_qty + 1)})
+            else:
+                val = {
+                    'name':  product['value'].get('name'),
+                    'product_uom_qty': self.quantity,
+                    'order_id': active_id,
+                    'product_id': product_id.id or False,
+                    'product_uom': product_id.uom_po_id.id,
+                    'date_planned': product['value'].get('date_planned'),
+                    'price_unit': product['value'].get('price_unit'),
+                    'taxes_id': [(6, 0, product['value'].get('taxes_id'))],
+                    'sequence': x,
+                }
+                self.env['purchase.order.line'].create(val)

BIN
models/search_barcode_purchase.pyc


+ 17 - 0
purchase_view.xml

@@ -0,0 +1,17 @@
+<?xml version="1.0"?>
+<openerp>
+    <data>
+        <record id="view_order_form" model="ir.ui.view">
+            <field name="name">purchase.order.form</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">
+                    <button name="%(action_purchase_add_multiple)d"
+                            type="action" string="Activar Lector"
+                            attrs="{'invisible':[('state','not in',['draft','sent'])]}"/>
+                </field>
+            </field>
+        </record>
+    </data>
+</openerp>

BIN
static/description/icon.png


BIN
wizard/__init__.pyc


+ 42 - 0
wizard/purchase_add_multiple.xml

@@ -0,0 +1,42 @@
+<?xml version="1.0"?>
+<openerp>
+    <data>
+        <record model="ir.ui.view" id="search_barcode_purchase_view">
+            <field name="name">search.barcode.purchase.form</field>
+            <field name="model">search.barcode.purchase</field>
+            <field name="arch" type="xml">
+                <form string="Add Multiple">
+
+                    <group>
+                        <field name='product_code' />
+                    </group>
+                    <group>
+                        <field name="products_ids" nolabel='1'>
+                          <tree string="Product Variants">
+                            <field name="factory_reference"/>
+                            <field name="factory_barcode"/>
+                            <field name="product_tmpl_id"/>
+                            <field name="attribute_value_ids" widget="many2many_tags"/>
+                            <field name="standard_price" string="Precio coste"/>
+                            <!-- <field name="price" invisible="not context.get('pricelist',False)"/> -->
+                            <!-- <field name="uom_id"/> -->
+                          </tree>
+                        </field>
+                    </group>
+                <footer>
+                    <button name="add_multiple" type="object" class="oe_highlight" string="Aceptar"/>
+                </footer>
+                </form>
+            </field>
+        </record>
+
+        <record model="ir.actions.act_window" id="action_purchase_add_multiple">
+            <field name="name">Purchase Order Add Multiple</field>
+            <field name="res_model">search.barcode.purchase</field>
+            <field name="view_type">form</field>
+            <field name="view_mode">form</field>
+            <field name="view_id" ref="search_barcode_purchase_view"/>
+            <field name="target">new</field>
+        </record>
+    </data>
+</openerp>

BIN
wizard/purchase_order_wizard.pyc