mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
Generic module to compute the stock quantity available to promise using several implementations.
stock_available_immediatly is changed to become the first optional implementation.
Cherry pick of commit 0b060f619f from the v7 branch
60 lines
2.5 KiB
Python
60 lines
2.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
##############################################################################
|
|
#
|
|
# Copyright 2010-2012 Camptocamp SA
|
|
# Copyright (C) 2011 Akretion Sébastien BEAU <sebastien.beau@akretion.com>
|
|
#
|
|
# 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/>.
|
|
#
|
|
##############################################################################
|
|
|
|
from openerp.osv import orm
|
|
|
|
from openerp.osv import orm, fields
|
|
|
|
class product_immediately_usable(orm.Model):
|
|
"""Subtract incoming qty from immediately_usable_qty
|
|
|
|
We don't need to override the function fields, the module stock_available
|
|
takes of it for us.
|
|
|
|
Side-effect warning: This method may change the list passed as the
|
|
field_names parameter, which will then alter the caller's state."""
|
|
_inherit = 'product.product'
|
|
|
|
def _product_available(self, cr, uid, ids, field_names=None,
|
|
arg=False, context=None):
|
|
"""Ignore the incoming goods in the quantity available to promise"""
|
|
# If we didn't get a field_names list, there's nothing to do
|
|
if field_names is None or 'immediately_usable_qty' not in field_names:
|
|
return super(product_immediately_usable, self)._product_available(
|
|
cr, uid, ids, field_names=field_names, arg=arg,
|
|
context=context)
|
|
|
|
# We need available and incoming quantities to compute
|
|
# immediately usable quantity.
|
|
# We DO want to change the caller's list so we're NOT going to
|
|
# work on a copy of field_names.
|
|
field_names.append('qty_available')
|
|
field_names.append('incoming_qty')
|
|
|
|
res = super(product_immediately_usable, self)._product_available(
|
|
cr, uid, ids, field_names=field_names, arg=arg, context=context)
|
|
|
|
for stock_qty in res.itervalues():
|
|
stock_qty['immediately_usable_qty'] -= \
|
|
stock_qty['incoming_qty']
|
|
|
|
return res
|