diff --git a/stock_reserve/model/stock_reserve.py b/stock_reserve/model/stock_reserve.py index bfb43344b..81afc0223 100644 --- a/stock_reserve/model/stock_reserve.py +++ b/stock_reserve/model/stock_reserve.py @@ -86,6 +86,7 @@ class stock_reservation(orm.Model): 'type': 'internal', 'location_id': _default_location_id, 'location_dest_id': _default_dest_location_id, + 'product_qty': 1.0, } def reserve(self, cr, uid, ids, context=None): @@ -131,11 +132,7 @@ class stock_reservation(orm.Model): return super(stock_reservation, self).unlink(cr, uid, ids, context=context) - def onchange_product_id(self, cr, uid, ids, prod_id=False, loc_id=False, - loc_dest_id=False, partner_id=False, context=None): - """ On change of product id, if finds UoM, UoS, - quantity and UoS quantity. - """ + def onchange_product_id(self, cr, uid, ids, product_id=False, context=None): move_obj = self.pool.get('stock.move') if ids: reserv = self.read(cr, uid, ids, ['move_id'], context=context, @@ -143,9 +140,11 @@ class stock_reservation(orm.Model): move_ids = [rv['move_id'] for rv in reserv] else: move_ids = [] - return move_obj.onchange_product_id( - cr, uid, move_ids, prod_id=prod_id, loc_id=loc_id, - loc_dest_id=loc_dest_id, partner_id=partner_id) + result = move_obj.onchange_product_id( + cr, uid, move_ids, prod_id=product_id, loc_id=False, + loc_dest_id=False, partner_id=False) + del result['value']['product_qty'] # keeps the current value + return result def onchange_quantity(self, cr, uid, ids, product_id, product_qty, context=None): """ On change of product quantity avoid negative quantities """ diff --git a/stock_reserve/view/stock_reserve.xml b/stock_reserve/view/stock_reserve.xml index 2d6f9806a..c65e4c6e4 100644 --- a/stock_reserve/view/stock_reserve.xml +++ b/stock_reserve/view/stock_reserve.xml @@ -24,7 +24,7 @@ + + + + diff --git a/stock_reserve_sale/wizard/__init__.py b/stock_reserve_sale/wizard/__init__.py new file mode 100644 index 000000000..6156962e3 --- /dev/null +++ b/stock_reserve_sale/wizard/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Guewen Baconnier +# Copyright 2013 Camptocamp SA +# +# 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 . import sale_stock_reserve diff --git a/stock_reserve_sale/wizard/sale_stock_reserve.py b/stock_reserve_sale/wizard/sale_stock_reserve.py new file mode 100644 index 000000000..734e6010f --- /dev/null +++ b/stock_reserve_sale/wizard/sale_stock_reserve.py @@ -0,0 +1,82 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Guewen Baconnier +# Copyright 2013 Camptocamp SA +# +# 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 openerp.osv import orm, fields + + +class sale_stock_reserve(orm.TransientModel): + _name = 'sale.stock.reserve' + + _columns = { + 'date_validity': fields.date( + "Validity Date", + help="If a date is given, the reservations will be released " + "at the end of the validity."), + } + + def _prepare_stock_reservation(self, cr, uid, form, line, context=None): + return {'product_id': line.product_id.id, + 'product_uom': line.product_uom.id, + 'product_qty': line.product_uom_qty, + 'validity_date': form.date_validity, + 'name': "{} ({})".format(line.order_id.name, line.name), + } + + def stock_reserve(self, cr, uid, ids, line_ids, context=None): + assert len(ids) == 1, "Expected 1 ID, got %r" % ids + reserv_obj = self.pool.get('stock.reservation') + line_obj = self.pool.get('sale.order.line') + + form = self.browse(cr, uid, ids[0], context=context) + lines = line_obj.browse(cr, uid, line_ids, context=context) + for line in lines: + if line.reservation_id: + continue + if not line.product_id: + continue + vals = self._prepare_stock_reservation(cr, uid, form, line, + context=context) + reserv_id = reserv_obj.create(cr, uid, vals, context=context) + reserv_obj.reserve(cr, uid, [reserv_id], context=context) + line.write({'reservation_id': reserv_id}) + return True + + def button_reserve(self, cr, uid, ids, context=None): + assert len(ids) == 1, "Expected 1 ID, got %r" % ids + if context is None: + context = {} + close = {'type': 'ir.actions.act_window_close'} + active_model = context.get('active_model') + active_ids = context.get('active_ids') + if not (active_model and active_ids): + return close + + line_obj = self.pool.get('sale.order.line') + if active_model == 'sale.order': + sale_obj = self.pool.get('sale.order') + sales = sale_obj.browse(cr, uid, active_ids, context=context) + line_ids = [line.id for sale in sales for line in sale.order_line] + + if active_model == 'sale.order.line': + line_ids = active_ids + + self.stock_reserve(cr, uid, ids, line_ids, context=context) + return close diff --git a/stock_reserve_sale/wizard/sale_stock_reserve_view.xml b/stock_reserve_sale/wizard/sale_stock_reserve_view.xml new file mode 100644 index 000000000..66017c53a --- /dev/null +++ b/stock_reserve_sale/wizard/sale_stock_reserve_view.xml @@ -0,0 +1,39 @@ + + + + + + sale.stock.reserve.form + sale.stock.reserve + +
+

+ A stock reservation will be created for the products + of the selected quotation lines. If a validity date is specified, + the reservation will be released once the date has passed. +

+ + + +
+
+
+
+
+ + + Reserve Stock for Quotation Lines + ir.actions.act_window + sale.stock.reserve + form + form + new + +
+