[FIX] stock_dropshipping: do not warn for dropshipped items non-availibility

When selectiong a dropshipped product in a sale.order, the user should not be
warned that the product is not available in stock (as it never goes to the stock
anyway but directly from the supplier to the customer).
Factorise verification in _check_routing method.
This commit is contained in:
Ravi Gohil 2014-12-31 18:59:45 +05:30 committed by Martin Trigaux
parent 3c61ee5c68
commit a7cb326e5a
3 changed files with 48 additions and 21 deletions

View File

@ -266,6 +266,29 @@ class sale_order_line(osv.osv):
return {'value': result, 'warning': warning}
def _check_routing(self, cr, uid, ids, product, warehouse_id, context=None):
""" Verify the route of the product based on the warehouse
return True if the product availibility in stock does not need to be verified
"""
is_available = False
if warehouse_id:
warehouse = self.pool['stock.warehouse'].browse(cr, uid, warehouse_id, context=context)
for product_route in product.route_ids:
if warehouse.mto_pull_id and warehouse.mto_pull_id.route_id and warehouse.mto_pull_id.route_id.id == product_route.id:
is_available = True
break
else:
try:
mto_route_id = self.pool['stock.warehouse']._get_mto_route(cr, uid, context=context)
except osv.except_osv:
# if route MTO not found in ir_model_data, we treat the product as in MTS
mto_route_id = False
if mto_route_id:
for product_route in product.route_ids:
if product_route.id == mto_route_id:
is_available = True
break
return is_available
def product_id_change_with_wh(self, cr, uid, ids, pricelist, product, qty=0,
uom=False, qty_uos=0, uos=False, name='', partner_id=False,
@ -273,7 +296,6 @@ class sale_order_line(osv.osv):
context = context or {}
product_uom_obj = self.pool.get('product.uom')
product_obj = self.pool.get('product.product')
warehouse_obj = self.pool['stock.warehouse']
warning = {}
#UoM False due to hack which makes sure uom changes price, ... in product_id_change
res = self.product_id_change(cr, uid, ids, pricelist, product, qty=qty,
@ -302,28 +324,11 @@ class sale_order_line(osv.osv):
warning_msgs = res_packing.get('warning') and res_packing['warning']['message'] or ''
if product_obj.type == 'product':
#determine if the product is MTO or not (for a further check)
isMto = False
if warehouse_id:
warehouse = warehouse_obj.browse(cr, uid, warehouse_id, context=context)
for product_route in product_obj.route_ids:
if warehouse.mto_pull_id and warehouse.mto_pull_id.route_id and warehouse.mto_pull_id.route_id.id == product_route.id:
isMto = True
break
else:
try:
mto_route_id = warehouse_obj._get_mto_route(cr, uid, context=context)
except:
# if route MTO not found in ir_model_data, we treat the product as in MTS
mto_route_id = False
if mto_route_id:
for product_route in product_obj.route_ids:
if product_route.id == mto_route_id:
isMto = True
break
#determine if the product needs further check for stock availibility
is_available = self._check_routing(cr, uid, ids, product_obj, warehouse_id, context=context)
#check if product is available, and if not: raise a warning, but do this only for products that aren't processed in MTO
if not isMto:
if not is_available:
uom_record = False
if uom:
uom_record = product_uom_obj.browse(cr, uid, uom, context=context)

View File

@ -18,6 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import stock_dropshipping
import wizard
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,21 @@
# coding: utf-8
from openerp import models, api
class sale_order_line(models.Model):
_inherit = 'sale.order.line'
@api.one
def _check_routing(self, product, warehouse):
""" skip stock verification if the route goes from supplier to customer
As the product never goes in stock, no need to verify it's availibility
"""
res = super(sale_order_line, self)._check_routing(product, warehouse)
if not res:
for pull_rule in self.route_id.pull_ids:
if (pull_rule.picking_type_id.default_location_src_id.usage == 'supplier' and
pull_rule.picking_type_id.default_location_dest_id.usage == 'customer'):
res = True
break
return res