openerp-dev-web team mailing list archive
-
openerp-dev-web team
-
Mailing list archive
-
Message #02333
lp:~openerp-dev/openobject-addons/xmo-reformat-cleanup-partial-pickings into lp:openobject-addons
Xavier (Open ERP) has proposed merging lp:~openerp-dev/openobject-addons/xmo-reformat-cleanup-partial-pickings into lp:openobject-addons.
Requested reviews:
OpenERP R&D Addons Team 2 (openerp-dev-addons2)
For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/xmo-reformat-cleanup-partial-pickings/+merge/46147
Some code reformatting and cleanups (as well as a pair of fixes to context usages) for the partial pickings object.
--
https://code.launchpad.net/~openerp-dev/openobject-addons/xmo-reformat-cleanup-partial-pickings/+merge/46147
Your team OpenERP R&D Team is subscribed to branch lp:~openerp-dev/openobject-addons/xmo-reformat-cleanup-partial-pickings.
=== modified file 'stock/wizard/stock_partial_picking.py'
--- stock/wizard/stock_partial_picking.py 2011-01-10 14:09:49 +0000
+++ stock/wizard/stock_partial_picking.py 2011-01-13 16:42:36 +0000
@@ -1,4 +1,3 @@
-
# -*- coding: utf-8 -*-
##############################################################################
#
@@ -32,64 +31,70 @@
'product_moves_out' : fields.one2many('stock.move.memory.out', 'wizard_id', 'Moves'),
'product_moves_in' : fields.one2many('stock.move.memory.in', 'wizard_id', 'Moves'),
}
-
+
+ _defaults = {
+ 'product_moves_in' : __get_active_stock_pickings,
+ 'product_moves_out' : __get_active_stock_pickings,
+ 'date' : lambda *a : time.strftime('%Y-%m-%d %H:%M:%S'),
+ }
+
+
def __is_in(self,cr, uid, pick_ids):
"""
@return: True if one of the moves has as picking type 'in'
"""
if not pick_ids:
return False
-
+
pick_obj = self.pool.get('stock.picking')
pick_ids = pick_obj.search(cr, uid, [('id','in',pick_ids)])
-
-
+
for pick in pick_obj.browse(cr, uid, pick_ids):
for move in pick.move_lines:
if pick.type == 'in' and move.product_id.cost_method == 'average':
return True
return False
-
+
def __get_picking_type(self, cr, uid, pick_ids):
if self.__is_in(cr, uid, pick_ids):
return "product_moves_in"
else:
return "product_moves_out"
- def view_init(self, cr, uid, fields_list, context=None):
- res = super(stock_partial_picking, self).view_init(cr, uid, fields_list, context=context)
- return res
-
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False,submenu=False):
- result = super(stock_partial_picking, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar,submenu)
-
-
+ result = super(stock_partial_picking, self).fields_view_get(
+ cr, uid, view_id, view_type, context, toolbar,submenu)
+
picking_ids = context.get('active_ids', False)
picking_type = self.__get_picking_type(cr, uid, picking_ids)
-
- _moves_arch_lst = """<form string="%s">
- <field name="date" invisible="1"/>
- <separator colspan="4" string="%s"/>
- <field name="%s" colspan="4" nolabel="1" mode="tree,form" width="550" height="200" ></field>
- """ % (_('Process Document'), _('Products'), picking_type)
- _moves_fields = result['fields']
- _moves_fields.update({
- 'product_moves_in' : {'relation': 'stock.move.memory.in', 'type' : 'one2many', 'string' : 'Product Moves'},
- 'product_moves_out' : {'relation': 'stock.move.memory.out', 'type' : 'one2many', 'string' : 'Product Moves'}
- })
-
- _moves_arch_lst += """
+
+ result['fields'].update(
+ product_moves_in={
+ 'relation': 'stock.move.memory.in',
+ 'string': 'Product Moves',
+ 'type': 'one2many'},
+ product_moves_out={
+ 'relation': 'stock.move.memory.out',
+ 'string': 'Product Moves',
+ 'type': 'one2many'})
+
+ result['arch'] = '''
+ <form string="%s">
+ <field name="date" invisible="1"/>
+ <separator colspan="4" string="%s"/>
+ <field name="%s" colspan="4" nolabel="1" mode="tree,form"
+ width="550" height="200" ></field>
<separator string="" colspan="4" />
<label string="" colspan="2"/>
<group col="2" colspan="2">
- <button icon='gtk-cancel' special="cancel"
- string="_Cancel" />
- <button name="do_partial" string="_Validate"
- colspan="1" type="object" icon="gtk-go-forward" />
- </group>
- </form>"""
- result['arch'] = _moves_arch_lst
- result['fields'] = _moves_fields
+ <button icon="gtk-cancel" special="cancel"
+ string="_Cancel" />
+ <button name="do_partial" string="_Validate"
+ colspan="1" type="object" icon="gtk-go-forward" />
+ </group>
+ </form>
+ ''' % (_('Process Document'), _('Products'), picking_type)
+
return result
def __create_partial_picking_memory(self, picking, is_in):
@@ -100,45 +105,32 @@
'prodlot_id' : picking.prodlot_id.id,
'move_id' : picking.id,
}
-
+
if is_in:
- move_memory.update({
- 'cost' : picking.product_id.standard_price,
- 'currency' : picking.product_id.company_id and picking.product_id.company_id.currency_id and picking.product_id.company_id.currency_id.id or False,
- })
+ move_memory.update(
+ cost=picking.product_id.standard_price,
+ currency=picking.product_id.company_id and picking.product_id.company_id.currency_id and picking.product_id.company_id.currency_id.id or False,
+ )
return move_memory
def __get_active_stock_pickings(self, cr, uid, context=None):
pick_obj = self.pool.get('stock.picking')
- if not context:
+ if context is None:
context = {}
-
+
res = []
for pick in pick_obj.browse(cr, uid, context.get('active_ids', []), context):
need_product_cost = (pick.type == 'in')
for m in pick.move_lines:
if m.state in ('done', 'cancel'):
- continue
+ continue
res.append(self.__create_partial_picking_memory(m, need_product_cost))
-
return res
-
- _defaults = {
- 'product_moves_in' : __get_active_stock_pickings,
- 'product_moves_out' : __get_active_stock_pickings,
- 'date' : lambda *a : time.strftime('%Y-%m-%d %H:%M:%S'),
- }
-
def do_partial(self, cr, uid, ids, context=None):
""" Makes partial moves and pickings done.
- @param self: The object pointer.
- @param cr: A database cursor
- @param uid: ID of the user currently logged in
- @param fields: List of fields for which we want default values
- @param context: A standard dictionary
- @return: A dictionary which of fields with values.
"""
+ if context is None: context = {}
pick_obj = self.pool.get('stock.picking')
picking_ids = context.get('active_ids', False)
partial = self.browse(cr, uid, ids[0], context=context)
@@ -152,35 +144,24 @@
p_moves = {}
for product_move in moves_list:
p_moves[product_move.move_id.id] = product_move
-
-
+
for move in pick.move_lines:
- if move.state in ('done', 'cancel'):
- continue
- if not p_moves.get(move.id):
- continue
-
+ if move.state in ('done', 'cancel')\
+ or not p_moves.get(move.id):
+ continue
+
partial_datas['move%s' % (move.id)] = {
'product_id' : p_moves[move.id].id,
'product_qty' : p_moves[move.id].quantity,
'product_uom' :p_moves[move.id].product_uom.id,
'prodlot_id' : p_moves[move.id].prodlot_id.id,
}
-
-
+
if (move.picking_id.type == 'in') and (move.product_id.cost_method == 'average'):
- partial_datas['move%s' % (move.id)].update({
- 'product_price' : p_moves[move.id].cost,
- 'product_currency': p_moves[move.id].currency.id,
- })
+ partial_datas['move%s' % (move.id)].update(
+ product_price=p_moves[move.id].cost,
+ product_currency=p_moves[move.id].currency.id,
+ )
pick_obj.do_partial(cr, uid, picking_ids, partial_datas, context=context)
return {'type': 'ir.actions.act_window_close'}
-
-
-
-
stock_partial_picking()
-
-
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
-
Follow ups