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.
This commit is contained in:
Leonardo Pistone
2015-03-17 17:30:57 +01:00
committed by Víctor Martínez
parent 07e6be5375
commit 5b77b0c9c5
6 changed files with 72 additions and 23 deletions

View File

@@ -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 <guewen.baconnier@camptocamp.com>
* Yannick Vaucher <yannick.vaucher@camptocamp.com>
* Leonardo Pistone <leonardo.pistone@camptocamp.com>
""",
'depends': ['stock',

View File

@@ -3,7 +3,7 @@
<data noupdate="1">
<record id="stock_location_reservation" model="stock.location">
<field name="name">Reservation Stock</field>
<field name="location_id" ref="stock.stock_location_company"/>
<field name="location_id" ref="stock.stock_location_locations"/>
</record>

View File

@@ -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 <http://www.gnu.org/licenses/>.
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'
);
''')

View File

@@ -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

View File

@@ -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
-

View File

@@ -36,6 +36,7 @@
<field name="company_id"
groups="base.group_multi_company"
widget="selection"/>
<field name="restrict_partner_id" groups="stock.group_tracking_owner"/>
</group>
<group name="location" string="Locations"
groups="stock.group_locations">
@@ -63,6 +64,7 @@
<field name="product_uom_qty" sum="Total" />
<field name="product_uom" />
<field name="date_validity" />
<field name="restrict_partner_id" groups="stock.group_tracking_owner"/>
<field name="state"/>
<button name="reserve" type="object"
string="Reserve"
@@ -93,6 +95,7 @@
<field name="name" />
<field name="product_id" />
<field name="move_id" />
<field name="restrict_partner_id" groups="stock.group_tracking_owner"/>
<group expand="0" string="Group By...">
<filter string="Status"
name="groupby_state"