[IMP] purchase: on procurement triggering a PO, try to link the new line first to an existing draft PO
bzr revid: qdp-launchpad@openerp.com-20131003131448-q1iayy0um5xpy82p
This commit is contained in:
parent
c6799b414b
commit
5898738b36
|
@ -1231,12 +1231,13 @@ class procurement_order(osv.osv):
|
|||
context = {}
|
||||
company = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id
|
||||
partner_obj = self.pool.get('res.partner')
|
||||
po_obj = self.pool.get('purchase.order')
|
||||
po_line_obj = self.pool.get('purchase.order.line')
|
||||
uom_obj = self.pool.get('product.uom')
|
||||
pricelist_obj = self.pool.get('product.pricelist')
|
||||
prod_obj = self.pool.get('product.product')
|
||||
acc_pos_obj = self.pool.get('account.fiscal.position')
|
||||
seq_obj = self.pool.get('ir.sequence')
|
||||
warehouse_obj = self.pool.get('stock.warehouse')
|
||||
pass_ids = []
|
||||
for procurement in self.browse(cr, uid, ids, context=context):
|
||||
res_id = procurement.move_dest_id and procurement.move_dest_id.id or False
|
||||
|
@ -1278,6 +1279,15 @@ class procurement_order(osv.osv):
|
|||
'move_dest_id': res_id,
|
||||
'taxes_id': [(6, 0, taxes)],
|
||||
}
|
||||
#look for any other draft PO for the same supplier, to attach the new line on instead of creating a new draft one
|
||||
available_draft_po_ids = po_obj.search(cr, uid, [
|
||||
('partner_id', '=', partner_id), ('state', '=', 'draft'), ('picking_type_id', '=', procurement.rule_id.picking_type_id.id),
|
||||
('location_id', '=', procurement.location_id.id), ('company_id', '=', procurement.company_id.id)], context=context)
|
||||
if available_draft_po_ids:
|
||||
po_id = available_draft_po_ids[0]
|
||||
line_vals.update(order_id=po_id)
|
||||
po_line_id = po_line_obj.create(cr, uid, line_vals, context=context)
|
||||
else:
|
||||
name = seq_obj.get(cr, uid, 'purchase.order') or _('PO: %s') % procurement.name
|
||||
po_vals = {
|
||||
'name': name,
|
||||
|
@ -1291,9 +1301,10 @@ class procurement_order(osv.osv):
|
|||
'fiscal_position': partner.property_account_position and partner.property_account_position.id or False,
|
||||
'payment_term_id': partner.property_supplier_payment_term.id or False,
|
||||
}
|
||||
res[procurement.id] = self.create_procurement_purchase_order(cr, uid, procurement, po_vals, line_vals, context=new_context)
|
||||
procurement_line = self.pool.get('purchase.order').browse(cr, uid, res[procurement.id]).order_line[0].id
|
||||
self.write(cr, uid, [procurement.id], {'purchase_line_id': procurement_line}, context=context)
|
||||
po_id = self.create_procurement_purchase_order(cr, uid, procurement, po_vals, line_vals, context=new_context)
|
||||
po_line_id = po_obj.browse(cr, uid, po_id, context=context).order_line[0].id
|
||||
res[procurement.id] = po_line_id
|
||||
self.write(cr, uid, [procurement.id], {'purchase_line_id': po_line_id}, context=context)
|
||||
pass_ids += [procurement.id]
|
||||
if pass_ids:
|
||||
self.message_post(cr, uid, pass_ids, body=_("Draft Purchase Order created"), context=context)
|
||||
|
|
Loading…
Reference in New Issue