Skip to content

Commit

Permalink
Merge 4c7a964 into 06c60b1
Browse files Browse the repository at this point in the history
  • Loading branch information
yvaucher committed Dec 1, 2014
2 parents 06c60b1 + 4c7a964 commit b6e0428
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions framework_agreement_sourcing/model/logistic_requisition_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,24 @@ def _company(self, cr, uid, context):
return self.pool['res.company']._company_default_get(
cr, uid, self._name, context=context)

@api.model
def _get_po_picking_type_id(self, dest_address):
if not dest_address:
return False
PickType = self.env['stock.picking.type']
types = PickType.search([
('warehouse_id.partner_id', '=', dest_address.id)])

picking_type_id = False
if types:
picking_type_id = types[0].id
elif dest_address.customer:
# if destination is not for a warehouse address,
# we set dropshipping picking type
ref = 'stock_dropshipping.picking_type_dropship'
picking_type_id = self.env['ir.model.data'].xmlid_to_res_id(ref)
return picking_type_id

def _prepare_purchase_order(self, cr, uid, line, po_pricelist,
context=None):
"""Prepare the dict of values to create the PO from a
Expand All @@ -72,6 +90,8 @@ def _prepare_purchase_order(self, cr, uid, line, po_pricelist,
"""
supplier = line.framework_agreement_id.supplier_id
add = line.requisition_id.consignee_shipping_id
pick_type_id = self._get_po_picking_type_id(
cr, uid, add, context=context)
term = supplier.property_supplier_payment_term
term = term.id if term else False
position = supplier.property_account_position
Expand All @@ -83,6 +103,8 @@ def _prepare_purchase_order(self, cr, uid, line, po_pricelist,
data['company_id'] = self._company(cr, uid, context)
data['pricelist_id'] = po_pricelist.id
data['dest_address_id'] = add.id
if pick_type_id:
data['picking_type_id'] = pick_type_id
data['location_id'] = add.property_stock_customer.id
data['payment_term_id'] = term
data['fiscal_position'] = position
Expand Down

0 comments on commit b6e0428

Please sign in to comment.