2014-12-31 13:29:45 +00:00
# coding: utf-8
2015-05-22 17:32:28 +00:00
from openerp import models , api , _
from openerp . exceptions import Warning
2014-12-31 13:29:45 +00:00
class sale_order_line ( models . Model ) :
_inherit = ' sale.order.line '
2015-05-11 11:20:06 +00:00
@api.multi
2014-12-31 13:29:45 +00:00
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 :
2015-05-11 11:20:06 +00:00
for line in self :
for pull_rule in line . 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
2014-12-31 13:29:45 +00:00
return res
2015-05-22 17:32:28 +00:00
class purchase_order ( models . Model ) :
_inherit = ' purchase.order '
2015-06-02 10:07:50 +00:00
@api.one
def _check_invoice_policy ( self ) :
if self . invoice_method == ' picking ' and self . location_id . usage == ' customer ' :
for proc in self . order_line . mapped ( ' procurement_ids ' ) :
if proc . sale_line_id . order_id . order_policy == ' picking ' :
raise Warning ( _ ( ' In the case of a dropship route, it is not possible to have an invoicing control set on " Based on incoming shipments " and a sale order with an invoice creation on " On Delivery Order " ' ) )
2015-05-22 17:32:28 +00:00
@api.multi
def wkf_confirm_order ( self ) :
2015-06-02 10:07:50 +00:00
""" Raise a warning to forbid to have both purchase and sale invoices
policies at delivery in dropshipping . As it is not implemented .
This check can be disabled setting ' no_invoice_policy_check ' in context
"""
if not self . env . context . get ( ' no_invoice_policy_check ' ) :
self . _check_invoice_policy ( )
2015-05-22 17:32:28 +00:00
super ( purchase_order , self ) . wkf_confirm_order ( )
2015-08-17 13:41:34 +00:00
class procurement_order ( models . Model ) :
_inherit = ' procurement.order '
@api.model
def update_origin_po ( self , po , proc ) :
super ( procurement_order , self ) . update_origin_po ( po , proc )
if proc . sale_line_id and not ( proc . origin in po . origin ) :
po . sudo ( ) . write ( { ' origin ' : po . origin + ' , ' + proc . origin } )