← Back to team overview

avanzosc team mailing list archive

Re: [Merge] lp:~oihanecruce/avanzosc/nayar_stock_picking_multiple into lp:~avanzosc-security-team/avanzosc/72horas

 

Review: Needs Fixing code review

Dos cosillas más y listo.

Un saludo.

Diff comments:

> === modified file 'nayar_stock_picking_multiple/__init__.py'
> --- nayar_stock_picking_multiple/__init__.py	2014-06-11 10:23:47 +0000
> +++ nayar_stock_picking_multiple/__init__.py	2014-07-03 11:55:39 +0000
> @@ -19,8 +19,5 @@
>  #
>  ##############################################################################
>  
> -import stock
> -import wizard
> -
> -
> -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
> +from . import models
> +from . import wizard
> 
> === modified file 'nayar_stock_picking_multiple/__openerp__.py'
> --- nayar_stock_picking_multiple/__openerp__.py	2014-06-11 10:23:47 +0000
> +++ nayar_stock_picking_multiple/__openerp__.py	2014-07-03 11:55:39 +0000
> @@ -19,20 +19,23 @@
>  #
>  ##############################################################################
>  
> -
>  {
> -    "name" : "Salida multiple",
> -    "version" : "1.0",
> -    "author" : "Nayar Systems",
> -    "category" : "Enterprise Specific Modules",
> -    "website" : "www.72horas.net",
> -    "description": "Selección múltiple de lotes de producción para albaranes de salida",
> -    "depends" : ["base", "stock"],
> -    "init_xml" : [],
> -    "update_xml" : [
> -        'stock_picking_wizard.xml',
> -        'stock_picking_view.xml',
> -        ],
> +    "name": "Salida multiple",
> +    "version": "1.0",
> +    "author": "Nayar Systems",
> +    "category": "Enterprise Specific Modules",
> +    "website": "www.72horas.net",
> +    "description": """
> +    Selección múltiple de lotes de producción para albaranes de salida
> +    """,
> +    "depends": [
> +        "base",
> +        "stock",
> +    ],
> +    "data": [
> +        'wizard/stock_picking_wizard.xml',
> +        'views/stock_picking_view.xml',
> +    ],
>      "active": False,
>      "installable": True
>  }
> 
> === added directory 'nayar_stock_picking_multiple/models'
> === added file 'nayar_stock_picking_multiple/models/__init__.py'
> --- nayar_stock_picking_multiple/models/__init__.py	1970-01-01 00:00:00 +0000
> +++ nayar_stock_picking_multiple/models/__init__.py	2014-07-03 11:55:39 +0000
> @@ -0,0 +1,22 @@
> +# -*- coding: utf-8 -*-
> +##############################################################################
> +#
> +#    OpenERP, Open Source Management Solution
> +#    Copyright (C) 2013 Nayar Systems (<http://www.72horas.net/>)
> +#
> +#    This program is free software: you can redistribute it and/or modify
> +#    it under the terms of the GNU Affero 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 Affero General Public License for more details.
> +#
> +#    You should have received a copy of the GNU Affero General Public License
> +#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +#
> +##############################################################################
> +
> +from . import stock
> 
> === renamed file 'nayar_stock_picking_multiple/stock.py' => 'nayar_stock_picking_multiple/models/stock.py'
> --- nayar_stock_picking_multiple/stock.py	2014-06-11 10:23:47 +0000
> +++ nayar_stock_picking_multiple/models/stock.py	2014-07-03 11:55:39 +0000
> @@ -19,29 +19,50 @@
>  #
>  ##############################################################################
>  
> -from osv import osv, fields
> -
> -
> -class stock_production_lot(osv.osv):
> +from openerp.osv import orm, fields
> +
> +
> +class StockProductionLot(orm.Model):
>      _inherit = 'stock.production.lot'
>  
>      def _get_contract_id(self, cr, uid, ids, field_name, arg, context=None):
>          res = {}
>          for id in ids:
> -            cr.execute("SELECT contract_id FROM contract_annexe WHERE production_lot_id = %s OR production_lot_2_id = %s OR pack_production_lot_id = %s", (id, id, id))
> -            contract = cr.fetchone()
> -            res[id] = (contract and contract[0]) or False
> +            annexe_obj = self.pool['contract_annexe']
> +
> +            annexe_ids = annexe_obj.search(
> +                cr, uid, ['|', ['production_lot_id', '=', id],

Se suelen utilizar tuplas en lugar de listas en los dominios por su inmutabilidad, aunque creo que en este caso no fallaría.

> +                          '|', ['production_lot_2_id', '=', id],
> +                          ['pack_production_lot_id', '=', id]],
> +                context=context)
> +
> +            contract_id = annexe_obj.read(cr, uid, annexe_ids, ['contract_id'],

Llama mejor contract a la variable

> +                                          context=context)
> +
> +            res[id] = (contract_id and contract_id[0]['contract_id']) or False
>  
>          return res
>  
>      def _contract_search(self, cr, uid, obj, name, args, context=None):
> -        cr.execute("SELECT DISTINCT production_lot_id FROM contract_annexe WHERE contract_id " + str(args[0][1]) + str(args[0][2]) + " AND production_lot_id IS NOT NULL UNION SELECT DISTINCT production_lot_2_id FROM contract_annexe WHERE contract_id " + str(args[0][1]) + str(args[0][2]) + " AND production_lot_2_id IS NOT NULL UNION SELECT DISTINCT pack_production_lot_id FROM contract_annexe WHERE contract_id " + str(args[0][1]) + str(args[0][2]) + " AND pack_production_lot_id IS NOT NULL")
> +        args_string = str(args[0][1]) + str(args[0][2])
> +        cr.execute("SELECT DISTINCT production_lot_id "
> +                   "  FROM contract_annexe "
> +                   " WHERE contract_id %s"
> +                   "   AND production_lot_id IS NOT NULL UNION "
> +                   "    SELECT DISTINCT production_lot_2_id "
> +                   "      FROM contract_annexe "
> +                   "     WHERE contract_id %s"
> +                   "       AND production_lot_2_id IS NOT NULL UNION "
> +                   "    SELECT DISTINCT pack_production_lot_id "
> +                   "      FROM contract_annexe "
> +                   "     WHERE contract_id %s"
> +                   "       AND pack_production_lot_id IS NOT NULL",
> +                   (args_string, args_string, args_string))
>          res = cr.fetchall()
>          return [('id', 'in', map(lambda x:x[0], res))]
>  
>      _columns = {
> -        'contract_id': fields.function(_get_contract_id, fnct_search=_contract_search, method=True, type="many2one", obj="contract.contract", string="Contract"),
> -        }
> -
> -
> -stock_production_lot()
> +        'contract_id': fields.function(
> +            _get_contract_id, fnct_search=_contract_search, method=True,
> +            type="many2one", obj="contract.contract", string="Contract"),
> +    }
> 
> === added directory 'nayar_stock_picking_multiple/views'
> === renamed file 'nayar_stock_picking_multiple/stock_picking_view.xml' => 'nayar_stock_picking_multiple/views/stock_picking_view.xml'
> --- nayar_stock_picking_multiple/stock_picking_view.xml	2014-06-11 10:23:47 +0000
> +++ nayar_stock_picking_multiple/views/stock_picking_view.xml	2014-07-03 11:55:39 +0000
> @@ -1,17 +1,16 @@
>  <?xml version="1.0" encoding="utf-8"?>
>  <openerp>
> -  <data>
> -    <record id="search_product_lot_filter_description" model="ir.ui.view">
> -      <field name="name">Production Lots Filter</field>
> -      <field name="model">stock.production.lot</field>
> -      <field name="inherit_id" ref="stock.search_product_lot_filter"/>
> -      <field name="type">search</field>
> -      <field name="arch" type="xml">
> -	<field name="date" position="after">
> -	  <field name="descripcion" />
> -	  <field name="contract_id" />
> -	</field>
> -      </field>
> -    </record>
> -  </data>
> +    <data>
> +        <record id="search_product_lot_filter_description" model="ir.ui.view">
> +            <field name="name">Production Lots Filter</field>
> +            <field name="model">stock.production.lot</field>
> +            <field name="inherit_id" ref="stock.search_product_lot_filter" />
> +            <field name="arch" type="xml">
> +                <field name="date" position="after">
> +                    <field name="descripcion" />
> +                    <field name="contract_id" />
> +                </field>
> +            </field>
> +        </record>
> +    </data>
>  </openerp>
> 
> === modified file 'nayar_stock_picking_multiple/wizard/__init__.py'
> --- nayar_stock_picking_multiple/wizard/__init__.py	2014-06-11 10:23:47 +0000
> +++ nayar_stock_picking_multiple/wizard/__init__.py	2014-07-03 11:55:39 +0000
> @@ -19,7 +19,4 @@
>  #
>  ##############################################################################
>  
> -import stock_picking_multiple
> -
> -
> -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
> +from . import stock_picking_multiple
> 
> === modified file 'nayar_stock_picking_multiple/wizard/stock_picking_multiple.py'
> --- nayar_stock_picking_multiple/wizard/stock_picking_multiple.py	2014-06-11 10:23:47 +0000
> +++ nayar_stock_picking_multiple/wizard/stock_picking_multiple.py	2014-07-03 11:55:39 +0000
> @@ -19,71 +19,48 @@
>  #
>  ##############################################################################
>  
> -import wizard
> -import pooler
> -
> -
> -fields = {
> -    'lots': {'string': 'Production Lots', 'type': 'many2many', 'relation': 'stock.production.lot'},
> -    'location_id': {'string': 'Source Location', 'type': 'many2one', 'relation': 'stock.location', 'select': True, 'required': True, 'default': lambda *a: 12},
> -    'location_dest_id': {'string': 'Destination Location', 'type': 'many2one', 'relation': 'stock.location', 'select': True, 'required': True, 'default': lambda *a: 8},
> -    }
> -
> -arch = '''<?xml version="1.0" encoding="utf-8"?>
> -<form string="Search production lots">
> -  <field name="lots" colspan="4" nolabel="1" />
> -  <field name="location_id" colspan="2" />
> -  <field name="location_dest_id" colspan="2" />
> -</form>'''
> -
> -
> -def add_lots(self, cr, uid, data, context):
> -    lot_ids = data['form']['lots'][0][2]
> -    if not lot_ids:
> -        return {}
> -
> -    pool = pooler.get_pool(cr.dbname)
> -    move_obj = pool.get('stock.move')
> -    lot_obj = pool.get('stock.production.lot')
> -    picking_id = data['id']
> -    location_id = data['form']['location_id']
> -    location_dest_id = data['form']['location_dest_id']
> -
> -    for lot in lot_obj.browse(cr, uid, lot_ids, context=context):
> -        move_obj.create(cr, uid, {
> -                'picking_id': picking_id,
> -                'name': lot.product_id.name,
> -                'product_id': lot.product_id.id,
> -                'product_qty': 1,
> -                'product_uom': lot.product_id.uom_id.id,
> -                'prodlot_id': lot.id,
> -                'location_id': location_id,
> -                'location_dest_id': location_dest_id})
> -
> -    return {}
> -
> -
> -class wizard_stock_picking_multiple(wizard.interface):
> -    states = {
> -        'init': {
> -            'result': {
> -                'type': 'form',
> -                'arch': arch,
> -                'fields': fields,
> -                'state': [
> -                    ('end', '_Cancel'),
> -                    ('create', '_Add to stock picking', '', True)
> -                    ]
> -                },
> -            },
> -        'create': {
> -            'result': {
> -                'type': 'action',
> -                'action': add_lots,
> -                'state': 'end'}
> -            },
> -        }
> -
> -wizard_stock_picking_multiple('stock_picking_multiple')
> -
> -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
> +from openerp.osv import orm, fields
> +
> +
> +class WizardStockPickingMultiple(orm.TransientModel):
> +    _name = 'wizard.stock.picking.multiple'
> +
> +    _columns = {
> +        'lots': fields.many2many('stock.production.lot'
> +                                 'wiz_stock_picking_multiple_lots',
> +                                 'multiple_picking_id', 'lot_id',
> +                                 'Production Lots'),
> +        'location_id': fields.many2one('stock.location', 'Source Location',
> +                                       select=True, required=True),
> +        'location_dest_id': fields.many2one('stock.location',
> +                                            'Destination Location',
> +                                            select=True, required=True),
> +    }
> +
> +    # TODO: Erase hardcoded ids, don't know which ones to take
> +    _defaults = {
> +        'location_id': 12,
> +        'location_dest_id': 8,
> +    }
> +
> +    def add_lots(self, cr, uid, ids, context=None):
> +        if context is None:
> +            context = {}
> +
> +        for data in self.browse(cr, uid, ids, context=context):
> +            lot_obj = self.pool['stock.production.lot']
> +            move_obj = self.pool['stock.move']
> +
> +            for lot in lot_obj.browse(cr, uid, data.lot_ids, context=context):
> +                move_obj.create(
> +                    cr, uid, {'name': lot.product_id.name,
> +                              'picking_id': context['active_id'],
> +                              'product_id': lot.product_id.id,
> +                              'product_qty': 1,
> +                              'product_uom': lot.product_id.uom_id.id,
> +                              'prodlot_id': lot.id,
> +                              'location_id': data.location_id,
> +                              'location_dest_id': data.location_dest_id},
> +                    context=context)
> +
> +        return {'type': 'ir.action.close_window'}
> 
> === renamed file 'nayar_stock_picking_multiple/stock_picking_wizard.xml' => 'nayar_stock_picking_multiple/wizard/stock_picking_wizard.xml'
> --- nayar_stock_picking_multiple/stock_picking_wizard.xml	2014-06-11 10:23:47 +0000
> +++ nayar_stock_picking_multiple/wizard/stock_picking_wizard.xml	2014-07-03 11:55:39 +0000
> @@ -1,6 +1,27 @@
>  <?xml version="1.0" encoding="utf-8"?>
>  <openerp>
> -  <data>
> -    <wizard id="wizard_stock_picking_multiple" model="stock.picking" name="stock_picking_multiple" string="Select production lots" />
> -  </data>
> +    <data>
> +        <record model="ir.ui.view" id="wizard_stock_picking_multiple_view">
> +            <field name="name">stock.picking.multiple.wizard.view</field>
> +            <field name="model">wizard.stock.picking.multiple</field>
> +            <field name="arch" type="xml">
> +                <form string="Search production lots">
> +                    <field name="lots" colspan="4" nolabel="1" />
> +                    <field name="location_id" colspan="2" />
> +                    <field name="location_dest_id" colspan="2" />
> +                    <footer>
> +                        <button icon="gtk-ok" name="add_lots"
> +                            string="Add Lots" type="object" />
> +                        <button class="oe_link" special="cancel"
> +                            string="Cancel" />
> +                    </footer>
> +                </form>
> +            </field>
> +        </record>
> +
> +        <act_window id="wizard_stock_picking_multiple" name="Select production lots"
> +            res_model="wizard.stock.picking.multiple" src_model="stock.picking"
> +            key2="client_action_multi" view_id="wizard_stock_picking_multiple_view"
> +            target="new" />
> +    </data>
>  </openerp>
> 


-- 
https://code.launchpad.net/~oihanecruce/avanzosc/nayar_stock_picking_multiple/+merge/225003
Your team Avanzosc_security is subscribed to branch lp:~avanzosc-security-team/avanzosc/72horas.