From 32e4fdd40e31b6480971887850bed50fb62f22e7 Mon Sep 17 00:00:00 2001 From: "nel@tinyerp.com" <> Date: Tue, 15 Jun 2010 11:09:33 +0200 Subject: [PATCH] [ADD]stock :split bzr revid: nel@tinyerp.com-20100615090933-sr3xl66g4q6x7rcb --- addons/product_expiry/product_expiry.py | 11 +++ addons/stock/wizard/stock_splitinto.py | 79 ++++++++++++++++++++ addons/stock/wizard/stock_splitinto_view.xml | 30 ++++++++ 3 files changed, 120 insertions(+) create mode 100644 addons/stock/wizard/stock_splitinto.py create mode 100644 addons/stock/wizard/stock_splitinto_view.xml diff --git a/addons/product_expiry/product_expiry.py b/addons/product_expiry/product_expiry.py index 92dc7974bf7..fdc63d28afe 100644 --- a/addons/product_expiry/product_expiry.py +++ b/addons/product_expiry/product_expiry.py @@ -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""" diff --git a/addons/stock/wizard/stock_splitinto.py b/addons/stock/wizard/stock_splitinto.py new file mode 100644 index 00000000000..a3b372d7eb8 --- /dev/null +++ b/addons/stock/wizard/stock_splitinto.py @@ -0,0 +1,79 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 Tiny SPRL (). +# +# 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 . +# +############################################################################## + +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() + diff --git a/addons/stock/wizard/stock_splitinto_view.xml b/addons/stock/wizard/stock_splitinto_view.xml new file mode 100644 index 00000000000..116511b8755 --- /dev/null +++ b/addons/stock/wizard/stock_splitinto_view.xml @@ -0,0 +1,30 @@ + + + + + + Split move + stock.split.into + form + +
+ +