From 0cf5e41afc708448479a998e46c4b17f44a7e425 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Mon, 4 Nov 2013 11:19:57 +0100 Subject: [PATCH 1/2] [IMP] extracted '_prepare' method to be able to customize the creation of po from tenders bzr revid: guewen.baconnier@camptocamp.com-20131104101957-krpkp24ctc4k3zjy --- .../purchase_requisition.py | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/addons/purchase_requisition/purchase_requisition.py b/addons/purchase_requisition/purchase_requisition.py index afb18dc0d2c..0e2d2cc5e85 100644 --- a/addons/purchase_requisition/purchase_requisition.py +++ b/addons/purchase_requisition/purchase_requisition.py @@ -212,6 +212,28 @@ 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 for 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 for 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 +277,15 @@ 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]) From 99b27fa6b4b5497d6d5457839a7bfdf941da97a7 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Mon, 4 Nov 2013 11:26:46 +0100 Subject: [PATCH 2/2] [FIX] open_product_line() returns an action, the action should not propagate the current context but use its own one (so it will have the correct active_model, active_ids and so on, otherwise, it propagates a wrong active_ids and active_model). bzr revid: guewen.baconnier@camptocamp.com-20131104102646-pjdorjqfaic3sw7b --- addons/purchase_requisition/purchase_requisition.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/addons/purchase_requisition/purchase_requisition.py b/addons/purchase_requisition/purchase_requisition.py index 0e2d2cc5e85..119bbd1b997 100644 --- a/addons/purchase_requisition/purchase_requisition.py +++ b/addons/purchase_requisition/purchase_requisition.py @@ -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):