Skip to content

Commit

Permalink
fix OCA#42: reserve location should be outside WH
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lepistone authored and mt-software-de committed Jan 10, 2022
1 parent 74b2b00 commit 478f1ea
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 23 deletions.
6 changes: 5 additions & 1 deletion stock_reserve/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -43,11 +43,15 @@
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 <[email protected]>
* Yannick Vaucher <[email protected]>
* Leonardo Pistone <[email protected]>
""",
'depends': ['stock',
Expand Down
2 changes: 1 addition & 1 deletion stock_reserve/data/stock_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>


Expand Down
42 changes: 42 additions & 0 deletions stock_reserve/migrations/0.2/post-migration.py
Original file line number Diff line number Diff line change
@@ -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'
);
''')
25 changes: 9 additions & 16 deletions stock_reserve/model/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,14 @@
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):
Expand All @@ -56,18 +51,16 @@ def action_view_reservations(self):
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
Expand Down
17 changes: 12 additions & 5 deletions stock_reserve/test/stock_reserve.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
-
Expand All @@ -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
-
Expand Down
3 changes: 3 additions & 0 deletions stock_reserve/view/stock_reserve.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 478f1ea

Please sign in to comment.