diff --git a/product/ERP5Type/Base.py b/product/ERP5Type/Base.py index bcd864c3862504fe32637c5ade8109efb565b9b1..fcd8320f6640fc538f0d7c98bb0f5a5110da8483 100644 --- a/product/ERP5Type/Base.py +++ b/product/ERP5Type/Base.py @@ -2801,12 +2801,31 @@ class Base( CopyContainer, for k in REQUEST.keys(): if k != 'SESSION': setattr(context, k, REQUEST[k]) + # Set the original document + kw['_original'] = self # Define local properties context.__dict__.update(kw) return context else: return context.asContext(REQUEST=REQUEST, **kw) + security.declarePublic('getOriginalDocument') + def getOriginalDocument(self, context=None, REQUEST=None, **kw): + """ + This method returns: + * the original document for an asContext() result document. + * self for a real document. + * None for a temporary document. + """ + if not self.isTempObject(): + return self + else: + original = getattr(self, '_original', None) + if original is not None: + return aq_inner(original) + else: + return None + security.declarePublic('isTempObject') def isTempObject(self): """Return true if self is an instance of a temporary document class. diff --git a/product/ERP5Type/tests/testERP5Type.py b/product/ERP5Type/tests/testERP5Type.py index 0e6f844021066e62f329b4fffec363cb92ecded1..276ac77469b999af8e1612f7d082acd024d65620 100644 --- a/product/ERP5Type/tests/testERP5Type.py +++ b/product/ERP5Type/tests/testERP5Type.py @@ -1338,6 +1338,9 @@ class TestPropertySheet: obj.setTitle('obj title') copy = obj.asContext() self.assertTrue(copy.isTempObject(), '%r is not a temp object' % (copy,)) + self.assertEquals(obj, copy.getOriginalDocument()) + self.assertEquals(obj.absolute_url(), + copy.getOriginalDocument().absolute_url()) copy.setTitle('copy title') self.assertEquals('obj title', obj.getTitle()) self.assertEquals('copy title', copy.getTitle()) @@ -1671,6 +1674,7 @@ class TestPropertySheet: from Products.ERP5Type.Document import newTempPerson o = newTempPerson(portal, 'temp_person_1') self.assertTrue(o.isTempObject()) + self.assertEquals(o.getOriginalDocument(), None) # This should generate a workflow method. self.assertEquals(o.getValidationState(), 'draft')