From 9442412b8e8896aede810a96acd93812d7272e95 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Fri, 6 Sep 2013 16:47:55 +0200 Subject: [PATCH] [IMP] continued the stock_reserve_sale module --- stock_reserve/__openerp__.py | 6 ++ stock_reserve/model/stock_reserve.py | 17 +++--- stock_reserve/view/stock_reserve.xml | 8 ++- stock_reserve_sale/__openerp__.py | 21 +++++-- stock_reserve_sale/model/sale.py | 55 ++++++++++++++++++- stock_reserve_sale/view/sale.xml | 36 +++++++----- .../wizard/sale_stock_reserve.py | 31 ++++++++++- .../wizard/sale_stock_reserve_view.xml | 5 ++ 8 files changed, 147 insertions(+), 32 deletions(-) diff --git a/stock_reserve/__openerp__.py b/stock_reserve/__openerp__.py index a2b6c0657..8633fcfcd 100644 --- a/stock_reserve/__openerp__.py +++ b/stock_reserve/__openerp__.py @@ -36,6 +36,12 @@ Allows to create stock reservation on a product. Each reservation can have a validity date, once passed, the reservation is automatically lifted. +The reserved products are substracted from the virtual stock. It means +that if you reserved too many products and the virtual stock goes below +the minimum, the orderpoint will be trigged and new purchase orders will +be generated. It also implies that the max may be exceeded if the +reservations are canceled. + """, 'depends': ['stock', ], diff --git a/stock_reserve/model/stock_reserve.py b/stock_reserve/model/stock_reserve.py index de20bcc9d..f3b8241b1 100644 --- a/stock_reserve/model/stock_reserve.py +++ b/stock_reserve/model/stock_reserve.py @@ -59,7 +59,7 @@ class stock_reservation(orm.Model): 'date_validity': fields.date('Validity Date'), } - def _get_location_from_ref(self, cr, uid, ref, context=None): + def get_location_from_ref(self, cr, uid, ref, context=None): """ Get a location from a xmlid if allowed :param ref: tuple (module, xmlid) """ @@ -75,17 +75,20 @@ class stock_reservation(orm.Model): return location_id def _default_location_id(self, cr, uid, context=None): - ref = ('stock', 'stock_location_stock') - return self._get_location_from_ref(cr, uid, ref, context=context) + if context is None: + context = {} + move_obj = self.pool.get('stock.move') + context['picking_type'] = 'internal' + return move_obj._default_location_source(cr, uid, context=context) - def _default_dest_location_id(self, cr, uid, context=None): + def _default_location_dest_id(self, cr, uid, context=None): ref = ('stock_reserve', 'stock_location_reservation') - return self._get_location_from_ref(cr, uid, ref, context=context) + return self.get_location_from_ref(cr, uid, ref, context=context) _defaults = { 'type': 'internal', 'location_id': _default_location_id, - 'location_dest_id': _default_dest_location_id, + 'location_dest_id': _default_location_dest_id, 'product_qty': 1.0, } @@ -118,7 +121,7 @@ class stock_reservation(orm.Model): def release_validity_exceeded(self, cr, uid, ids=None, context=None): """ Release all the reservation having an exceeded validity date """ domain = [('date_validity', '<', fields.date.today()), - ('state', '=', 'done')] + ('state', '=', 'assigned')] if ids: domain.append(('id', 'in', ids)) reserv_ids = self.search(cr, uid, domain, context=context) diff --git a/stock_reserve/view/stock_reserve.xml b/stock_reserve/view/stock_reserve.xml index c65e4c6e4..a15d08c8c 100644 --- a/stock_reserve/view/stock_reserve.xml +++ b/stock_reserve/view/stock_reserve.xml @@ -18,7 +18,7 @@ @@ -22,37 +24,45 @@