[MERGE] merged the branch from camptocamp with enhancements in purchase_requisition: it includes a bugfix and the introduction of 2 methods to prepare values before theh creatino of objects (to ease the inheritancy)

bzr revid: qdp-launchpad@openerp.com-20131104140724-z6kt0zqwrtbjso5a
This commit is contained in:
Quentin (OpenERP) 2013-11-04 15:07:24 +01:00
commit 3df02e56a5
1 changed files with 29 additions and 9 deletions

View File

@ -119,15 +119,12 @@ class purchase_requisition(osv.osv):
context = {}
res = self.pool.get('ir.actions.act_window').for_xml_id(cr, uid, 'purchase_requisition', 'purchase_line_tree', context=context)
res['context'] = context
po_ids_browse = self.browse(cr, uid, ids, context=context)[0].po_line_ids
po_ids = []
for po in po_ids_browse:
po_ids.append(po.id)
res['context'].update({
po_lines = self.browse(cr, uid, ids, context=context)[0].po_line_ids
res['context'] = {
'search_default_groupby_product': True,
'search_default_hide_cancelled': True,
})
res['domain'] = [('id', 'in', po_ids)]
}
res['domain'] = [('id', 'in', [line.id for line in po_lines])]
return res
def open_rfq(self, cr, uid, ids, context=None):
@ -212,6 +209,27 @@ class purchase_requisition(osv.osv):
return False
return True
def _prepare_po_from_tender(self, cr, uid, tender, context=None):
""" Prepare the values to write in the purchase order
created from a tender.
:param tender: the source tender from which we generate a purchase order
"""
return {'order_line': [],
'requisition_id': tender.id,
'origin': tender.name}
def _prepare_po_line_from_tender(self, cr, uid, tender, line, purchase_id, context=None):
""" Prepare the values to write in the purchase order line
created from a line of the tender.
:param tender: the source tender from which we generate a purchase order
:param line: the source tender's line from which we generate a line
:param purchase_id: the id of the new purchase
"""
return {'product_qty': line.quantity_bid,
'order_id': purchase_id}
def generate_po(self, cr, uid, ids, context=None):
"""
Generate all purchase order based on selected lines, should only be called on one tender at a time
@ -255,10 +273,12 @@ class purchase_requisition(osv.osv):
for supplier, product_line in id_per_supplier.items():
#copy a quotation for this supplier and change order_line then validate it
quotation_id = po.search(cr, uid, [('requisition_id', '=', tender.id), ('partner_id', '=', supplier)], limit=1)[0]
new_po = po.copy(cr, uid, quotation_id, default={'order_line': [], 'requisition_id': tender.id, 'origin': tender.name}, context=ctx)
vals = self._prepare_po_from_tender(cr, uid, tender, context=context)
new_po = po.copy(cr, uid, quotation_id, default=vals, context=ctx)
#duplicate po_line and change product_qty if needed and associate them to newly created PO
for line in product_line:
poline.copy(cr, uid, line.id, default={'product_qty': line.quantity_bid, 'order_id': new_po}, context=context)
vals = self._prepare_po_line_from_tender(cr, uid, tender, line, new_po, context=context)
poline.copy(cr, uid, line.id, default=vals, context=context)
#use workflow to set new PO state to confirm
po.signal_purchase_confirm(cr, uid, [new_po])