← Back to team overview

avanzosc team mailing list archive

Re: [Merge] lp:~mikelarregi/avanzosc/dos_mrp_production into lp:~avanzosc-security-team/avanzosc/72horas

 

Review: Needs Fixing code review

Cuatro cosillas.

Diff comments:

> === modified file 'dos_mrp_production/__init__.py'
> --- dos_mrp_production/__init__.py	2014-06-11 10:23:47 +0000
> +++ dos_mrp_production/__init__.py	2014-06-19 15:55:19 +0000
> @@ -19,7 +19,6 @@
>  #
>  ##############################################################################
>  
> -import mrp_production
> -import mrp_procurement
> +from . import models
>  
>  # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
> 
> === modified file 'dos_mrp_production/__openerp__.py'
> --- dos_mrp_production/__openerp__.py	2014-06-11 10:23:47 +0000
> +++ dos_mrp_production/__openerp__.py	2014-06-19 15:55:19 +0000
> @@ -21,17 +21,14 @@
>  
>  
>  {
> -	"name" : "DOS Mrp Production",
> -	"version" : "1.0",
> -	"author" : "DOS",
> -	"category" : "Production",
> -	"website" : "www.dos-sl.es",
> -	"description": "This module allows automates the selection of locations for production orders.",
> -	"depends" : ["dos_product_additional_info", "mrp"],
> -	"init_xml" : [],
> -	"update_xml" : ['stock_view.xml',],
> -	"active": False,
> -	"installable": True
> +    "name": "DOS Mrp Production",
> +    "version": "1.0",
> +    "author": "DOS",
> +    "category": "Production",
> +    "website": "www.dos-sl.es",
> +    "description": "This module allows automates the selection of "
> +                   "locations for production orders.",
> +    "depends": ["dos_product_additional_info", "mrp"],
> +    "data": ['stock_view.xml'],
> +    "installable": True
>  }
> -
> -
> 
> === added directory 'dos_mrp_production/models'
> === renamed file 'dos_mrp_production/mrp_procurement.py' => 'dos_mrp_production/models/mrp_procurement.py'
> --- dos_mrp_production/mrp_procurement.py	2014-06-11 10:23:47 +0000
> +++ dos_mrp_production/models/mrp_procurement.py	2014-06-19 15:55:19 +0000
> @@ -21,35 +21,39 @@
>  
>  from datetime import datetime
>  from dateutil.relativedelta import relativedelta
> -from osv import fields
> -from osv import osv
> -from tools.translate import _
> -import ir
> -import netsvc
> -import time
> -
> -class procurement_order(osv.osv):
> +from openerp.osv import orm, fields
> +from openerp.tools.translate import _
> +from . import ir
> +from . import netsvc

¿Por qué pones from .? Estos tres import son así:
from openerp.addons.base import ir
from openerp import netsvc
import time

