← Back to team overview

openerp-community team mailing list archive

[Merge] lp:~ajite/openobject-addons/elico-7.0-imp-intercompany-000001 into lp:~openerp-community/openobject-addons/elico-7.0

 

Augustin Cisterne-Kaas - www.elico-corp.com has proposed merging lp:~ajite/openobject-addons/elico-7.0-imp-intercompany-000001 into lp:~openerp-community/openobject-addons/elico-7.0.

Requested reviews:
  Eric Caudal - www.elico-corp.com (elicoidal)

For more details, see:
https://code.launchpad.net/~ajite/openobject-addons/elico-7.0-imp-intercompany-000001/+merge/202453

Added lock and unlock function for object created during the ICOPS process.
Corrected a bug that was preventing an user from creating an object when the update event was disabled in the backend.
-- 
https://code.launchpad.net/~ajite/openobject-addons/elico-7.0-imp-intercompany-000001/+merge/202453
Your team OpenERP Community is subscribed to branch lp:~openerp-community/openobject-addons/elico-7.0.
=== modified file 'base_intercompany/__init__.py'
--- base_intercompany/__init__.py	2014-01-17 13:12:23 +0000
+++ base_intercompany/__init__.py	2014-01-21 13:18:01 +0000
@@ -2,7 +2,7 @@
 ##############################################################################
 #
 #    OpenERP, Open Source Management Solution
-#    Copyright (c) 2010-2013 Elico Corp. All Rights Reserved.
+#    Copyright (c) 2010-2014 Elico Corp. All Rights Reserved.
 #    Augustin Cisterne-Kaas <augustin.cisterne-kaas@xxxxxxxxxxxxxx>
 #    Eric Caudal <eric.caudal@xxxxxxxxxxxxxx>
 

=== modified file 'base_intercompany/__openerp__.py'
--- base_intercompany/__openerp__.py	2014-01-17 16:27:10 +0000
+++ base_intercompany/__openerp__.py	2014-01-21 13:18:01 +0000
@@ -2,7 +2,7 @@
 ##############################################################################
 #
 #    OpenERP, Open Source Management Solution
-#    Copyright (c) 2010-2013 Elico Corp. All Rights Reserved.
+#    Copyright (c) 2010-2014 Elico Corp. All Rights Reserved.
 #    Augustin Cisterne-Kaas <augustin.cisterne-kaas@xxxxxxxxxxxxxx>
 #    Eric Caudal <eric.caudal@xxxxxxxxxxxxxx>
 

=== modified file 'base_intercompany/backend.py'
--- base_intercompany/backend.py	2014-01-17 13:12:23 +0000
+++ base_intercompany/backend.py	2014-01-21 13:18:01 +0000
@@ -2,7 +2,7 @@
 ##############################################################################
 #
 #    OpenERP, Open Source Management Solution
-#    Copyright (c) 2010-2013 Elico Corp. All Rights Reserved.
+#    Copyright (c) 2010-2014 Elico Corp. All Rights Reserved.
 #    Augustin Cisterne-Kaas <augustin.cisterne-kaas@xxxxxxxxxxxxxx>
 #    Eric Caudal <eric.caudal@xxxxxxxxxxxxxx>
 

=== modified file 'base_intercompany/company.py'
--- base_intercompany/company.py	2014-01-17 13:12:23 +0000
+++ base_intercompany/company.py	2014-01-21 13:18:01 +0000
@@ -2,7 +2,7 @@
 ##############################################################################
 #
 #    OpenERP, Open Source Management Solution
-#    Copyright (c) 2010-2013 Elico Corp. All Rights Reserved.
+#    Copyright (c) 2010-2014 Elico Corp. All Rights Reserved.
 #    Augustin Cisterne-Kaas <augustin.cisterne-kaas@xxxxxxxxxxxxxx>
 #    Eric Caudal <eric.caudal@xxxxxxxxxxxxxx>
 
