avanzosc team mailing list archive
-
avanzosc team
-
Mailing list archive
-
Message #00730
Re: [Merge] lp:~mikelarregi/avanzosc/dos_picking_in_import into lp:~avanzosc-security-team/avanzosc/72horas
Lo del stock_warehouse, no lo he hecho así pero la solución serviría, creo yo
comentario inline
Diff comments:
> === modified file 'dos_picking_in_import/__init__.py'
> --- dos_picking_in_import/__init__.py 2014-06-11 10:23:47 +0000
> +++ dos_picking_in_import/__init__.py 2014-07-03 15:42:12 +0000
> @@ -19,7 +19,7 @@
> #
> ##############################################################################
>
> -import wizard
> -import stock
> +from . import wizard
> +from . import models
>
> # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
>
> === modified file 'dos_picking_in_import/__openerp__.py'
> --- dos_picking_in_import/__openerp__.py 2014-06-11 10:23:47 +0000
> +++ dos_picking_in_import/__openerp__.py 2014-07-03 15:42:12 +0000
> @@ -19,19 +19,17 @@
> #
> ##############################################################################
>
> -
> {
> - "name" : "DOS Services To Invoice",
> - "version" : "1.0",
> - "author" : "DOS",
> - "category" : "Stock",
> - "website" : "www.dos-sl.es",
> - "description": "This module allows to speed up the process of importing invoices input from a data file for the automatic creation of the delivery note lines with the SIM and lot numbers specified in the file.",
> - "depends" : ['stock'],
> - "init_xml" : [],
> - "update_xml" : ['wizard/picking_in_import_view.xml', 'stock_view.xml'],
> - "active": False,
> + "name": "DOS Services To Invoice",
> + "version": "1.0",
> + "author": "DOS",
> + "category": "Stock",
> + "website": "www.dos-sl.es",
> + "description": "This module allows to speed up the process of "
> + "importing invoices input from a data file for the "
> + " automatic creation of the delivery note lines with "
> + "the SIM and lot numbers specified in the file.",
> + "depends": ['stock'],
> + "data": ['wizard/picking_in_import_view.xml', 'views/stock_view.xml'],
> "installable": True
> }
> -
> -
>
> === added directory 'dos_picking_in_import/models'
> === added file 'dos_picking_in_import/models/__init__.py'
> --- dos_picking_in_import/models/__init__.py 1970-01-01 00:00:00 +0000
> +++ dos_picking_in_import/models/__init__.py 2014-07-03 15:42:12 +0000
> @@ -0,0 +1,22 @@
> +# -*- coding: utf-8 -*-
> +##############################################################################
> +#
> +# OpenERP, Open Source Management Solution
> +# Copyright (C) 2004-2010 DOS (<http://www.dos-sl.es>). All Rights Reserved
> +#
> +# This program is free software: you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation, either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program. If not, see <http://www.gnu.org/licenses/>.
> +#
> +##
> +
> +from . import stock
> \ No newline at end of file
>
> === renamed file 'dos_picking_in_import/stock.py' => 'dos_picking_in_import/models/stock.py'
> --- dos_picking_in_import/stock.py 2014-06-11 10:23:47 +0000
> +++ dos_picking_in_import/models/stock.py 2014-07-03 15:42:12 +0000
> @@ -19,88 +19,78 @@
> #
> ##############################################################################
>
> -from osv import fields, osv
> -import decimal_precision as dp
> +from openerp.osv import fields, orm
> import time
>
> -class stock_picking(osv.osv):
> -
> - _inherit ="stock.picking"
> +
> +class StockPicking(orm.Models):
> +
> + _inherit = "stock.picking"
>
> def do_partial(self, cr, uid, ids, partial_datas, context=None):
> -
> - res = super(stock_picking, self).do_partial(cr, uid, ids, partial_datas, context=context)
> -
> - if context is None: context = {}
> -
> - stock_move_obj = self.pool.get('stock.move')
> - stock_warehouse_obj = self.pool.get('stock.warehouse')
> -
> - #Comprobamos que hay al menos un almacen definido
> - stock_warehouse = None
> - stock_warehouse_ids = stock_warehouse_obj.search(cr, uid, [])
> - for warehouse in stock_warehouse_obj.browse(cr, uid, stock_warehouse_ids, context):
> - stock_warehouse = warehouse
> - break
> -
> - if stock_warehouse:
> -
> + res = super(StockPicking, self).do_partial(cr, uid, ids, partial_datas,
> + context=context)
> + if context is None:
> + context = {}
> + stock_move_obj = self.pool['stock.move']
> + stock_warehouse_obj = self.pool['stock.warehouse']
> + # Comprobamos que hay al menos un almacen definido
> + stock_warehouse = None
> + stock_warehouse_ids = stock_warehouse_obj.search(cr, uid, [],
> + context=context)[0]
> + stock_warehouse = stock_warehouse_obj.browse(cr, uid,
> + stock_warehouse_ids,
Si stock_warehouse_ids tiene de por si el [0] no serviría
> + context):
> + if stock_warehouse:
> for id in ids:
> if id in res and 'delivered_picking' in res[id]:
> picking_id = res[id]['delivered_picking']
> - picking = self.browse(cr, uid, picking_id, context=context)
> - picking_internal_id = None
> -
> - # Solo al validar albaranes de entrada
> - if picking.type in ('in',):
> -
> - for line in picking.move_lines:
> -
> - #Comprobamos si el lote se debe trasladar de ubicacion
> - # SIM - Si tiene fecha activacion
> - # ENLACE - Si tiene fecha activacion
> - if line.prodlot_id and line.prodlot_id.fecha_activacion:
> -
> - if not picking_internal_id:
> - #Creamos albaran interno que englobara todos los traspasos
> - vals = {
> - 'origin': picking.name,
> - 'date': time.strftime('%Y-%m-%d %H:%M:%S'),
> - 'move_type': 'direct',
> - 'invoice_state': 'none',
> - 'state': 'draft',
> - 'auto_picking': False,
> - 'type': 'internal',
> - }
> -
> - picking_internal_id = self.create(cr, uid, vals)
> -
> - #Traspaso de ubicacion
> - product = line.prodlot_id.product_id
> -
> - vals = {
> - 'picking_id': picking_internal_id,
> - 'product_id': product.id,
> - 'name': '[' + product.default_code + '] ' + product.name,
> - 'prodlot_id': line.prodlot_id.id,
> - 'product_qty': 1,
> - 'product_uos_qty': 1,
> - 'product_uom': 1,
> - 'location_id': stock_warehouse.lot_input_id.id,
> - 'location_dest_id': stock_warehouse.lot_stock_id.id,
> - 'date_expected': time.strftime('%Y-%m-%d %H:%M:%S'),
> - 'date': time.strftime('%Y-%m-%d %H:%M:%S'),
> - 'auto_validate': False,
> - 'priority': '1',
> - 'state': 'done',
> - }
> -
> - stock_move_int_id = stock_move_obj.create(cr, uid, vals)
> -
> - #Validamos albaran interno si se han traspasado lotes
> - if picking_internal_id:
> - self.write(cr, uid, [picking_internal_id], {'state': 'done'})
> -
> + picking = self.browse(cr, uid, picking_id, context=context)
> + internal_pick_id = None
> + # Solo al validar albaranes de entrada
> + if picking.type =='in':
> + for line in picking.move_lines:
> + # Comprobamos si el lote se debe trasladar de ubicacion
> + # SIM - Si tiene fecha activacion
> + # ENLACE - Si tiene fecha activacion
> + if (line.prodlot_id
> + and line.prodlot_id.fecha_activacion):
> + if not internal_pick_id:
> + # Creamos albaran interno
> + # que englobara todos los traspasos
> + curr_data = time.strftime('%Y-%m-%d %H:%M:%S')
> + vals = {'origin': picking.name,
> + 'date': curr_data,
> + 'move_type': 'direct',
> + 'invoice_state': 'none',
> + 'state': 'draft',
> + 'auto_picking': False,
> + 'type': 'internal',
> + }
> + internal_pick_id = self.create(cr, uid,
> + vals,
> + context=context)
> + # Traspaso de ubicacion
> + product = line.prodlot_id.product_id
> + vals = {
> + 'picking_id': internal_pick_id,
> + 'product_id': product.id,
> + 'name': '[%s] %s' % (product.default_code,
> + product.name),
> + 'prodlot_id': line.prodlot_id.id,
> + 'product_qty': 1,
> + 'product_uos_qty': 1,
> + 'product_uom': 1,
> + 'location_id': stock_warehouse.lot_input_id.id,
> + 'location_dest_id': stock_warehouse.lot_stock_id.id,
> + 'date_expected': time.strftime('%Y-%m-%d %H:%M:%S'),
> + 'date': time.strftime('%Y-%m-%d %H:%M:%S'),
> + 'auto_validate': False,
> + 'priority': '1',
> + 'state': 'done',
> + }
> + stock_move_int_id = stock_move_obj.create(cr, uid, vals)
> + # Validamos albaran interno si se han traspasado lotes
> + if internal_pick_id:
> + self.write(cr, uid, [internal_pick_id], {'state': 'done'})
> return res
> -
> -stock_picking()
>
> === added directory 'dos_picking_in_import/views'
> === renamed file 'dos_picking_in_import/stock_view.xml' => 'dos_picking_in_import/views/stock_view.xml'
> --- dos_picking_in_import/stock_view.xml 2014-06-11 10:23:47 +0000
> +++ dos_picking_in_import/views/stock_view.xml 2014-07-03 15:42:12 +0000
> @@ -6,7 +6,6 @@
> <field name="name">picking.in.inherit.form</field>
> <field name="model">stock.picking</field>
> <field name="inherit_id" ref="stock.view_picking_in_form"/>
> - <field name="type">form</field>
> <field name="arch" type="xml">
> <xpath expr="/form/notebook/page/field[@name='move_lines']/tree/field[@name='state']" position="after">
> <button name="%(action_view_picking_in_import)d" states="assigned,draft" string="Import file" type="action" icon="gtk-execute"/>
>
> === modified file 'dos_picking_in_import/wizard/__init__.py'
> --- dos_picking_in_import/wizard/__init__.py 2014-06-11 10:23:47 +0000
> +++ dos_picking_in_import/wizard/__init__.py 2014-07-03 15:42:12 +0000
> @@ -19,6 +19,6 @@
> #
> ##############################################################################
>
> -import picking_in_import
> +from . import picking_in_import
>
> # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
>
> === modified file 'dos_picking_in_import/wizard/picking_in_import.py'
> --- dos_picking_in_import/wizard/picking_in_import.py 2014-06-11 10:23:47 +0000
> +++ dos_picking_in_import/wizard/picking_in_import.py 2014-07-03 15:42:12 +0000
> @@ -19,17 +19,16 @@
> #
> ##############################################################################
>
> -import tools
> import base64
> import logging
> -import pooler
> import csv
> import time
> -from tools.translate import _
> +from openerp.tools.translate import _
> from tempfile import TemporaryFile
> -from osv import osv, fields
> -
> -class picking_in_import(osv.osv_memory):
> +from openerp.osv import orm, fields
> +
> +
> +class PickingInImport(orm.TransientModel):
> """ Picking In Import """
>
> _name = "picking.in.import"
> @@ -37,281 +36,283 @@
> _inherit = "ir.wizard.screen"
>
> _columns = {
> - 'product_type': fields.selection([('sim', 'Tarjeta SIM'), ('enlace', 'Enlace')], 'Product type'),
> - 'data': fields.binary('File', required=True),
> - }
> + 'product_type': fields.selection([('sim', 'Tarjeta SIM'),
> + ('enlace', 'Enlace')],
> + 'Product type'),
> + 'data': fields.binary('File', required=True),
> + }
>
> def is_date(self, date):
> try:
> if date != '':
> valid_date = time.strptime(date, '%Y-%m-%d')
> - return True
> - except ValueError:
> + return True
> + except ValueError:
> return False
>
> def verify_line(self, dic):
> result = False
> - if 'product_id' in dic:
> + if 'product_id' in dic:
> if 'fecha_alta' in dic and not self.is_date(dic['fecha_alta']):
> return False
> - result = True
> - return result
> + result = True
> + return result
>
> def exist_production_lot(self, cr, uid, dic):
> - db_name = cr.dbname
> - pool = pooler.get_pool(db_name)
> - production_lot_obj = pool.get('stock.production.lot')
> - product_obj = pool.get('product.product')
> -
> + production_lot_obj = self.pool['stock.production.lot']
> + product_obj = self.pool['product.product']
> product = product_obj.browse(cr, uid, dic['product_id'])
> - if product_obj._is_sim(product.categ_id) or product_obj._is_pack(product.categ_id):
> - return production_lot_obj.search(cr, uid, [('product_id', '=', product.id), ('name', '=', dic['name']), ('ref', '=', dic.get('telefono'))])
> + if (product_obj._is_sim(product.categ_id) or
> + product_obj._is_pack(product.categ_id)):
> + return production_lot_obj.search(cr, uid,
> + [('product_id', '=', product.id),
> + ('name', '=', dic['name']),
> + ('ref', '=', dic.get('telefono'))
> + ])
> elif product_obj._is_link(product.categ_id):
> - return production_lot_obj.search(cr, uid, [('product_id', '=', product.id), ('name', '=', dic['name'])])
> + return production_lot_obj.search(cr, uid,
> + [('product_id', '=', product.id),
> + ('name', '=', dic['name'])])
> else:
> return False
>
> def get_stock_move_active(self, cr, uid, picking_id, product_id):
> - db_name = cr.dbname
> - pool = pooler.get_pool(db_name)
> - stock_picking_obj = pool.get('stock.picking')
> -
> - picking = stock_picking_obj.browse(cr, uid, picking_id, context=None)
> - move = None
> -
> - for line in picking.move_lines:
> - if line.product_id.id == product_id and line.product_qty > 0 and not line.prodlot_id:
> + stock_picking_obj = self.pool['stock.picking']
> + picking = stock_picking_obj.browse(cr, uid, picking_id, context=None)
> + move = None
> + for line in picking.move_lines:
> + if line.product_id.id == (product_id and line.product_qty > 0
> + and not line.prodlot_id):
> move = line
> - break
> -
> - return move
> + break
> + return move
>
> def create_production_lot(self, cr, uid, dic):
> - db_name = cr.dbname
> - pool = pooler.get_pool(db_name)
> - lot_obj = pool.get('stock.production.lot')
> - product_obj = pool.get('product.product')
> -
> + lot_obj = self.pool['stock.production.lot']
> + product_obj = self.pool['product.product']
> lot_id = lot_obj.create(cr, uid, dic)
> product = product_obj.browse(cr, uid, dic['product_id'])
> -
> if product_obj._is_pack(product.categ_id):
> ldm = product.bom_ids[0]
> for m in ldm.bom_lines:
> if product_obj._is_sim(m.product_id.categ_id):
> - if not lot_obj.search(cr, uid, [('product_id', '=', m.product_id.id), ('name', '=', dic['icc']), ('ref', '=', dic['telefono'])]):
> - self.create_production_lot(cr, uid, {'product_id': m.product_id.id,
> - 'name': dic['icc'],
> - 'icc': dic['icc'],
> - 'telefono': dic['telefono'],
> - 'pin': dic.get('pin'),
> - 'puk': dic.get('puk'),
> - 'fecha_alta': dic['fecha_alta'],
> - 'fecha_activacion': dic.get('fecha_activacion'),
> - 'descripcion': dic.get('descripcion'),
> - 'albaran_entrada': dic.get('albaran_entrada'),
> - })
> + lot_info = [('product_id', '=', m.product_id.id),
> + ('name', '=', dic['icc']),
> + ('ref', '=', dic['telefono'])]
> + if not lot_obj.search(cr, uid, lot_info):
> + lot_data = {
> + 'product_id': m.product_id.id,
> + 'name': dic['icc'],
> + 'icc': dic['icc'],
> + 'telefono': dic['telefono'],
> + 'pin': dic.get('pin'),
> + 'puk': dic.get('puk'),
> + 'fecha_alta': dic['fecha_alta'],
> + 'fecha_activacion': dic.get('fecha_activacion'),
> + 'descripcion': dic.get('descripcion'),
> + 'albaran_entrada': dic.get('albaran_entrada'),
> + }
> + self.create_production_lot(cr, uid, lot_data)
> elif product_obj._is_link(m.product_id.categ_id):
> - if not lot_obj.search(cr, uid, [('product_id', '=', m.product_id.id), ('name', '=', dic['imei'])]):
> - self.create_production_lot(cr, uid, {'product_id': m.product_id.id,
> - 'name': dic['imei'],
> - 'imei': dic['imei'],
> - 'n_serie': dic.get('n_serie'),
> - 'fecha_alta': dic['fecha_alta'],
> - 'propietario': dic.get('propietario'),
> - 'descripcion': dic.get('descripcion'),
> - 'albaran_entrada': dic.get('albaran_entrada'),
> - })
> -
> + lot_info = [('product_id', '=', m.product_id.id),
> + ('name', '=', dic['imei'])]
> + if not lot_obj.search(cr, uid, lot_info, context=context):
> + lot_data = {
> + 'product_id': m.product_id.id,
> + 'name': dic['imei'],
> + 'imei': dic['imei'],
> + 'n_serie': dic.get('n_serie'),
> + 'fecha_alta': dic['fecha_alta'],
> + 'propietario': dic.get('propietario'),
> + 'descripcion': dic.get('descripcion'),
> + 'albaran_entrada': dic.get('albaran_entrada')
> + }
> + self.create_production_lot(cr, uid, lot_data)
> return lot_id
> -
>
> - def load_data(self, cr, uid, fileobj, fileformat, header_line_columns, product, move_id, context):
> + def load_data(self, cr, uid, fileobj, fileformat, header_line_columns,
> + product, move_id, context):
> """Read file and save"""
> - logger = logging.getLogger('picking_in_import')
> -
> - if context is None:
> + logger = logging.getLogger('picking_in_import')
> + if context is None:
> context = {}
> -
> - db_name = cr.dbname
> - pool = pooler.get_pool(db_name)
> - stock_warehouse_obj = pool.get('stock.warehouse')
> - stock_move_obj = pool.get('stock.move')
> - stock_prod_lot_obj = pool.get('stock.production.lot')
> - product_obj = pool.get('product.product')
> -
> - try:
> + stock_warehouse_obj = self.pool['stock.warehouse']
> + move_obj = self.pool['stock.move']
> + stock_prod_lot_obj = self.pool['stock.production.lot']
> + product_obj = self.pool['product.product']
> + try:
> # Empezamos a leer fichero
> fileobj.seek(0)
> - if fileformat == 'csv':
> + if fileformat == 'csv':
> reader = csv.reader(fileobj, quotechar='"', delimiter=';')
> - # Leemos cabecera que contiene títulos y cabeceras
> - f = header_line_columns.split(';')
> - else:
> + # Leemos cabecera que contiene títulos y cabeceras
> + f = header_line_columns.split(';')
> + else:
> logger.error('Bad file format: %s', fileformat)
> - raise osv.except_osv(_('Bad file !'), _('Bad file format.'))
> -
> - #Comprobamos que hay al menos un almacen definido
> - stock_warehouse = None
> - stock_warehouse_ids = stock_warehouse_obj.search(cr, uid, [])
> -
> - for warehouse in stock_warehouse_obj.browse(cr, uid, stock_warehouse_ids, context):
> - stock_warehouse = warehouse
> - break
> -
> - if not stock_warehouse:
> - raise osv.except_osv(_('Stock Warehouse not defined !'), _('Stock Warehouse not defined.'))
> -
> - #Leemos fichero
> - line = 0
> - succesfull = True
> -
> - fileobj.seek(0)
> -
> - for row in reader:
> + raise orm.except_orm(_('Bad file !'), _('Bad file format.'))
> +
> + # Comprobamos que hay al menos un almacen definido
> + stock_warehouse = None
> + stock_warehouse_ids = (
> + stock_warehouse_obj.search(cr, uid, [], context=context)[0])
> + stock_warehouse = stock_warehouse_obj.browse(cr, uid,
> + stock_warehouse_ids,
> + context):
> + if not stock_warehouse:
> + raise orm.except_orm(_('Stock Warehouse not defined !'),
> + _('Stock Warehouse not defined.'))
> + # Leemos fichero
> + line = 0
> + succesfull = True
> + fileobj.seek(0)
> + for row in reader:
> line += 1
> - # Leemos para cada línea todos sus valores y los almacenamos en un diccionario
> - dic = {'product_id': product.id}
> - for i in range(len(f)):
> -
> - # Formateamos fecha
> - if f[i] in ('fecha_alta',):
> + # Leemos para cada línea todos sus valores y
> + # los almacenamos en un diccionario
> + dic = {'product_id': product.id}
> + for i in range(len(f)):
> + # Formateamos fecha
> + if f[i] in ('fecha_alta',):
> date = time.strptime(row[i], "%d/%m/%Y")
> - dic[f[i]] = time.strftime("%Y-%m-%d", date)
> -
> - #Activamos el lote:
> - # SIM - Si la linea trae ICC y numero de telefono
> - # ENLACE - Siempre
> - if product_obj._is_link(product.categ_id) or ('icc' in dic and 'telefono' in dic):
> - dic['fecha_activacion'] = time.strftime("%Y-%m-%d", date)
> -
> - continue
> -
> - # Si la columna es icc o imei, la utilizamos como nombre de lote
> - elif f[i] == 'icc' and product_obj._is_sim(product.categ_id):
> - dic['name'] = row[i]
> - elif f[i] == 'imei' and (product_obj._is_link(product.categ_id) or product_obj._is_pack(product.categ_id)):
> - dic['name'] = row[i]
> -
> + dic[f[i]] = time.strftime("%Y-%m-%d", date)
> + # Activamos el lote:
> + # SIM - Si la linea trae ICC y numero de telefono
> + # ENLACE - Siempre
> + if (product_obj._is_link(product.categ_id) or
> + ('icc' in dic and 'telefono' in dic)):
> + dic['fecha_activacion'] = time.strftime("%Y-%m-%d",
> + date)
> + continue
> + # Si la columna es icc o imei,
> + # la utilizamos como nombre de lote
> + elif (f[i] == 'icc' and
> + product_obj._is_sim(product.categ_id)):
> + dic['name'] = row[i]
> + elif (f[i] == 'imei' and
> + (product_obj._is_link(product.categ_id) or
> + product_obj._is_pack(product.categ_id))):
> + dic['name'] = row[i]
> # Añadimos resto valores al diccionario
> - if row[i] not in ('NULL', ''):
> + if row[i] not in ('NULL', ''):
> dic[f[i]] = row[i]
> -
> - try:
> - #Actualizamos albaran de entrada con informacion de los lotes
> + try:
> + # Actualizamos albaran de entrada con
> + # informacion de los lotes
> if self.verify_line(dic):
> - move = stock_move_obj.browse(cr, uid, move_id)
> -
> - if move:
> -
> - #Creamos lote de produccion
> - stock_prod_lot_id = self.exist_production_lot(cr, uid, dic)
> - if stock_prod_lot_id:
> - stock_prod_lot_id = stock_prod_lot_id[0]
> - else:
> - stock_prod_lot_id = self.create_production_lot(cr, uid, dic)
> -
> - if move.product_qty > 1:
> -
> - #Creamos linea de albaran con informacion del lote
> - default_val = {
> - 'prodlot_id': stock_prod_lot_id,
> - 'product_qty': 1,
> - 'product_uos_qty': 1,
> - 'state': move.state
> - }
> -
> - stock_move_id = stock_move_obj.copy(cr, uid, move.id, default_val, context=context)
> -
> - #Decrementamos cantidad en linea de albaran
> - update_val = {
> - 'product_qty': move.product_qty - 1,
> - 'product_uos_qty': move.product_uos_qty - 1,
> - 'state': move.state
> - }
> -
> - stock_move_obj.write(cr, uid, [move.id], update_val)
> -
> - else:
> - #Actualizamos linea de albaran origen con informacion del lote
> - default_val = {
> - 'prodlot_id': stock_prod_lot_id,
> - 'product_qty': 1,
> - 'product_uos_qty': 1,
> - 'state': move.state
> - }
> - stock_move_obj.write(cr, uid, [move.id], default_val)
> -
> - else:
> + move = move_obj.browse(cr, uid, move_id)
> + if move:
> + # Creamos lote de produccion
> + prod_lot_id = self.exist_production_lot(cr, uid,
> + dic)
> + if prod_lot_id:
> + prod_lot_id = prod_lot_id[0]
> + else:
> + prod_lot_id = self.create_production_lot(cr,
> + uid,
> + dic)
> + if move.product_qty > 1:
> + # Creamos linea de albaran
> + # con informacion del lote
> + default_val = {
> + 'prodlot_id': prod_lot_id,
> + 'product_qty': 1,
> + 'product_uos_qty': 1,
> + 'state': move.state
> + }
> + stock_move_id = move_obj.copy(cr, uid,
> + move.id,
> + default_val,
> + context=context)
> + # Decrementamos cantidad en linea de albaran
> + product_uos_qty = move.product_uos_qty - 1
> + update_val = {
> + 'product_qty': move.product_qty - 1,
> + 'product_uos_qty': product_uos_qty,
> + 'state': move.state}
> + move_obj.write(cr, uid, [move.id],
> + update_val)
> + else:
> + # Actualizamos linea de albaran origen
> + # con informacion del lote
> + default_val = {'prodlot_id': prod_lot_id,
> + 'product_qty': 1,
> + 'product_uos_qty': 1,
> + 'state': move.state}
> + move_obj.write(cr, uid, [move.id],
> + default_val)
> + else:
> succesfull = False
> - filename = '[production_lot_import][format: %s]' % (fileformat)
> - logger.exception("Couldn't import production lot line %s of file %s", str(line), filename)
> - else:
> + filename = ('[production_lot_import][format: %s]' %
> + (fileformat))
> + logger.exception("Couldn't import production lot"
> + " line %s of file %s",
> + str(line), filename)
> + else:
> succesfull = False
> - filename = '[production_lot_import][format: %s]' % (fileformat)
> - logger.exception("Couldn't import production lot line %s of file %s", str(line), filename)
> - except:
> + filename = ('[production_lot_import][format: %s]' %
> + (fileformat))
> + logger.exception("Couldn't import production lot line"
> + " %s of file %s", str(line), filename)
> + except:
> succesfull = False
> - filename = '[production_lot_import][format: %s]' % (fileformat)
> - logger.exception("Couldn't import production lot line %s of file %s", str(line), filename)
> -
> - if succesfull:
> + filename = ('[production_lot_import][format: %s]' %
> + (fileformat))
> + logger.exception("Couldn't import production lot line"
> + " %s of file %s", str(line), filename)
> + if succesfull:
> logger.info("import file loaded succesfully")
> - else:
> + else:
> logger.info("import file loaded with errors")
> - raise osv.except_osv(_('Bad file !'), "Couldn't import production lot line %s of file %s" % (str(line), filename))
> -
> - except IOError:
> + raise orm.except_orm(_('Bad file !'),
> + _("Couldn't import production lot line"
> + " %s of file %s" % (str(line), filename)
> + ))
> + except IOError:
> filename = '[production_lot_import][format: %s]' % (fileformat)
> - logger.exception("Couldn't import production lot file %s", filename)
> + logger.exception("Couldn't import production lot file %s",
> + filename)
>
> def import_file(self, cr, uid, ids, context):
> """
> - Import File
> - @param cr: the current row, from the database cursor.
> - @param uid: the current user’s ID for security checks.
> - @param ids: the ID or list of IDs
> - @param context: A standard dictionary
> - """
> -
> - product_obj = self.pool.get('product.product')
> -
> - #Obtenemos datos de la línea del albarán
> - move_id = context['active_id']
> - product = self.pool.get('stock.move').browse(cr, uid, move_id).product_id
> -
> - import_data = self.browse(cr, uid, ids)[0]
> - fileobj = TemporaryFile('w+')
> - fileobj.write(base64.decodestring(import_data.data))
> -
> + Import File
> + @param cr: the current row, from the database cursor.
> + @param uid: the current user’s ID for security checks.
> + @param ids: the ID or list of IDs
> + @param context: A standard dictionary
> + """
> + product_obj = self.pool['product.product']
> + # Obtenemos datos de la línea del albarán
> + move_id = context['active_id']
> + product = self.pool['stock.move'].browse(cr, uid, move_id).product_id
> + import_data = self.browse(cr, uid, ids)[0]
> + fileobj = TemporaryFile('w+')
> + fileobj.write(base64.decodestring(import_data.data))
> # now we determine the file format
> - fileobj.seek(0)
> - first_line = fileobj.readline().strip().replace('"', '').replace(' ', '')
> - columns = first_line.split(';')
> - num_columns = len(columns)
> -
> - if product_obj._is_sim(product.categ_id) and num_columns == 7:
> - #Fichero SIM
> - header_line_columns = "icc;telefono;pin;puk;fecha_alta;descripcion;albaran_entrada"
> - fileformat = 'csv'
> - elif product_obj._is_link(product.categ_id) and num_columns == 6:
> - #Fichero Enlaces
> - header_line_columns = "imei;n_serie;fecha_alta;propietario;descripcion;albaran_entrada"
> - fileformat = 'csv'
> + fileobj.seek(0)
> + first_line = fileobj.readline().strip().replace('"', '').replace(' ',
> + '')
> + columns = first_line.split(';')
> + num_columns = len(columns)
> + if product_obj._is_sim(product.categ_id) and num_columns == 7:
> + # Fichero SIM
> + header_line_columns = ("icc;telefono;pin;puk;fecha_alta;"
> + "descripcion;albaran_entrada")
> + fileformat = 'csv'
> + elif product_obj._is_link(product.categ_id) and num_columns == 6:
> + # Fichero Enlaces
> + header_line_columns = ("imei;n_serie;fecha_alta;propietario;"
> + "descripcion;albaran_entrada")
> + fileformat = 'csv'
> elif product_obj._is_pack(product.categ_id) and num_columns == 9:
> - header_line_columns = "icc;telefono;pin;puk;imei;n_serie;fecha_alta;descripcion;albaran_entrada"
> - fileformat = 'csv'
> - else:
> + header_line_columns = ("icc;telefono;pin;puk;imei;n_serie;"
> + "fecha_alta;descripcion;albaran_entrada")
> + fileformat = 'csv'
> + else:
> header_line_columns = ""
> - fileformat = 'no_csv'
> -
> - fileobj.seek(0)
> -
> - self.load_data(cr, uid, fileobj, fileformat, header_line_columns, product, move_id, context)
> -
> - fileobj.close()
> -
> - return {}
> - #return {'type': 'ir.actions.act_window_close'}
> -
> -picking_in_import()
> + fileformat = 'no_csv'
> + fileobj.seek(0)
> + self.load_data(cr, uid, fileobj, fileformat, header_line_columns,
> + product, move_id, context)
> + fileobj.close()
> + return {}
> + # return {'type': 'ir.actions.act_window_close'}
>
> === modified file 'dos_picking_in_import/wizard/picking_in_import_view.xml'
> --- dos_picking_in_import/wizard/picking_in_import_view.xml 2014-06-11 10:23:47 +0000
> +++ dos_picking_in_import/wizard/picking_in_import_view.xml 2014-07-03 15:42:12 +0000
> @@ -13,7 +13,6 @@
> <record id="picking_in_import_view" model="ir.ui.view">
> <field name="name">picking.in.import.form</field>
> <field name="model">picking.in.import</field>
> - <field name="type">form</field>
> <field name="arch" type="xml">
> <form string = "Picking In Import">
> <group col="8">
>
--
https://code.launchpad.net/~mikelarregi/avanzosc/dos_picking_in_import/+merge/224147
Your team Avanzosc_security is subscribed to branch lp:~avanzosc-security-team/avanzosc/72horas.
References