> +from . import time
> +
> +
> +class procuremenOrder(orm.Model):
>  
>      _inherit = 'procurement.order'
> - 
> +
>      def make_mo(self, cr, uid, ids, context=None):
>          """ Make Manufacturing(production) order from procurement
> -        @return: New created Production Orders procurement wise 
> +        @return: New created Production Orders procurement wise
>          """
>          res = {}
> -        company = self.pool.get('res.users').browse(cr, uid, uid, context).company_id
> -        production_obj = self.pool.get('mrp.production')
> -        move_obj = self.pool.get('stock.move')
> +        company = self.pool['res.users'].browse(cr, uid, uid,
> +                                                context).company_id
> +        production_obj = self.pool['mrp.production']
> +        move_obj = self.pool['stock.move']
>          wf_service = netsvc.LocalService("workflow")
> -        procurement_obj = self.pool.get('procurement.order')
> -        for procurement in procurement_obj.browse(cr, uid, ids, context=context):
> +        procurement_obj = self.pool['procurement.order']
> +        for procurement in procurement_obj.browse(cr, uid, ids,
> +                                                  context=context):
>              res_id = procurement.move_id.id
>              loc_id = procurement.location_id.id
> -            newdate = datetime.strptime(procurement.date_planned, '%Y-%m-%d %H:%M:%S') - relativedelta(days=procurement.product_id.product_tmpl_id.produce_delay or 0.0)
> +            tmpl_delay = procurement.product_id.product_tmpl_id.produce_delay
> +            newdate = (datetime.strptime(procurement.date_planned,
> +                                         '%Y-%m-%d %H:%M:%S') -
> +                       relativedelta(days=tmpl_delay or 0.0))
>              newdate = newdate - relativedelta(days=company.manufacturing_lead)
> -            
> -            #Si el producto esta marcado como producción unitaria
> -            #Creamos tantas ordenes de producción como cantidad a produccir
> +            #  Si el producto esta marcado como producción unitaria
> +            #  Creamos tantas ordenes de producción como cantidad a produccir
>              if procurement.product_id.unitary_prod_order:
>                  produce_ids = []
>                  for i in range(0, int(procurement.product_qty)):
> @@ -58,55 +62,60 @@
>                          'product_id': procurement.product_id.id,
>                          'product_qty': 1,
>                          'product_uom': procurement.product_uom.id,
> -                        'product_uos_qty': procurement.product_uos and procurement.product_uos_qty or False,
> -                        'product_uos': procurement.product_uos and procurement.product_uos.id or False,
> +                        'product_uos_qty': (procurement.product_uos and
> +                                            procurement.product_uos_qty
> +                                            or False),
> +                        'product_uos': (procurement.product_uos and
> +                                        procurement.product_uos.id or False),
>                          'location_src_id': procurement.location_id.id,
>                          'location_dest_id': procurement.location_id.id,
> -                        'bom_id': procurement.bom_id and procurement.bom_id.id or False,
> +                        'bom_id': (procurement.bom_id and procurement.bom_id.id
> +                                   or False),
>                          'date_planned': newdate.strftime('%Y-%m-%d %H:%M:%S'),
>                          'move_prod_id': res_id,
>                          'company_id': procurement.company_id.id,
>                      })
> -                    
>                      produce_ids.append(produce_id)
> -                    
>                  self.write(cr, uid, [procurement.id], {'state': 'running'})
> +                props = [x.id for x in procurement.property_ids]
>                  bom_result = production_obj.action_compute(cr, uid,
> -                        produce_ids, properties=[x.id for x in procurement.property_ids])
> -                
> +                                                           produce_ids,
> +                                                           properties=props)
>                  for produce_id in produce_ids:
> -                    wf_service.trg_validate(uid, 'mrp.production', produce_id, 'button_confirm', cr)
> +                    wf_service.trg_validate(uid, 'mrp.production', produce_id,
> +                                            'button_confirm', cr)
>                      res[procurement.id] = produce_id
> -                    
>                  move_obj.write(cr, uid, [res_id],
> -                        {'location_id': procurement.location_id.id})
> -                
> -            #Caso normal
> +                               {'location_id': procurement.location_id.id})
> +            #  Caso normal
>              else:
>                  produce_id = production_obj.create(cr, uid, {
>                      'origin': procurement.origin,
>                      'product_id': procurement.product_id.id,
>                      'product_qty': procurement.product_qty,
>                      'product_uom': procurement.product_uom.id,
> -                    'product_uos_qty': procurement.product_uos and procurement.product_uos_qty or False,
> -                    'product_uos': procurement.product_uos and procurement.product_uos.id or False,
> +                    'product_uos_qty': (procurement.product_uos and
> +                                        procurement.product_uos_qty or False),
> +                    'product_uos': (procurement.product_uos and
> +                                    procurement.product_uos.id or False),
>                      'location_src_id': procurement.location_id.id,
>                      'location_dest_id': procurement.location_id.id,
> -                    'bom_id': procurement.bom_id and procurement.bom_id.id or False,
> +                    'bom_id': (procurement.bom_id and procurement.bom_id.id
> +                               or False),
>                      'date_planned': newdate.strftime('%Y-%m-%d %H:%M:%S'),
>                      'move_prod_id': res_id,
>                      'company_id': procurement.company_id.id,
>                  })
>                  res[procurement.id] = produce_id
>                  self.write(cr, uid, [procurement.id], {'state': 'running'})
> +                props = [x.id for x in procurement.property_ids]
>                  bom_result = production_obj.action_compute(cr, uid,
> -                        [produce_id], properties=[x.id for x in procurement.property_ids])
> -                wf_service.trg_validate(uid, 'mrp.production', produce_id, 'button_confirm', cr)
> +                                                           [produce_id],
> +                                                           properties=props)
> +                wf_service.trg_validate(uid, 'mrp.production', produce_id,
> +                                        'button_confirm', cr)
>                  move_obj.write(cr, uid, [res_id],
> -                        {'location_id': procurement.location_id.id})
> -                
> +                               {'location_id': procurement.location_id.id})

