Kirti Savalia(OpenERP) has proposed merging 
lp:~openerp-dev/openobject-server/trunk-temporal-db-shallow-copy-ksa into 
lp:~openerp-dev/openobject-server/trunk-temporal-db.

Requested reviews:
  Rucha (Open ERP) (rpa-openerp)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-server/trunk-temporal-db-shallow-copy-ksa/+merge/65652

shallow copy method
-- 
https://code.launchpad.net/~openerp-dev/openobject-server/trunk-temporal-db-shallow-copy-ksa/+merge/65652
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-server/trunk-temporal-db.
=== modified file 'openerp/osv/orm.py'
--- openerp/osv/orm.py	2011-06-22 13:53:44 +0000
+++ openerp/osv/orm.py	2011-06-23 12:42:56 +0000
@@ -4471,6 +4471,51 @@
         self.copy_translations(cr, uid, id, new_id, context)
         return new_id
 
+    def shallow_copy(self, cr, uid, id, default=None, context=None):
+        """
+        Copy given record's data with all its fields values for filed located on that object
+
+        :param cr: database cursor
+        :param user: current user id
+        :param id: id of the record to copy
+        :param default: field values to override in the original values of the copied record
+        :type default: dictionary
+        :param context: context arguments, like lang, time zone
+        :type context: dictionary
+        :return: dictionary containing all the field values
+        """
+        if context is None:
+            context = {}
+
+        data = self.read(cr, uid, [id,], context=context)
+        if data:
+            data = data[0]
+        else:
+            raise IndexError( _("Record #%d of %s not found, cannot copy!") %( id, self._name))
+
+        fields = self.fields_get(cr, uid, context=context)
+        for f in fields:
+            ftype = fields[f]['type']
+
+            if ftype in ('one2many','many2one'):
+                del data[f]
+            elif ftype in ('one2one'):
+                res = []
+                rel = self.pool.get(fields[f]['relation'])
+                if data[f]:
+                    data[f].sort()
+                    for rel_id in data[f]:
+                        d = rel.copy_data(cr, uid, rel_id, context=context)
+                        if d:
+                            res.append((0, 0, d))
+                data[f] = res
+            elif ftype == 'many2many':
+                del data[f]
+        del data['id']
+
+        new_id = self.create(cr, uid, data, context)
+        return new_id
+
     def exists(self, cr, uid, ids, context=None):
         if type(ids) in (int, long):
             ids = [ids]

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to