Browse Source

Solucionar tema que al leer el lector aumente la cantidad

SEBAS 2 weeks ago
commit
fe1122e141

+ 2 - 0
__init__.py

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

BIN
__init__.pyc


+ 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 (Código EAN13, Referencia interna y Código de barra 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 (Código EAN13, Referencia interna y Código de barra 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


+ 202 - 0
models/search_barcode_purchase.py

@@ -0,0 +1,202 @@
+# -*- coding: utf-8 -*-
+from openerp import models, fields, api, _
+from openerp.exceptions import Warning as UserError
+
+
+class SearchBarcodePurchase(models.TransientModel):
+    _name = 'search.barcode.purchase'
+    _description = 'Buscar Producto por Codigo de Barra en Compras'
+
+    line_ids = fields.One2many(
+        'search.barcode.purchase.line', 'wiz_id', string='Escaneos')
+    product_code = fields.Char(
+        string='Codigo de Barra EAN13',
+        help="Escanee el código de barras aquí"
+    )
+
+    @api.onchange('product_code')
+    def _onchange_product_code(self):
+        if not self.product_code:
+            return
+
+        products = self.env['product.product'].search([
+            ('factory_barcode', '=ilike', self.product_code)
+        ])
+
+        if len(products) == 1:
+            prod = products[0]
+            existing = self.line_ids.filtered(lambda l: l.product_id.id == prod.id)
+            if existing:
+                existing.qty += 1
+            else:
+                self.line_ids += self.line_ids.new({
+                    'product_id': prod.id,
+                    'qty': 1.0,
+                })
+            self.product_code = None
+
+        elif len(products) > 1:
+            desc = u"\n\nProductos con el código repetido: %s" % self.product_code
+            for p in products:
+                desc += u"\n%s" % p.product_tmpl_id.name
+            self.product_code = None
+            return {'warning': {
+                'title': _('Error'),
+                'message': _(u'Varios productos se han encontrado con el código ingresado.\n'
+                             u'Debe seleccionar el producto manualmente.') + desc}}
+
+        else:
+            self.product_code = None
+            return {'warning': {
+                'title': _('Error'),
+                'message': _(u'Ningún producto encontrado con el código ingresado.\n'
+                             u'Debe seleccionar el producto manualmente.')}}
+
+    @api.multi
+    def add_multiple(self):
+        self.ensure_one()
+        purchase = self.env['purchase.order'].browse(self._context.get('active_id'))
+        if not purchase:
+            raise UserError(_('No se encontró la orden de compra activa.'))
+
+        for line in self.line_ids:
+            product = line.product_id
+            existing = self.env['purchase.order.line'].search([
+                ('order_id', '=', purchase.id),
+                ('product_id', '=', product.id),
+            ], limit=1)
+
+            onchange_vals = self.env['purchase.order.line'].product_id_change(
+                False,  # en compras no siempre hay pricelist_id
+                product.id,
+                qty=line.qty,
+                uom_id=product.uom_po_id.id,
+                partner_id=purchase.partner_id.id,
+            )
+
+            if existing:
+                existing.write({
+                    'product_qty': existing.product_qty + line.qty
+                })
+            else:
+                vals = {
+                    'name': onchange_vals['value'].get('name'),
+                    'order_id': purchase.id,
+                    'product_id': product.id,
+                    'product_uom': product.uom_po_id.id,
+                    'product_qty': line.qty,
+                    'date_planned': onchange_vals['value'].get('date_planned'),
+                    'price_unit': onchange_vals['value'].get('price_unit'),
+                    'taxes_id': [(6, 0, onchange_vals['value'].get('taxes_id') or [])],
+                }
+                self.env['purchase.order.line'].create(vals)
+
+        return {'type': 'ir.actions.act_window_close'}
+
+
+class SearchBarcodePurchaseLine(models.TransientModel):
+    _name = 'search.barcode.purchase.line'
+    _description = 'Líneas del wizard de lectura de EAN'
+
+    wiz_id = fields.Many2one(
+        'search.barcode.purchase', ondelete='cascade')
+    product_id = fields.Many2one(
+        'product.product', string='Producto',
+        domain=[('purchase_ok', '=', True)], required=True)
+    qty = fields.Float('Cantidad', default=1.0, required=True)
+
+
+# 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([('factory_barcode', '=ilike', self.product_code)])
+#
+#             if len(products) == 1:
+#                 self.products_ids += products[0]
+#                 self.product_code =None
+#
+#             elif len(products) > 1:
+#                 descrpcion="\n\nProductos con el codigo repetido : "+str(self.product_code)
+#                 for xx in products:
+#                     descrpcion +="\n"+str(xx.product_tmpl_id.name)
+#                 self.product_code =None
+#                 return {'warning': {
+#                     'title': _('Error'),
+#                     'message': _(
+#                         'Varios productos se han encontrado con el código ingresado,'
+#                         '\nDebe seleccionar el producto manualmente.'+descrpcion)}}
+#             else:
+#                 self.product_code =None
+#                 return {'warning': {
+#                     'title': _('Error'),
+#                     'message': _(
+#                         'Ningún producto encontrado con el código 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)
+
+            # if orde_line_datos:
+            #     orde_line_datos.write({
+            #         'product_qty': orde_line_datos.product_qty + (self.quantity or 1.0)
+            #     })
+            # else:
+            #     val = {
+            #         'name':  product['value'].get('name'),
+            #         'product_qty': self.quantity or 1.0,  # <-- antes: product_uom_qty
+            #         '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'))],
+            #     }
+            #     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


+ 76 - 0
wizard/purchase_add_multiple.xml

@@ -0,0 +1,76 @@
+<?xml version="1.0"?>
+<openerp>
+  <data>
+    <record id="search_barcode_purchase_view" model="ir.ui.view">
+      <field name="name">search.barcode.purchase.form</field>
+      <field name="model">search.barcode.purchase</field>
+      <field name="arch" type="xml">
+        <form string="Agregar por EAN">
+          <group>
+            <field name="product_code"/>
+          </group>
+          <group string="Escaneos">
+            <field name="line_ids" nolabel="1">
+              <tree editable="bottom" string="Productos">
+                <field name="product_id"/>
+                <field name="qty"/>
+              </tree>
+            </field>
+          </group>
+          <footer>
+            <button name="add_multiple" type="object" class="oe_highlight" string="Aceptar"/>
+            <button string="Cancelar" class="oe_link" special="cancel"/>
+          </footer>
+        </form>
+      </field>
+    </record>
+
+    <record id="action_purchase_add_multiple" model="ir.actions.act_window">
+      <field name="name">Agregar por EAN</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>
+
+<!-- <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" domain="[('purchase_ok','=',True)]">
+                          <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"/>
+                          </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> -->