openerp-community team mailing list archive
-
openerp-community team
-
Mailing list archive
-
Message #04971
[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:
LIN Yu (lin-yu)
For more details, see:
https://code.launchpad.net/~ajite/openobject-addons/elico-7.0-imp-intercompany-000001/+merge/207113
Made this module compatible with the latest version of the connector (Version > 2.0.1)
--
https://code.launchpad.net/~ajite/openobject-addons/elico-7.0-imp-intercompany-000001/+merge/207113
Your team OpenERP Community is subscribed to branch lp:~openerp-community/openobject-addons/elico-7.0.
=== modified file 'base_intercompany/__openerp__.py'
--- base_intercompany/__openerp__.py 2014-01-17 22:42:32 +0000
+++ base_intercompany/__openerp__.py 2014-02-19 08:51:05 +0000
@@ -22,7 +22,7 @@
##############################################################################
{'name': 'Base Intercompany',
- 'version': '0.3',
+ 'version': '0.4',
'category': 'Generic Modules',
'depends': ['connector'],
'author': 'Elico Corp',
=== modified file 'base_intercompany/unit/export_synchronizer.py'
--- base_intercompany/unit/export_synchronizer.py 2014-01-18 20:51:09 +0000
+++ base_intercompany/unit/export_synchronizer.py 2014-02-19 08:51:05 +0000
@@ -124,26 +124,26 @@
nb_records = 0
icops_ids = {}
+
for icops in self._get_icops():
backend = self._get_backend_with_permission(icops)
self._set_icops(icops, backend)
try:
- self._map_data(fields=fields)
+ map_record = self._map_data(fields=fields)
except MappingError as e:
continue
if self.icops_ids:
- record = self.mapper.data
+ record = self._update_data(map_record, fields=fields)
if not record:
continue
nb_records += 1
self._validate_data(record)
self._routing(record, fields)
else:
- record = self.mapper.data_for_create
+ record = self._create_data(map_record, fields=fields)
if not record:
continue
nb_records += 1
- self._validate_data(record)
key = '%s_%s' % (icops.backend_to.id, icops.concept)
icops_ids[key] = {
'id': self._create(record),
@@ -183,13 +183,14 @@
def _set_icops(self, icops, backend):
self.mapper._icops = icops
+ self.mapper._backend_to = backend
self.backend_adapter._icops = icops
- self.mapper._backend_to = backend
self.backend_adapter._backend_to = backend
def _create(self, data):
if not self.backend_adapter._icops.on_create:
raise osv.except_osv('ICOPS Error', 'Can\'t create')
+ self._validate_data(data)
return self.backend_adapter.create(data)
def _write(self, id, data):
@@ -215,7 +216,15 @@
def _map_data(self, fields=None):
""" Convert the external record to OpenERP """
- self.mapper.convert(self.binding_record, fields=fields)
+ return self.mapper.map_record(self.binding_record)
+
+ def _create_data(self, map_record, fields=None, **kwargs):
+ """ Get the data to pass to :py:meth:`_create` """
+ return map_record.values(for_create=True, fields=fields, **kwargs)
+
+ def _update_data(self, map_record, fields=None, **kwargs):
+ """ Get the data to pass to :py:meth:`_update` """
+ return map_record.values(fields=fields, **kwargs)
def _validate_data(self, data):
""" Check if the values to export are correct
=== modified file 'base_intercompany/unit/mapper.py'
--- base_intercompany/unit/mapper.py 2014-01-17 22:42:32 +0000
+++ base_intercompany/unit/mapper.py 2014-02-19 08:51:05 +0000
@@ -20,10 +20,27 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
-from openerp.addons.connector.unit.mapper import ExportMapper
+from openerp.addons.connector.unit.mapper import (ExportMapper, ExportMapChild)
+
+
+class ICOPSExportMapChild(ExportMapChild):
+ """ :py:class:`MapChild` for the Exports """
+
+ def _child_mapper(self):
+ mapper = self.get_connector_unit_for_model(
+ ExportMapper, self.model._name)
+ mapper._icops = self._icops
+ mapper._backend_to = self._backend_to
+ return mapper
+
+ def format_items(self, items_values):
+ items = super(ICOPSExportMapChild, self).format_items(items_values)
+ return [(5, 0)] + [(0, 0, data) for data in items]
class ICOPSExportMapper(ExportMapper):
+ _map_child_class = ICOPSExportMapChild
+
def __init__(self, environment):
"""
@@ -34,11 +51,8 @@
self._icops = None
self._backend_to = None
- def _format_child_rows(self, child_records):
- return [(5, 0)] + [(0, 0, data) for data in child_records]
-
- def _init_child_mapper(self, model_name):
- mapper = super(ICOPSExportMapper, self)._init_child_mapper(model_name)
+ def _get_map_child_unit(self, model_name):
+ mapper = super(ICOPSExportMapper, self)._get_map_child_unit(model_name)
mapper._icops = self._icops
mapper._backend_to = self._backend_to
return mapper
=== modified file 'base_intercompany_sale/__openerp__.py'
--- base_intercompany_sale/__openerp__.py 2014-01-17 22:42:32 +0000
+++ base_intercompany_sale/__openerp__.py 2014-02-19 08:51:05 +0000
@@ -22,7 +22,7 @@
##############################################################################
{'name': 'Base Intercompany Sale',
- 'version': '0.3',
+ 'version': '0.4',
'category': 'Sales Management',
'depends': ['base_intercompany', 'sale', 'purchase'],
'author': 'Elico Corp',
=== modified file 'base_intercompany_sale/purchase.py'
--- base_intercompany_sale/purchase.py 2014-01-18 20:51:09 +0000
+++ base_intercompany_sale/purchase.py 2014-02-19 08:51:05 +0000
@@ -266,11 +266,10 @@
class PurchaseOrderLineExportMapper(ICOPSExportMapper):
_model_name = 'icops.purchase.order.line'
- direct = [('name', 'name')]
-
@mapping
def product(self, record):
return {
+ 'name': record.name,
'product_id': record.product_id.id,
'product_uom': record.product_uom.id,
'product_uom_qty': record.product_qty
=== modified file 'base_intercompany_sale/sale.py'
--- base_intercompany_sale/sale.py 2014-01-18 20:51:09 +0000
+++ base_intercompany_sale/sale.py 2014-02-19 08:51:05 +0000
@@ -327,7 +327,9 @@
class SaleOrderLineExportMapper(ICOPSExportMapper):
_model_name = 'icops.sale.order.line'
- direct = [('name', 'name')]
+ @mapping
+ def name(self, record):
+ return {'name': record.name}
def _price(self, record, is_po=False):
if not record.product_id:
Follow ups