2010-11-11 21:58:22 +00:00
|
|
|
|
2010-03-26 09:25:02 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# OpenERP, Open Source Management Solution
|
|
|
|
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
|
|
|
#
|
|
|
|
# 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/>.
|
|
|
|
#
|
|
|
|
##############################################################################
|
2010-08-04 11:07:44 +00:00
|
|
|
|
2010-03-26 09:25:02 +00:00
|
|
|
from osv import fields, osv
|
|
|
|
from tools.translate import _
|
|
|
|
import time
|
|
|
|
|
|
|
|
class stock_partial_picking(osv.osv_memory):
|
|
|
|
_name = "stock.partial.picking"
|
|
|
|
_description = "Partial Picking"
|
|
|
|
_columns = {
|
2010-08-13 12:20:05 +00:00
|
|
|
'date': fields.datetime('Date', required=True),
|
2010-11-11 21:58:22 +00:00
|
|
|
'product_moves_out' : fields.one2many('stock.move.memory.out', 'wizard_id', 'Moves'),
|
|
|
|
'product_moves_in' : fields.one2many('stock.move.memory.in', 'wizard_id', 'Moves'),
|
2010-03-26 09:25:02 +00:00
|
|
|
}
|
2010-11-11 21:58:22 +00:00
|
|
|
|
|
|
|
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')
|
2010-12-23 10:21:04 +00:00
|
|
|
pick_ids = pick_obj.search(cr, uid, [('id','in',pick_ids)])
|
|
|
|
|
2010-11-11 21:58:22 +00:00
|
|
|
|
2010-12-23 10:21:04 +00:00
|
|
|
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
|
2010-11-11 21:58:22 +00:00
|
|
|
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"
|
2010-03-26 09:25:02 +00:00
|
|
|
|
|
|
|
def view_init(self, cr, uid, fields_list, context=None):
|
|
|
|
res = super(stock_partial_picking, self).view_init(cr, uid, fields_list, context=context)
|
2010-06-21 18:40:58 +00:00
|
|
|
return res
|
2010-03-26 09:25:02 +00:00
|
|
|
|
|
|
|
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False,submenu=False):
|
2010-06-21 18:40:58 +00:00
|
|
|
result = super(stock_partial_picking, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar,submenu)
|
2010-11-11 21:58:22 +00:00
|
|
|
|
|
|
|
|
2010-06-21 18:40:58 +00:00
|
|
|
picking_ids = context.get('active_ids', False)
|
2010-11-11 21:58:22 +00:00
|
|
|
picking_type = self.__get_picking_type(cr, uid, picking_ids)
|
|
|
|
|
2010-10-17 11:59:01 +00:00
|
|
|
_moves_arch_lst = """<form string="%s">
|
|
|
|
<field name="date" invisible="1"/>
|
|
|
|
<separator colspan="4" string="%s"/>
|
2010-11-11 21:58:22 +00:00
|
|
|
<field name="%s" colspan="4" nolabel="1" mode="tree,form" width="550" height="200" ></field>
|
|
|
|
""" % (_('Process Document'), _('Products'), picking_type)
|
2010-03-26 14:52:01 +00:00
|
|
|
_moves_fields = result['fields']
|
2010-11-11 21:58:22 +00:00
|
|
|
_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'}
|
|
|
|
})
|
|
|
|
|
2010-03-26 14:52:01 +00:00
|
|
|
_moves_arch_lst += """
|
|
|
|
<separator string="" colspan="4" />
|
|
|
|
<label string="" colspan="2"/>
|
|
|
|
<group col="2" colspan="2">
|
2010-06-21 18:40:58 +00:00
|
|
|
<button icon='gtk-cancel' special="cancel"
|
|
|
|
string="_Cancel" />
|
|
|
|
<button name="do_partial" string="_Validate"
|
2010-10-25 12:02:21 +00:00
|
|
|
colspan="1" type="object" icon="gtk-go-forward" />
|
2010-06-21 18:40:58 +00:00
|
|
|
</group>
|
2010-03-26 14:52:01 +00:00
|
|
|
</form>"""
|
|
|
|
result['arch'] = _moves_arch_lst
|
2010-06-21 18:40:58 +00:00
|
|
|
result['fields'] = _moves_fields
|
2010-03-26 09:25:02 +00:00
|
|
|
return result
|
|
|
|
|
2010-11-11 21:58:22 +00:00
|
|
|
def __create_partial_picking_memory(self, picking, is_in):
|
|
|
|
move_memory = {
|
|
|
|
'product_id' : picking.product_id.id,
|
|
|
|
'quantity' : picking.product_qty,
|
|
|
|
'product_uom' : picking.product_uom.id,
|
|
|
|
'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.currency_id.id,
|
|
|
|
})
|
|
|
|
return move_memory
|
|
|
|
|
|
|
|
def __get_active_stock_pickings(self, cr, uid, context=None):
|
2010-06-21 18:40:58 +00:00
|
|
|
pick_obj = self.pool.get('stock.picking')
|
2010-03-26 09:25:02 +00:00
|
|
|
if not context:
|
2010-11-11 21:58:22 +00:00
|
|
|
context = {}
|
|
|
|
|
|
|
|
res = []
|
|
|
|
for pick in pick_obj.browse(cr, uid, context.get('active_ids', []), context):
|
2010-10-14 00:40:47 +00:00
|
|
|
need_product_cost = (pick.type == 'in')
|
2010-03-26 09:25:02 +00:00
|
|
|
for m in pick.move_lines:
|
|
|
|
if m.state in ('done', 'cancel'):
|
2010-11-11 21:58:22 +00:00
|
|
|
continue
|
|
|
|
res.append(self.__create_partial_picking_memory(m, need_product_cost))
|
|
|
|
|
2010-06-21 18:40:58 +00:00
|
|
|
return res
|
2010-11-11 21:58:22 +00:00
|
|
|
|
|
|
|
_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'),
|
|
|
|
}
|
|
|
|
|
2010-03-26 09:25:02 +00:00
|
|
|
|
2010-11-22 10:37:53 +00:00
|
|
|
def do_partial(self, cr, uid, ids, context=None):
|
2010-05-26 12:59:30 +00:00
|
|
|
""" 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
|
2010-06-21 18:40:58 +00:00
|
|
|
@param fields: List of fields for which we want default values
|
|
|
|
@param context: A standard dictionary
|
|
|
|
@return: A dictionary which of fields with values.
|
|
|
|
"""
|
|
|
|
pick_obj = self.pool.get('stock.picking')
|
2010-03-26 09:25:02 +00:00
|
|
|
picking_ids = context.get('active_ids', False)
|
2010-11-22 10:37:53 +00:00
|
|
|
partial = self.browse(cr, uid, ids[0], context=context)
|
2010-03-26 09:25:02 +00:00
|
|
|
partial_datas = {
|
2010-06-21 18:40:58 +00:00
|
|
|
'delivery_date' : partial.date
|
2010-03-26 09:25:02 +00:00
|
|
|
}
|
2010-12-22 15:00:33 +00:00
|
|
|
|
2010-11-22 10:37:53 +00:00
|
|
|
for pick in pick_obj.browse(cr, uid, picking_ids, context=context):
|
2010-10-14 00:40:47 +00:00
|
|
|
need_product_cost = (pick.type == 'in')
|
2010-11-11 21:58:22 +00:00
|
|
|
moves_list = need_product_cost and partial.product_moves_in or partial.product_moves_out
|
|
|
|
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'):
|
2010-03-26 09:25:02 +00:00
|
|
|
continue
|
2010-11-11 21:58:22 +00:00
|
|
|
if not p_moves.get(move.id):
|
|
|
|
continue
|
|
|
|
|
|
|
|
partial_datas['move%s' % (move.id)] = {
|
2010-12-23 10:21:04 +00:00
|
|
|
'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,
|
2010-03-26 09:25:02 +00:00
|
|
|
}
|
2010-11-11 21:58:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
})
|
2010-10-14 00:40:47 +00:00
|
|
|
pick_obj.do_partial(cr, uid, picking_ids, partial_datas, context=context)
|
2010-12-28 10:41:38 +00:00
|
|
|
return {'type': 'ir.actions.act_window_close'}
|
2010-06-21 18:40:58 +00:00
|
|
|
|
2010-11-11 21:58:22 +00:00
|
|
|
|
|
|
|
|
2010-06-21 18:40:58 +00:00
|
|
|
|
|
|
|
stock_partial_picking()
|
2010-03-26 09:25:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
|
|
|