From 224cd3e181bf69bf81984e3c68f77b153cd44590 Mon Sep 17 00:00:00 2001 From: Leonardo Pistone Date: Tue, 17 Mar 2015 17:30:57 +0100 Subject: [PATCH] fix #42: reserve location should be outside WH This has always been wrong on v8, but because of the very obscure odoo/odoo#5797, this seemed to work every time we had single-step reception. Please note that this block of XML is noupdate, so for existing installations you need to change the parent of the reservation location to something outside your warehouses manually. Incidentally, this makes the branch green independently of odoo/odoo#5797. --- stock_reserve/__openerp__.py | 6 ++- stock_reserve/data/stock_data.xml | 2 +- .../migrations/0.2/post-migration.py | 42 +++++++++++++++++++ stock_reserve/model/product.py | 25 ++++------- stock_reserve/test/stock_reserve.yml | 17 +++++--- stock_reserve/view/stock_reserve.xml | 3 ++ 6 files changed, 72 insertions(+), 23 deletions(-) create mode 100644 stock_reserve/migrations/0.2/post-migration.py diff --git a/stock_reserve/__openerp__.py b/stock_reserve/__openerp__.py index 23386630f..1acf2312b 100644 --- a/stock_reserve/__openerp__.py +++ b/stock_reserve/__openerp__.py @@ -21,7 +21,7 @@ {'name': 'Stock Reservation', 'summary': 'Stock reservations on products', - 'version': '0.1', + 'version': '0.2', 'author': "Camptocamp,Odoo Community Association (OCA)", 'category': 'Warehouse', 'license': 'AGPL-3', @@ -43,11 +43,15 @@ stock below the minimum, the orderpoint will be triggered and new purchase orders will be generated. It also implies that the max may be exceeded if the reservations are canceled. +If ownership of stock is active in the stock settings, you can specify the +owner on the reservation. + Contributors ------------ * Guewen Baconnier * Yannick Vaucher +* Leonardo Pistone """, 'depends': ['stock', diff --git a/stock_reserve/data/stock_data.xml b/stock_reserve/data/stock_data.xml index be6e44224..d2dc81a49 100644 --- a/stock_reserve/data/stock_data.xml +++ b/stock_reserve/data/stock_data.xml @@ -3,7 +3,7 @@ Reservation Stock - + diff --git a/stock_reserve/migrations/0.2/post-migration.py b/stock_reserve/migrations/0.2/post-migration.py new file mode 100644 index 000000000..40e439352 --- /dev/null +++ b/stock_reserve/migrations/0.2/post-migration.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- +# Author: Leonardo Pistone +# Copyright 2015 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 . + + +def migrate(cr, installed_version): + """Update a wrong location that is no_update in XML.""" + if installed_version == '8.0.0.1': + cr.execute(''' + UPDATE stock_location + SET location_id = ( + SELECT res_id + FROM ir_model_data + WHERE name = 'stock_location_locations' + AND module = 'stock' + ) + WHERE id = ( + SELECT res_id + FROM ir_model_data + WHERE name = 'stock_location_reservation' + AND module = 'stock_reserve' + ) + AND location_id = ( + SELECT res_id + FROM ir_model_data + WHERE name = 'stock_location_company' + AND module = 'stock' + ); + ''') diff --git a/stock_reserve/model/product.py b/stock_reserve/model/product.py index fd9ea385b..1f6c42333 100644 --- a/stock_reserve/model/product.py +++ b/stock_reserve/model/product.py @@ -25,19 +25,14 @@ from openerp import models, fields, api class ProductTemplate(models.Model): _inherit = 'product.template' - reservation_count = fields.Integer( + reservation_count = fields.Float( compute='_reservation_count', string='# Sales') - @api.multi + @api.one def _reservation_count(self): - StockReservation = self.env['stock.reservation'] - product_ids = self._get_products() - domain = [('product_id', 'in', product_ids), - ('state', 'in', ['draft', 'assigned'])] - reservations = StockReservation.search(domain) - self.reservation_count = sum(reserv.product_uom_qty - for reserv in reservations) + self.reservation_count = sum(variant.reservation_count + for variant in self.product_variant_ids) @api.multi def action_view_reservations(self): @@ -56,18 +51,16 @@ class ProductTemplate(models.Model): class ProductProduct(models.Model): _inherit = 'product.product' - reservation_count = fields.Integer( + reservation_count = fields.Float( compute='_reservation_count', string='# Sales') - @api.multi + @api.one def _reservation_count(self): - StockReservation = self.env['stock.reservation'] - product_id = self._ids[0] - domain = [('product_id', '=', product_id), + domain = [('product_id', '=', self.id), ('state', 'in', ['draft', 'assigned'])] - reservations = StockReservation.search(domain) - self.reservation_count = sum(reserv.product_uom_qty + reservations = self.env['stock.reservation'].search(domain) + self.reservation_count = sum(reserv.product_qty for reserv in reservations) @api.multi diff --git a/stock_reserve/test/stock_reserve.yml b/stock_reserve/test/stock_reserve.yml index 66b6f412e..369b1563f 100644 --- a/stock_reserve/test/stock_reserve.yml +++ b/stock_reserve/test/stock_reserve.yml @@ -60,8 +60,15 @@ - I confirm the reservation - - !python {model: stock.reservation}: | - self.reserve(cr, uid, [ref('reserv_sorbet2')], context=context) + !python {model: stock.reservation, id: reserv_sorbet2}: | + self.reserve() +- + I check the reserved amount of the product and the template +- + !python {model: product.product, id: product_sorbet}: | + from nose.tools import * + assert_almost_equal(6.5, self.reservation_count) + assert_almost_equal(6.5, self.product_tmpl_id.reservation_count) - Then the reservation should be assigned and have reserved a quant - @@ -73,9 +80,9 @@ - I check Virtual stock of Sorbet after update reservation - - !python {model: product.product}: | - product = self.browse(cr, uid, ref('stock_reserve.product_sorbet'), context=context) - assert product.virtual_available == 3.5, "Stock is not updated." + !python {model: product.product, id: product_sorbet}: | + from nose.tools import * + assert_almost_equal(3.5, self.virtual_available) - I run the scheduler - diff --git a/stock_reserve/view/stock_reserve.xml b/stock_reserve/view/stock_reserve.xml index 7ee9cbdd3..cbeaa8abf 100644 --- a/stock_reserve/view/stock_reserve.xml +++ b/stock_reserve/view/stock_reserve.xml @@ -36,6 +36,7 @@ + @@ -63,6 +64,7 @@ +