propagar context

>          return res
> -    
> -procurement_order()
>  
>  # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
> 
> === renamed file 'dos_mrp_production/mrp_production.py' => 'dos_mrp_production/models/mrp_production.py'
> --- dos_mrp_production/mrp_production.py	2014-06-11 10:23:47 +0000
> +++ dos_mrp_production/models/mrp_production.py	2014-06-19 15:55:19 +0000
> @@ -19,110 +19,104 @@
>  #
>  ##############################################################################
>  
> -from osv import osv, fields
> -from tools.translate import _
> -import netsvc
> -import time
> -import tools
> -
> -class mrp_production(osv.osv): 
> -
> +from openerp.osv import orm, fields
> +from openerp.tools.translate import _
> +from . import netsvc

Idem de la importación

> +from . import time
> +from . import tools
> +
> +
> +class MrpProduction(orm.Model):
>      _name = 'mrp.production'
>      _inherit = 'mrp.production'
> -    
> +
>      def product_id_change(self, cr, uid, ids, product_id, context=None):
> -    	
> -    	value = {}
> +        value = {}
>          location_src_id = False
>          location_dest_id = False
> -        
> -    	#Llamamos a la funcion on_change por defecto de product_id
> -    	result = super(mrp_production, self).product_id_change(cr, uid, ids, product_id, context=None)
> -    	
> -    	if result and result.has_key('value'):
> -    		value = result['value']
> -            
> +        # Llamamos a la funcion on_change por defecto de product_id
> +        result = super(MrpProduction, self).product_id_change(cr, uid, ids,
> +                                                              product_id,
> +                                                              context=None)
> +        if result and 'value' in result:
> +            value = result['value']
>          if product_id:
> -            bom_obj = self.pool.get('mrp.bom')
> -            product = self.pool.get('product.product').browse(cr, uid, product_id, context=context)
> -            bom_id = bom_obj._bom_find(cr, uid, product.id, product.uom_id and product.uom_id.id, [])
> +            bom_obj = self.pool['mrp.bom']
> +            product = self.pool['product.product'].browse(cr, uid,
> +                                                              product_id,

Indentación incorrecta

> +                                                              context=context)
> +            bom_id = bom_obj._bom_find(cr, uid, product.id, product.uom_id and
> +                                       product.uom_id.id, [])
>              routing_id = False
>              if bom_id:
>                  bom_point = bom_obj.browse(cr, uid, bom_id, context=context)
>                  for bom_line in bom_point.bom_lines:
> +                    prod = bom_line.product_id
>                      if not location_src_id:
> -                        location_src_id = bom_line.product_id and bom_line.product_id.property_stock_consumer_product and bom_line.product_id.property_stock_consumer_product.id or False
> -                    
> +                        consum_prod = (prod and
> +                                       prod.property_stock_consumer_product)
> +                        location_src_id = (consum_prod and consum_prod.id
> +                                           or False)
>                      if not location_dest_id:
> -                        location_dest_id = bom_line.product_id and bom_line.product_id.property_stock_finished_product and bom_line.product_id.property_stock_finished_product.id or False
> -     
> +                        finish_prod = (prod and
> +                                       prod.property_stock_finished_product)
> +                        location_dest_id = (finish_prod and finish_prod.id
> +                                            or False)
>                      if location_src_id and location_dest_id:
>                          break
> -        
>          value['location_src_id'] = location_src_id
> -        value['location_dest_id'] = location_dest_id      
> -          
> -    	return {'value': value}
> -    	
> +        value['location_dest_id'] = location_dest_id
> +        return {'value': value}
> +
>      def bom_id_change(self, cr, uid, ids, bom_id, context=None):
> -    	
>          value = {}
>          location_src_id = False
>          location_dest_id = False
> -        
> -        #Llamamos a la funcion on_change por defecto de product_id
> -        result = super(mrp_production, self).bom_id_change(cr, uid, ids, bom_id, context=None)
> -        
> -        if result and result.has_key('value'):
> +        # Llamamos a la funcion on_change por defecto de product_id
> +        result = super(MrpProduction, self).bom_id_change(cr, uid, ids, bom_id,
> +                                                          context=None)
> +        if result and 'value' in result:
>              value = result['value']
> -            
>          if bom_id:
> -            bom_obj = self.pool.get('mrp.bom')
> +            bom_obj = self.pool['mrp.bom']
>              bom_point = bom_obj.browse(cr, uid, bom_id, context=context)
> -
>              for bom_line in bom_point.bom_lines:
> +                prod = bom_line.product_id
>                  if not location_src_id:
> -                    location_src_id = bom_line.product_id and bom_line.product_id.property_stock_consumer_product and bom_line.product_id.property_stock_consumer_product.id or False
> -                
> +                    consum_prod = prod and prod.property_stock_consumer_product
> +                    location_src_id = (consum_prod and consum_prod.id or False)
>                  if not location_dest_id:
> -                    location_dest_id = bom_line.product_id and bom_line.product_id.property_stock_finished_product and bom_line.product_id.property_stock_finished_product.id or False
> - 
> +                    finish_prod = prod and prod.property_stock_finished_product
> +                    location_dest_id = (finish_prod and finish_prod.id
> +                                        or False)
>                  if location_src_id and location_dest_id:
>                      break
> -        
>          value['location_src_id'] = location_src_id
> -        value['location_dest_id'] = location_dest_id       
> -          
> +        value['location_dest_id'] = location_dest_id
>          return {'value': value}
>  
> -
> -    def action_produce(self, cr, uid, production_id, production_qty, production_mode, context=None):
> -        
> -        product_obj = self.pool.get('product.product')
> -        stock_mov_obj = self.pool.get('stock.move')
> -        prodlot_obj = self.pool.get('stock.production.lot')
> -        
> +    def action_produce(self, cr, uid, production_id, production_qty,
> +                       production_mode, context=None):
> +        product_obj = self.pool['product.product']
> +        stock_mov_obj = self.pool['stock.move']
> +        prodlot_obj = self.pool['stock.production.lot']
>          link_prodlot = False
>          sim_prodlot = False
>          pack_prodlot_id = False
>          pack_description = ''
> -        
>          production = self.browse(cr, uid, production_id, context=context)
> -        
>          # Identificamos los productos a consumir de tipo SIM y ENLACE
>          for move_line in production.move_lines + production.move_lines2:
>              if move_line.prodlot_id:
>                  if product_obj._is_sim(move_line.product_id.categ_id):
>                      sim_prodlot = move_line.prodlot_id
> -                    
>                  elif product_obj._is_link(move_line.product_id.categ_id):
>                      link_prodlot = move_line.prodlot_id
> -
>          # Creamos lotes de producción (si no lo estan ya)
>          # para los productos finalizados de tipo pack
>          for move_created in production.move_created_ids:
> -            if product_obj._is_pack(move_created.product_id.categ_id) and sim_prodlot and link_prodlot:
> -
> +            if (product_obj._is_pack(move_created.product_id.categ_id)
> +                    and sim_prodlot and link_prodlot):
>                  pack_description = move_created.name
>                  if move_created.prodlot_id:
>                      # Si tiene lote de produccion asignada
> @@ -130,46 +124,55 @@
>                  else:
>                      # Si no tiene lote de produccion, creamos uno nuevo
>                      # y lo asignamos al movimiento
> -                    pack_prodlot_id = prodlot_obj.search(cr, uid, [('name', '=', link_prodlot.name), ('ref', '=', sim_prodlot.telefono)])
> +                    lot_name_ref = [('name', '=', link_prodlot.name),
> +                                    ('ref', '=', sim_prodlot.telefono)]
> +                    pack_prodlot_id = prodlot_obj.search(cr, uid, lot_name_ref,
> +                                                         context=context)
>                      if pack_prodlot_id:
>                          pack_prodlot_id = pack_prodlot_id[0]
>                      else:
> -                        pack_prodlot_id = prodlot_obj.create(cr, uid, { 'product_id': move_created.product_id.id, })
> -
> -                    stock_mov_obj.write(cr, uid, [move_created.id], {'prodlot_id': pack_prodlot_id}, context={})
> -
> +                        prod_info = {'product_id': move_created.product_id.id}
> +                        pack_prodlot_id = prodlot_obj.create(cr, uid, prod_info
> +                                                             )
> +                    stock_mov_obj.write(cr, uid, [move_created.id],
> +                                        {'prodlot_id': pack_prodlot_id},
> +                                        context={})
>                  break
> -
> -
>          if sim_prodlot and link_prodlot and pack_prodlot_id:
> -            
>              # Rellenamos información adicional en el lote del pack
> -            prodlot_obj.write(cr, uid, [pack_prodlot_id], {'name': link_prodlot.name,
> -                                                           'descripcion': pack_description,
> -                                                           'icc': sim_prodlot.icc,
> -                                                           'telefono': sim_prodlot.telefono,
> -                                                           'pin': sim_prodlot.pin,
> -                                                           'puk': sim_prodlot.puk,
> -                                                           'operador': sim_prodlot.operador,
> -                                                           'imei': link_prodlot.imei,
> -                                                           'n_serie': link_prodlot.n_serie,
> -                                                           'tipo_enlace': link_prodlot.tipo_enlace,
> -                                                           'propietario': link_prodlot.propietario,
> -                                                           'precio': link_prodlot.precio,
> -                                                           'precio_subvencionado': link_prodlot.precio_subvencionado,                                                          
> -                                                           'ref_cliente': sim_prodlot.ref_cliente,
> -                                                           'fecha_alta': time.strftime('%Y-%m-%d'),
> -                                                           #'observaciones': sim_prodlot.observaciones,
> -                                                           #'albaran_entrada': sim_prodlot.albaran_entrada,
> -                                                           #'fecha_compra': link_prodlot.fecha_compra,
> -                                                           #'fecha_activacion': sim_prodlot.fecha_activacion,
> -                                                        }, context={})
> -            
> +            subsidy_price = link_prodlot.precio_subvencionado
> +            prodlot_obj.write(cr, uid, [pack_prodlot_id],
> +                              {'name': link_prodlot.name,
> +                               'descripcion': pack_description,
> +                               'icc': sim_prodlot.icc,
> +                               'telefono': sim_prodlot.telefono,
> +                               'pin': sim_prodlot.pin,
> +                               'puk': sim_prodlot.puk,
> +                               'operador': sim_prodlot.operador,
> +                               'imei': link_prodlot.imei,
> +                               'n_serie': link_prodlot.n_serie,
> +                               'tipo_enlace': link_prodlot.tipo_enlace,
> +                               'propietario': link_prodlot.propietario,
> +                               'precio': link_prodlot.precio,
> +                               'precio_subvencionado': subsidy_price,
> +                               'ref_cliente': sim_prodlot.ref_cliente,
> +                               'fecha_alta': time.strftime('%Y-%m-%d'),
> +                               # 'observaciones':
> +                               # sim_prodlot.observaciones,
> +                               # 'albaran_entrada':
> +                               # sim_prodlot.albaran_entrada,
> +                               # 'fecha_compra':
> +                               # link_prodlot.fecha_compra,
> +                               # 'fecha_activacion':
> +                               # sim_prodlot.fecha_activacion,
> +                               }, context={})
>          else:
> -            raise osv.except_osv(_('No production lots !'), _('Must assign production lots to consume products !'))
> -        
> -        #Llamamos a la funcion super de action_produce
> -        return super(mrp_production, self).action_produce(cr, uid, production_id, production_qty, production_mode, context=None)
> -        
> -        
> -mrp_production()
> +            raise orm.except_orm(_('No production lots !'),
> +                                 _('Must assign production lots'
> +                                   ' to consume products !'))
> +        #  Llamamos a la funcion super de action_produce
> +        return super(MrpProduction, self).action_produce(cr, uid,
> +                                                         production_id,
> +                                                         production_qty,
> +                                                         production_mode,
> +                                                         context=None)
> 
> === added directory 'dos_mrp_production/views'
> === renamed file 'dos_mrp_production/stock_view.xml' => 'dos_mrp_production/views/stock_view.xml'
> --- dos_mrp_production/stock_view.xml	2014-06-11 10:23:47 +0000
> +++ dos_mrp_production/views/stock_view.xml	2014-06-19 15:55:19 +0000
> @@ -5,7 +5,6 @@
>              <field name="name">stock.move.form.inherit</field>
>              <field name="model">stock.move</field>
>              <field name="inherit_id" ref="stock.view_move_form"/>
> -            <field name="type">form</field>
>              <field name="priority">1</field>
>              <field name="arch" type="xml">
>                  <field name="prodlot_id" position="replace">
> 


-- 
https://code.launchpad.net/~mikelarregi/avanzosc/dos_mrp_production/+merge/223764
Your team Avanzosc_security is subscribed to branch lp:~avanzosc-security-team/avanzosc/72horas.


References