@@ -35,25 +35,25 @@
         """
         return []
 
-    def _select_object_names(self, cr, uid, context=None):
+    def _select_models(self, cr, uid, context=None):
         """ Available Object names
 
         Can be inherited to add custom versions.
         """
         return {}
 
-    def _get_object_name(self, cr, uid, ids, name, arg, context=None):
+    def _get_model(self, cr, uid, ids, name, arg, context=None):
         """ Available versions
 
         Can be inherited to add custom versions.
         """
         res = {}
         for intercompany in self.browse(cr, uid, ids, context):
-            object_name = None
+            model = None
             if intercompany.concept:
-                object_name = self._select_object_names(
+                model = self._select_models(
                     cr, uid)[intercompany.concept]
-            res[intercompany.id] = object_name
+            res[intercompany.id] = model
         return res
 
     def get_intercompany(self, cr, uid, obj_id,
@@ -93,8 +93,8 @@
                                       required=True, ondelete='cascade'),
         'concept': fields.selection(_select_concepts, string="Concept",
                                     required=True),
-        'object_name': fields.function(_get_object_name, type='char',
-                                       string='Object', store=False),
+        'model': fields.function(_get_model, type='char',
+                                 string='Object', store=False),
         'icops_uid': fields.related(
             'backend_to', 'icops_uid', type='many2one',
             relation='res.users', readonly=True, string='IC User'),

=== modified file 'base_intercompany/connector.py'
--- base_intercompany/connector.py	2014-01-17 13:12:23 +0000
+++ base_intercompany/connector.py	2014-01-21 13:18:01 +0000
@@ -2,7 +2,7 @@
 ##############################################################################
 #
 #    OpenERP, Open Source Management Solution
-#    Copyright (c) 2010-2013 Elico Corp. All Rights Reserved.
+#    Copyright (c) 2010-2014 Elico Corp. All Rights Reserved.
 #    Augustin Cisterne-Kaas <augustin.cisterne-kaas@xxxxxxxxxxxxxx>
 #    Eric Caudal <eric.caudal@xxxxxxxxxxxxxx>
 
@@ -21,7 +21,7 @@
 #
 ##############################################################################
 
-from openerp.osv import orm, fields
+from openerp.osv import orm, osv, fields
 from openerp.addons.connector.connector import Environment
 from openerp.addons.connector.checkpoint import checkpoint
 
@@ -67,10 +67,59 @@
     _columns = {
         'binding_id': fields.integer('ICOPS Binding'),
         'record_id': fields.integer('ICOPS ID'),
+        'model': fields.char('Model'),
         'concept': fields.char('Concept'),
         'backend_id': fields.many2one(
-            'icops.backend', 'ICOPS Backends')
-    }
+            'icops.backend', 'ICOPS Backends'),
+    }
+
+
+class icops_model(orm.AbstractModel):
+    _name = 'icops.model'
+
+    def _is_locked(self, cr, uid, ids, name, arg, context=None):
+        res = {}
+        for obj in self.browse(cr, uid, ids, context=context):
+            pool = self.pool.get('icops.record')
+            record_ids = pool.search(
+                cr, uid, [('record_id', '=', obj.id),
+                          ('model', '=', self._name)])
+
+            res[obj.id] = True if record_ids else False
+        return res
+
+    def _check_icops(self, cr, uid, ids, context=None):
+        context = context or {}
+        if isinstance(ids, int):
+            ids = [ids]
+        if 'icops' in context:
+            return
+        fields = ['locked', 'temp_unlock']
+        for obj in self.read(cr, uid, ids, fields, context=context):
+            print "\n\n"
+            print obj
+            print "\n\n"
+            if obj['temp_unlock']:
+                return
+            elif obj['locked']:
+                raise osv.except_osv(
+                    'ICOPS Error',
+                    'This object is locked by an intercompany process')
+
+    _columns = {
+        'locked': fields.function(
+            _is_locked, type='boolean', string='Is Locked', store=False),
+        # To handle special workflow
+        'temp_unlock': fields.boolean('Temporary Unlock')
+    }
+
+    def action_unlock(self, cr, uid, ids, context):
+        pool = self.pool.get('icops.record')
+        for obj in self.browse(cr, uid, ids, context=context):
+            record_ids = pool.search(
+                cr, uid, [('record_id', '=', obj.id),
+                          ('model', '=', self._name)])
+            pool.unlink(cr, uid, record_ids, context=context)
 
 
 def add_checkpoint(session, model_name, record_id, backend_id):

=== modified file 'base_intercompany/consumer.py'
--- base_intercompany/consumer.py	2014-01-17 13:12:23 +0000
+++ base_intercompany/consumer.py	2014-01-21 13:18:01 +0000
@@ -2,7 +2,7 @@
 ##############################################################################
 #
 #    OpenERP, Open Source Management Solution
-#    Copyright (c) 2010-2013 Elico Corp. All Rights Reserved.
+#    Copyright (c) 2010-2014 Elico Corp. All Rights Reserved.
 #    Augustin Cisterne-Kaas <augustin.cisterne-kaas@xxxxxxxxxxxxxx>
 #    Eric Caudal <eric.caudal@xxxxxxxxxxxxxx>
 

=== modified file 'base_intercompany/icops_model.py'
--- base_intercompany/icops_model.py	2014-01-17 13:12:23 +0000
+++ base_intercompany/icops_model.py	2014-01-21 13:18:01 +0000
@@ -2,7 +2,7 @@
 ##############################################################################
 #
 #    OpenERP, Open Source Management Solution
-#    Copyright (c) 2010-2013 Elico Corp. All Rights Reserved.
+#    Copyright (c) 2010-2014 Elico Corp. All Rights Reserved.
 #    Augustin Cisterne-Kaas <augustin.cisterne-kaas@xxxxxxxxxxxxxx>
 #    Eric Caudal <eric.caudal@xxxxxxxxxxxxxx>
 
@@ -54,7 +54,10 @@
             'res.users', 'IC User',
             required=True,
             domain="[('company_id', '=', company_id)]",
-            help="User to create update unlink IC records")
+            help="User to create update unlink IC records"),
+        'model': fields.related(
+            'backend_to', 'icops_uid', type='many2one',
+            relation='res.users', readonly=True, string='IC User'),
     }
 
     _defaults = {

=== modified file 'base_intercompany/icops_model_view.xml'
--- base_intercompany/icops_model_view.xml	2014-01-17 13:12:23 +0000
+++ base_intercompany/icops_model_view.xml	2014-01-21 13:18:01 +0000
@@ -21,7 +21,7 @@
                         <field name="icops_ids" context="{'active_id': active_id}">
                             <tree editable="bottom">
                                 <field name="concept"/> 
-                                <field name="object_name" invisible="1" /> 
+                                <field name="model" /> 
                                 <field name="backend_id" invisible="1" />
                                 <field name="backend_to" />
                                 <field name='icops_uid' invisible="1" />

=== modified file 'base_intercompany/unit/__init__.py'
--- base_intercompany/unit/__init__.py	2014-01-17 13:12:23 +0000
+++ base_intercompany/unit/__init__.py	2014-01-21 13:18:01 +0000
@@ -2,7 +2,7 @@
 ##############################################################################
 #
 #    OpenERP, Open Source Management Solution
-#    Copyright (c) 2010-2013 Elico Corp. All Rights Reserved.
+#    Copyright (c) 2010-2014 Elico Corp. All Rights Reserved.
 #    Augustin Cisterne-Kaas <augustin.cisterne-kaas@xxxxxxxxxxxxxx>
 #    Eric Caudal <eric.caudal@xxxxxxxxxxxxxx>
 #

=== modified file 'base_intercompany/unit/backend_adapter.py'
--- base_intercompany/unit/backend_adapter.py	2014-01-17 13:12:23 +0000
+++ base_intercompany/unit/backend_adapter.py	2014-01-21 13:18:01 +0000
@@ -2,7 +2,7 @@
 ##############################################################################
 #
 #    OpenERP, Open Source Management Solution
-#    Copyright (c) 2010-2013 Elico Corp. All Rights Reserved.
+#    Copyright (c) 2010-2014 Elico Corp. All Rights Reserved.
 #    Augustin Cisterne-Kaas <augustin.cisterne-kaas@xxxxxxxxxxxxxx>
 #    Eric Caudal <eric.caudal@xxxxxxxxxxxxxx>
 
@@ -141,9 +141,11 @@
     def write(self, id, data):
         sess = self.session
         pool = self._get_pool()
-        pool.write(sess.cr, self._backend_to.icops_uid.id, id, data)
+        pool.write(sess.cr, self._backend_to.icops_uid.id, id, data,
+                   {'icops': True})
 
     def delete(self, id):
         sess = self.session
         pool = self._get_pool()
-        pool.unlink(sess.cr, self._backend_to.icops_uid.id, [id])
+        pool.unlink(sess.cr, self._backend_to.icops_uid.id, [id],
+                    {'icops': True})

=== modified file 'base_intercompany/unit/binder.py'
--- base_intercompany/unit/binder.py	2014-01-17 13:12:23 +0000
+++ base_intercompany/unit/binder.py	2014-01-21 13:18:01 +0000
@@ -2,7 +2,7 @@
 ##############################################################################
 #
 #    OpenERP, Open Source Management Solution
-#    Copyright (c) 2010-2013 Elico Corp. All Rights Reserved.
+#    Copyright (c) 2010-2014 Elico Corp. All Rights Reserved.
 #    Augustin Cisterne-Kaas <augustin.cisterne-kaas@xxxxxxxxxxxxxx>
 #    Eric Caudal <eric.caudal@xxxxxxxxxxxxxx>
 
@@ -86,7 +86,7 @@
         res = {}
         for icops in record.icops_ids:
             key = '%s_%s' % (icops.backend_id.id, icops.concept)
-            res[key] = icops.record_id
+            res[key] = {'id': icops.record_id}
         return res
 
     def bind(self, records, binding_id):
@@ -101,16 +101,17 @@
         if not records:
             return
         context = self.session.context.copy()
-        context['connector_no_export'] = True
+        context['icops'] = True
         now_fmt = datetime.now().strftime(DEFAULT_SERVER_DATETIME_FORMAT)
         icops_ids = []
         for record, record_id in records.items():
             backend_id, concept = record.split('_')
 
-            icops_id = (0, 0, {'record_id': record_id,
+            icops_id = (0, 0, {'record_id': record_id['id'],
                         'backend_id': backend_id,
                         'concept': concept,
-                        'binding_id': binding_id})
+                        'binding_id': binding_id,
+                        'model': record_id['model']})
             icops_ids.append(icops_id)
 
         self.environment.model.write(

=== modified file 'base_intercompany/unit/export_synchronizer.py'
--- base_intercompany/unit/export_synchronizer.py	2014-01-17 16:27:10 +0000
+++ base_intercompany/unit/export_synchronizer.py	2014-01-21 13:18:01 +0000
@@ -2,7 +2,7 @@
 ##############################################################################
 #
 #    OpenERP, Open Source Management Solution
-#    Copyright (c) 2010-2013 Elico Corp. All Rights Reserved.
+#    Copyright (c) 2010-2014 Elico Corp. All Rights Reserved.
 #    Augustin Cisterne-Kaas <augustin.cisterne-kaas@xxxxxxxxxxxxxx>
 #    Eric Caudal <eric.caudal@xxxxxxxxxxxxxx>
 
@@ -101,6 +101,8 @@
             icops = self.mapper._icops
             icops_id = self._get_icops_id(
                 icops.backend_to.id, icops.concept)
+            if not icops_id:
+                return
             if 'icops_delete' in fields:
                 self._delete(icops_id)
             else:
@@ -143,7 +145,10 @@
                 nb_records += 1
                 self._validate_data(record)
                 key = '%s_%s' % (icops.backend_to.id, icops.concept)
-                icops_ids[key] = self._create(record)
+                icops_ids[key] = {
+                    'id': self._create(record),
+                    'model': self.backend_adapter._get_pool()._name
+                }
 
         self.icops_ids = icops_ids
 
@@ -172,7 +177,7 @@
             sess.cr, sess.uid,
             [('backend_id', '=', backend_ids[0]),
              ('concept', 'in', self._concepts),
-             ('object_name', '=', self.binding_record.openerp_id._name)])
+             ('model', '=', self.binding_record.openerp_id._name)])
         res = intercompany_pool.browse(sess.cr, sess.uid, intercompany_ids)
         return res
 
@@ -188,7 +193,8 @@
         return self.backend_adapter.create(data)
 
     def _write(self, id, data):
-        if not self.backend_adapter._icops.on_write:
+        context = self.session.context or {}
+        if not self.backend_adapter._icops.on_write and not 'icops' in context:
             raise osv.except_osv('ICOPS Error', 'Can\'t write')
         self.backend_adapter.write(id, data)
 
@@ -223,7 +229,10 @@
 
     def _get_icops_id(self, backend_id, concept):
         key = '%s_%s' % (backend_id, concept)
-        return self.icops_ids[key]
+        try:
+            return self.icops_ids[key]['id']
+        except:
+            return None
 
 
 @job

=== modified file 'base_intercompany/unit/mapper.py'
--- base_intercompany/unit/mapper.py	2014-01-17 13:12:23 +0000
+++ base_intercompany/unit/mapper.py	2014-01-21 13:18:01 +0000
@@ -2,7 +2,7 @@
 ##############################################################################
 #
 #    OpenERP, Open Source Management Solution
-#    Copyright (c) 2010-2013 Elico Corp. All Rights Reserved.
+#    Copyright (c) 2010-2014 Elico Corp. All Rights Reserved.
 #    Augustin Cisterne-Kaas <augustin.cisterne-kaas@xxxxxxxxxxxxxx>
 #    Eric Caudal <eric.caudal@xxxxxxxxxxxxxx>
 

=== modified file 'base_intercompany_sale/__init__.py'
--- base_intercompany_sale/__init__.py	2014-01-17 13:12:23 +0000
+++ base_intercompany_sale/__init__.py	2014-01-21 13:18:01 +0000
@@ -2,7 +2,7 @@
 ##############################################################################
 #
 #    OpenERP, Open Source Management Solution
-#    Copyright (c) 2010-2013 Elico Corp. All Rights Reserved.
+#    Copyright (c) 2010-2014 Elico Corp. All Rights Reserved.
 #    Augustin Cisterne-Kaas <augustin.cisterne-kaas@xxxxxxxxxxxxxx>
 #    Eric Caudal <eric.caudal@xxxxxxxxxxxxxx>
 

=== modified file 'base_intercompany_sale/__openerp__.py'
--- base_intercompany_sale/__openerp__.py	2014-01-17 16:27:10 +0000
+++ base_intercompany_sale/__openerp__.py	2014-01-21 13:18:01 +0000
@@ -2,7 +2,7 @@
 ##############################################################################
 #
 #    OpenERP, Open Source Management Solution
-#    Copyright (c) 2010-2013 Elico Corp. All Rights Reserved.
+#    Copyright (c) 2010-2014 Elico Corp. All Rights Reserved.
 #    Augustin Cisterne-Kaas <augustin.cisterne-kaas@xxxxxxxxxxxxxx>
 #    Eric Caudal <eric.caudal@xxxxxxxxxxxxxx>
 

=== modified file 'base_intercompany_sale/company.py'
--- base_intercompany_sale/company.py	2014-01-17 13:12:23 +0000
+++ base_intercompany_sale/company.py	2014-01-21 13:18:01 +0000
@@ -2,7 +2,7 @@
 ##############################################################################
 #
 #    OpenERP, Open Source Management Solution
-#    Copyright (c) 2010-2013 Elico Corp. All Rights Reserved.
+#    Copyright (c) 2010-2014 Elico Corp. All Rights Reserved.
 #    Augustin Cisterne-Kaas <augustin.cisterne-kaas@xxxxxxxxxxxxxx>
 #    Eric Caudal <eric.caudal@xxxxxxxxxxxxxx>
 
@@ -37,12 +37,12 @@
                 ('po2so', 'PO to SO')]
         return res
 
-    def _select_object_names(self, cr, uid, context=None):
+    def _select_models(self, cr, uid, context=None):
         """ Available Object names
 
         Can be inherited to add custom versions.
         """
-        res = super(res_intercompany, self)._select_object_names(
+        res = super(res_intercompany, self)._select_models(
             cr, uid, context)
         new_dict = {'so2po': 'sale.order',
                     'so2so': 'sale.order',

=== modified file 'base_intercompany_sale/connector.py'
--- base_intercompany_sale/connector.py	2014-01-17 13:12:23 +0000
+++ base_intercompany_sale/connector.py	2014-01-21 13:18:01 +0000
@@ -2,7 +2,7 @@
 ##############################################################################
 #
 #    OpenERP, Open Source Management Solution
-#    Copyright (c) 2010-2013 Elico Corp. All Rights Reserved.
+#    Copyright (c) 2010-2014 Elico Corp. All Rights Reserved.
 #    Augustin Cisterne-Kaas <augustin.cisterne-kaas@xxxxxxxxxxxxxx>
 #    Eric Caudal <eric.caudal@xxxxxxxxxxxxxx>
 

=== modified file 'base_intercompany_sale/consumer.py'
--- base_intercompany_sale/consumer.py	2014-01-17 13:12:23 +0000
+++ base_intercompany_sale/consumer.py	2014-01-21 13:18:01 +0000
@@ -2,7 +2,7 @@
 ##############################################################################
 #
 #    OpenERP, Open Source Management Solution
-#    Copyright (c) 2010-2013 Elico Corp. All Rights Reserved.
+#    Copyright (c) 2010-2014 Elico Corp. All Rights Reserved.
 #    Augustin Cisterne-Kaas <augustin.cisterne-kaas@xxxxxxxxxxxxxx>
 #    Eric Caudal <eric.caudal@xxxxxxxxxxxxxx>
 

=== modified file 'base_intercompany_sale/icops_model.py'
--- base_intercompany_sale/icops_model.py	2014-01-17 16:27:10 +0000
+++ base_intercompany_sale/icops_model.py	2014-01-21 13:18:01 +0000
@@ -2,7 +2,7 @@
 ##############################################################################
 #
 #    OpenERP, Open Source Management Solution
-#    Copyright (c) 2010-2013 Elico Corp. All Rights Reserved.
+#    Copyright (c) 2010-2014 Elico Corp. All Rights Reserved.
 #    Augustin Cisterne-Kaas <augustin.cisterne-kaas@xxxxxxxxxxxxxx>
 #    Eric Caudal <eric.caudal@xxxxxxxxxxxxxx>
 

=== modified file 'base_intercompany_sale/purchase.py'
--- base_intercompany_sale/purchase.py	2014-01-17 13:12:23 +0000
+++ base_intercompany_sale/purchase.py	2014-01-21 13:18:01 +0000
@@ -2,7 +2,7 @@
 ##############################################################################
 #
 #    OpenERP, Open Source Management Solution
-#    Copyright (c) 2010-2013 Elico Corp. All Rights Reserved.
+#    Copyright (c) 2010-2014 Elico Corp. All Rights Reserved.
 #    Augustin Cisterne-Kaas <augustin.cisterne-kaas@xxxxxxxxxxxxxx>
 #    Eric Caudal <eric.caudal@xxxxxxxxxxxxxx>
 
@@ -32,7 +32,8 @@
 
 
 class purchase_order(orm.Model):
-    _inherit = 'purchase.order'
+    _name = 'purchase.order'
+    _inherit = ['purchase.order', 'icops.model']
 
     _columns = {
         'openerp_id': fields.many2one('purchase.order',
@@ -57,6 +58,14 @@
             'icops.backend').prepare_binding(cr, uid, data, context)
         return super(purchase_order, self).create(cr, uid, data, context)
 
+    def write(self, cr, uid, ids, data, context=None):
+        self._check_icops(cr, uid, ids, context=context)
+        return super(purchase_order, self).write(cr, uid, ids, data, context)
+
+    def unlink(self, cr, uid, ids, context=None):
+        self._check_icops(cr, uid, ids, context=context)
+        return super(purchase_order, self).unlink(cr, uid, ids, context)
+
 
 class icops_purchase_order(orm.Model):
     _name = 'icops.purchase.order'
@@ -153,13 +162,27 @@
     def confirm(self, id):
         sess = self.session
         pool = self._get_pool()
+        context = {'icops': True}
+        pool.write(
+            sess.cr, self._backend_to.icops_uid.id, [id],
+            {'temp_unlock': True}, context=context)
         pool.action_wait(
             sess.cr, self._backend_to.icops_uid.id, [id])
+        pool.write(
+            sess.cr, self._backend_to.icops_uid.id, [id],
+            {'temp_unlock': False}, context=context)
 
     def cancel(self, id):
         sess = self.session
         pool = self._get_pool()
+        context = {'icops': True}
+        pool.write(
+            sess.cr, self._backend_to.icops_uid.id, [id],
+            {'temp_unlock': True}, context=context)
         pool.action_cancel(sess.cr, self._backend_to.icops_uid.id, [id])
+        pool.write(
+            sess.cr, self._backend_to.icops_uid.id, [id],
+            {'temp_unlock': False}, context=context)
 
 
 @icops

=== modified file 'base_intercompany_sale/purchase_view.xml'
--- base_intercompany_sale/purchase_view.xml	2014-01-17 13:12:23 +0000
+++ base_intercompany_sale/purchase_view.xml	2014-01-21 13:18:01 +0000
@@ -6,8 +6,12 @@
             <field name="model">purchase.order</field>
             <field name="inherit_id" ref="purchase.purchase_order_form" />
             <field name="arch" type="xml">
-                <page string="Purchase Order" position="after">
+                <xpath expr="//header/button[last()]" position="after">
+                    <button name="action_unlock" string="Unlock" type="object" attrs="{'invisible':[('locked', '=', False)]}" class="oe_highlight" />
+                </xpath>
+                <xpath expr="//page[last()]" position="after">
                     <page string="ICOPS">
+                        <field name="locked" invisible="1" />
                         <field name="icops_bind_ids">
                             <tree string="ICOPS Backend" editable="bottom">
                                 <field name="backend_id" />
@@ -15,7 +19,7 @@
                             </tree>
                         </field>
                     </page>
-                </page>
+                </xpath>
             </field>
         </record>
     </data>

=== modified file 'base_intercompany_sale/sale.py'
--- base_intercompany_sale/sale.py	2014-01-17 13:12:23 +0000
+++ base_intercompany_sale/sale.py	2014-01-21 13:18:01 +0000
@@ -2,7 +2,7 @@
 ##############################################################################
 #
 #    OpenERP, Open Source Management Solution
-#    Copyright (c) 2010-2013 Elico Corp. All Rights Reserved.
+#    Copyright (c) 2010-2014 Elico Corp. All Rights Reserved.
 #    Augustin Cisterne-Kaas <augustin.cisterne-kaas@xxxxxxxxxxxxxx>
 #    Eric Caudal <eric.caudal@xxxxxxxxxxxxxx>
 
@@ -31,7 +31,8 @@
 
 
 class sale_order(orm.Model):
-    _inherit = 'sale.order'
+    _name = 'sale.order'
+    _inherit = ['sale.order', 'icops.model']
 
     _columns = {
         'openerp_id': fields.many2one('sale.order',
@@ -56,6 +57,19 @@
             'icops.backend').prepare_binding(cr, uid, data, context)
         return super(sale_order, self).create(cr, uid, data, context)
 
+    def write(self, cr, uid, ids, data, context=None):
+        print "\n\n"
+        print ids
+        print data
+        print context
+        print "\n\n"
+        self._check_icops(cr, uid, ids, context=context)
+        return super(sale_order, self).write(cr, uid, ids, data, context)
+
+    def unlink(self, cr, uid, ids, context=None):
+        self._check_icops(cr, uid, ids, context=context)
+        return super(sale_order, self).unlink(cr, uid, ids, context)
+
 
 class icops_sale_order(orm.Model):
     _name = 'icops.sale.order'
@@ -155,17 +169,31 @@
     def confirm(self, id):
         sess = self.session
         pool = self._get_pool()
+        context = {'icops': True}
+        pool.write(
+            sess.cr, self._backend_to.icops_uid.id, [id],
+            {'temp_unlock': True}, context)
         if hasattr(pool, 'wkf_confirm_order'):
             pool.wkf_confirm_order(
                 sess.cr, self._backend_to.icops_uid.id, [id])
         else:
             pool.action_wait(
                 sess.cr, self._backend_to.icops_uid.id, [id])
+        pool.write(
+            sess.cr, self._backend_to.icops_uid.id, [id],
+            {'temp_unlock': False}, context)
 
     def cancel(self, id):
         sess = self.session
         pool = self._get_pool()
+        context = {'icops': True}
+        pool.write(
+            sess.cr, self._backend_to.icops_uid.id, [id],
+            {'temp_unlock': True}, context)
         pool.action_cancel(sess.cr, self._backend_to.icops_uid.id, [id])
+        pool.write(
+            sess.cr, self._backend_to.icops_uid.id, [id],
+            {'temp_unlock': False}, context)
 
 
 @icops

=== modified file 'base_intercompany_sale/sale_view.xml'
--- base_intercompany_sale/sale_view.xml	2014-01-17 13:12:23 +0000
+++ base_intercompany_sale/sale_view.xml	2014-01-21 13:18:01 +0000
@@ -6,8 +6,12 @@
             <field name="model">sale.order</field>
             <field name="inherit_id" ref="sale.view_order_form" />
             <field name="arch" type="xml">
-                <page string="Order Lines" position="after">
+                <xpath expr="//header/button[last()]" position="after">
+                    <button name="action_unlock" string="Unlock" type="object" attrs="{'invisible':[('locked', '=', False)]}" class="oe_highlight" />
+                </xpath>
+                <xpath expr="//page[last()]" position="after">
                     <page string="ICOPS">
+                        <field name="locked" invisible="1" />
                         <field name="icops_bind_ids">
                             <tree string="ICOPS Backend" editable="bottom">
                                 <field name="backend_id" />
@@ -15,7 +19,7 @@
                             </tree>
                         </field>
                     </page>
-                </page>
+                </xpath>
             </field>
         </record>
     </data>


Follow ups