← Back to team overview

savoirfairelinux-openerp team mailing list archive

[Merge] lp:~savoirfairelinux-openerp/openerp-connector-magento/7.0_feature_choose_import_company into lp:openerp-connector-magento

 

Vincent Vinet has proposed merging lp:~savoirfairelinux-openerp/openerp-connector-magento/7.0_feature_choose_import_company into lp:openerp-connector-magento.

Requested reviews:
  OpenERP Connector Core Editors (openerp-connector-core-editors)

For more details, see:
https://code.launchpad.net/~savoirfairelinux-openerp/openerp-connector-magento/7.0_feature_choose_import_company/+merge/223480

This branch adds a "Company" field to the connector's "Magento Website" model that allows choosing which company products and partners that are imported will be assigned to.

Since Magento products can belong to multiple websites, the current way to resolve this is to raise a MappingError since Odoo does not accept a product belonging to multiple companies (it has to belong into a single warehouse). This has no effect if no company was set on websites, so it does not change existing behavior when not used.
-- 
https://code.launchpad.net/~savoirfairelinux-openerp/openerp-connector-magento/7.0_feature_choose_import_company/+merge/223480
Your team Savoir-faire Linux' OpenERP is subscribed to branch lp:~savoirfairelinux-openerp/openerp-connector-magento/7.0_feature_choose_import_company.
=== modified file 'magentoerpconnect/magento_model.py'
--- magentoerpconnect/magento_model.py	2014-05-26 10:57:10 +0000
+++ magentoerpconnect/magento_model.py	2014-06-17 21:39:29 +0000
@@ -346,6 +346,10 @@
         'product_binding_ids': fields.many2many('magento.product.product',
                                                 string='Magento Products',
                                                 readonly=True),
+        'company_id':  fields.many2one(
+            'res.company',
+            'Company',
+            help="Company to which objects imported from this store belong"),
     }
 
     _sql_constraints = [

=== modified file 'magentoerpconnect/magento_model_view.xml'
--- magentoerpconnect/magento_model_view.xml	2014-05-26 09:37:00 +0000
+++ magentoerpconnect/magento_model_view.xml	2014-06-17 21:39:29 +0000
@@ -64,6 +64,21 @@
                                     of the new records to review
                                     in the menu 'Connectors > Checkpoint'.
                                 </p>
+                                <p class="oe_grey oe_inline">
+                                  If you need to configure the import company
+                                  for websites in a multi-company environment,
+                                  you should first synchronize the metadata and
+                                  then configure the websites.
+                                </p>
+                                <group>
+                                    <label string="Update websites and stores" class="oe_inline"/>
+                                    <div>
+                                        <button name="update_website_stores"
+                                            type="object"
+                                            class="oe_highlight"
+                                            string="Update"/>
+                                    </div>
+                                </group>
                                 <group>
                                     <label string="Import all customer groups" class="oe_inline"/>
                                     <div>
@@ -189,6 +204,7 @@
                             <field name="sort_order"/>
                         </group>
                         <group string="Options" name="options">
+                            <field name="company_id" />
                         </group>
                         <notebook>
                             <page name="import" string="Imports">

=== modified file 'magentoerpconnect/partner.py'
--- magentoerpconnect/partner.py	2014-05-26 09:37:00 +0000
+++ magentoerpconnect/partner.py	2014-06-17 21:39:29 +0000
@@ -306,6 +306,7 @@
             ('email', 'emailid'),
             ('taxvat', 'taxvat'),
             ('group_id', 'group_id'),
+            ('company_id', 'company_id'),
         ]
 
     @only_create
@@ -342,7 +343,16 @@
     def website_id(self, record):
         binder = self.get_binder_for_model('magento.website')
         website_id = binder.to_openerp(record['website_id'])
-        return {'website_id': website_id}
+        res = {'website_id': website_id}
+
+        company_id = binder.session.read(binder.model._name,
+                                         website_id,
+                                         ["company_id"])["company_id"]
+        if company_id:
+            # We received (id, name)
+            res['company_id'] = company_id[0]
+        return res
+
 
     @mapping
     def lang(self, record):

=== modified file 'magentoerpconnect/product.py'
--- magentoerpconnect/product.py	2014-06-14 20:30:26 +0000
+++ magentoerpconnect/product.py	2014-06-17 21:39:29 +0000
@@ -452,11 +452,33 @@
     @mapping
     def website_ids(self, record):
         website_ids = []
+        company_ids = []
         binder = self.get_binder_for_model('magento.website')
         for mag_website_id in record['websites']:
             website_id = binder.to_openerp(mag_website_id)
             website_ids.append((4, website_id))
-        return {'website_ids': website_ids}
+
+            company_id = binder.session.read(binder.model._name,
+                                             website_id,
+                                             ["company_id"])["company_id"]
+            if company_id:
+                company_ids.append(company_id)
+
+        res = {'website_ids': website_ids}
+
+        if company_ids:
+            if len(company_ids) > 1:
+                raise MappingError("The product with magento id %s cannot be "
+                                   "imported because it would belong to more "
+                                   "than one company, and we can't allow that." %
+                                   (record.get('product_id', "N/A"), ),
+                                   )
+
+            res['company_id'] = company_id[0]
+
+        # TODO Should we set this to False to get default otherwise?
+
+        return res
 
     @mapping
     def categories(self, record):


Follow ups