← Back to team overview

openerp-community-reviewer team mailing list archive

[Merge] lp:~camptocamp/openerp-humanitarian-ngo/purchase-wkfl-fix_copy_origin-rde into lp:openerp-humanitarian-ngo/purchase-wkfl

 

Romain Deheele - Camptocamp has proposed merging lp:~camptocamp/openerp-humanitarian-ngo/purchase-wkfl-fix_copy_origin-rde into lp:openerp-humanitarian-ngo/purchase-wkfl.

Requested reviews:
  OpenERP for Humanitarian Core Editors (humanitarian-core-editors)

For more details, see:
https://code.launchpad.net/~camptocamp/openerp-humanitarian-ngo/purchase-wkfl-fix_copy_origin-rde/+merge/203584

Hi,

When a cost estimate is confirmed, a copy of chosen rfq is duplicated to create a PO in draftpo state.
The problem was that during this operation the origin is lost, because openerp original orm method copy clears the origin field.
This MP overwrites purchase.order copy to pick origin if PO comes from requisition.
-- 
https://code.launchpad.net/~camptocamp/openerp-humanitarian-ngo/purchase-wkfl-fix_copy_origin-rde/+merge/203584
Your team OpenERP for Humanitarian Core Editors is requested to review the proposed merge of lp:~camptocamp/openerp-humanitarian-ngo/purchase-wkfl-fix_copy_origin-rde into lp:openerp-humanitarian-ngo/purchase-wkfl.
=== modified file 'purchase_requisition_extended/model/purchase_order.py'
--- purchase_requisition_extended/model/purchase_order.py	2013-11-01 11:44:19 +0000
+++ purchase_requisition_extended/model/purchase_order.py	2014-01-28 16:37:00 +0000
@@ -1,6 +1,7 @@
 # -*- coding: utf-8 -*-
 
 from openerp.osv import fields, orm
+from openerp import SUPERUSER_ID
 
 
 class purchase_order(orm.Model):
@@ -63,6 +64,17 @@
         })
         return values
 
+    def copy(self, cr, uid, id, default=None, context=None):
+        """ Need to set origin after copy because original copy clears origin """
+        origin = ''
+        if 'requisition_id' in default:
+            origin = default['origin']
+        newid = super(purchase_order, self).copy(cr, uid, id, default=default,
+                                                 context=context)
+        if origin:
+            self.write(cr, SUPERUSER_ID, [newid], {'origin': origin}, context=context)
+        return newid
+
 
 class purchase_order_line(orm.Model):
     _inherit = 'purchase.order.line'


Follow ups