[ADD]stock :split
bzr revid: nel@tinyerp.com-20100615090933-sr3xl66g4q6x7rcb
This commit is contained in:
parent
d1c455363e
commit
32e4fdd40e
|
@ -25,6 +25,17 @@ import pooler
|
|||
class stock_production_lot(osv.osv):
|
||||
_name = 'stock.production.lot'
|
||||
_inherit = 'stock.production.lot'
|
||||
def name_get(self, cr, uid, ids, context=None):
|
||||
if not len(ids):
|
||||
return []
|
||||
result = []
|
||||
for line in self.browse(cr, uid, ids, context):
|
||||
if line.life_date:
|
||||
result.append((line.id, (line.name or '')+' ('+line.life_date+')'))
|
||||
else:
|
||||
result.append((line.id, line.name))
|
||||
return result
|
||||
|
||||
|
||||
def _get_date(dtype):
|
||||
"""Return a function to compute the limit date for this type"""
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
# -*- 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/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from osv import fields, osv
|
||||
from tools.translate import _
|
||||
|
||||
|
||||
class stock_split_into(osv.osv_memory):
|
||||
_name = "stock.split.into"
|
||||
_description = "Split into"
|
||||
|
||||
def default_get(self, cr, uid, fields, context=None):
|
||||
""" Get default values
|
||||
@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 default value
|
||||
@param context: A standard dictionary
|
||||
@return: Default values of fields
|
||||
"""
|
||||
res = super(stock_split_into, self).default_get(cr, uid, fields, context=context)
|
||||
move = self.pool.get('stock.move').browse(cr, uid, context['active_id'], context=context)
|
||||
if 'quantity' in fields:
|
||||
res.update({'quantity': move.product_qty})
|
||||
return res
|
||||
|
||||
_columns = {
|
||||
'quantity': fields.integer('Quantity'),
|
||||
}
|
||||
_defaults = {
|
||||
'quantity': lambda *x: 1,
|
||||
}
|
||||
|
||||
def split(self, cr, uid, data, context=None):
|
||||
rec_id = context and context.get('active_ids', False)
|
||||
move_obj = self.pool.get('stock.move')
|
||||
new_move = []
|
||||
update_val = {}
|
||||
value_to_split = self.browse(cr, uid, data[0], context)
|
||||
quantity = value_to_split.quantity or 0.0
|
||||
for move in move_obj.browse(cr, uid, rec_id):
|
||||
move_qty = move.product_qty
|
||||
uos_qty_rest = move.product_uos_qty
|
||||
quantity_rest = move_qty - quantity
|
||||
if quantity_rest == 0:
|
||||
continue
|
||||
uos_qty = quantity / move_qty * move.product_uos_qty
|
||||
uos_qty_rest = quantity_rest / move_qty * move.product_uos_qty
|
||||
default_val = {
|
||||
'product_qty': quantity,
|
||||
'product_uos_qty': uos_qty,
|
||||
'state': move.state
|
||||
}
|
||||
current_move = move_obj.copy(cr, uid, move.id, default_val)
|
||||
new_move.append(current_move)
|
||||
update_val['product_qty'] = quantity_rest
|
||||
update_val['product_uos_qty'] = uos_qty_rest
|
||||
move_obj.write(cr, uid, [move.id], update_val)
|
||||
return {}
|
||||
stock_split_into()
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<record id="view_stock_move_split_wizard" model="ir.ui.view">
|
||||
<field name="name">Split move</field>
|
||||
<field name="model">stock.split.into</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Split Move">
|
||||
<field name="quantity" colspan="4"/>
|
||||
<button icon='gtk-cancel' special="cancel"
|
||||
string="Cancel" />
|
||||
<button name="split" string="Ok"
|
||||
type="object" icon="gtk-ok" />
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="split_into" model="ir.actions.act_window">
|
||||
<field name="name">Split into</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">stock.split.into</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
Loading…
Reference in New Issue