diff --git a/addons/sale_stock/sale_stock.py b/addons/sale_stock/sale_stock.py index 544f8e43e42..312ebb674bc 100644 --- a/addons/sale_stock/sale_stock.py +++ b/addons/sale_stock/sale_stock.py @@ -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) diff --git a/addons/stock_dropshipping/__init__.py b/addons/stock_dropshipping/__init__.py index 0da169d786a..6f8498480f1 100644 --- a/addons/stock_dropshipping/__init__.py +++ b/addons/stock_dropshipping/__init__.py @@ -18,6 +18,7 @@ # along with this program. If not, see . # ############################################################################## +import stock_dropshipping import wizard # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/stock_dropshipping/stock_dropshipping.py b/addons/stock_dropshipping/stock_dropshipping.py new file mode 100644 index 00000000000..cbd079263ca --- /dev/null +++ b/addons/stock_dropshipping/stock_dropshipping.py @@ -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