Merge lp:~savoirfairelinux-openerp/openerp-connector-magento/7.0_feature_choose_import_company into lp:~openerp-connector-core-editors/openerp-connector-magento/7.0

Proposed by Vincent Vinet
Status: Needs review
Proposed branch: lp:~savoirfairelinux-openerp/openerp-connector-magento/7.0_feature_choose_import_company
Merge into: lp:~openerp-connector-core-editors/openerp-connector-magento/7.0
Diff against target: 117 lines (+54/-2)
4 files modified
magentoerpconnect/magento_model.py (+4/-0)
magentoerpconnect/magento_model_view.xml (+16/-0)
magentoerpconnect/partner.py (+11/-1)
magentoerpconnect/product.py (+23/-1)
To merge this branch: bzr merge lp:~savoirfairelinux-openerp/openerp-connector-magento/7.0_feature_choose_import_company
Reviewer Review Type Date Requested Status
Guewen Baconnier @ Camptocamp Needs Resubmitting
Review via email: mp+223480@code.launchpad.net

Description of the change

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.

To post a comment you must log in.
Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

Hi,

thanks for your proposal!

This is a good start but incomplete. When a record is imported for a company, it should be imported with a user that belongs to this company, so the property fields (accounts, ...) are set correctly according to the user's company.

Here is an example: https://gist.github.com/guewen/3528fe4be6bf527ed9d9
1. each company has a "connector user" that will be used for the imports for this company
2. before the import (the part that maps and store the data), we search the company for the record to import
3. we switch the current user to the user configured on the company (1.) to run the import, so the properties are defined correctly

Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

This project is now hosted on https://github.com/OCA/connector-magento. Please move your proposal there. This guide may help you https://github.com/OCA/maintainers-tools/wiki/How-to-move-a-Merge-Proposal-to-GitHub

review: Needs Resubmitting

Unmerged revisions

1004. By Vincent Vinet

[IMP] make help text more helpful/accurate

1003. By Vincent Vinet

[IMP] multi-company settings on websites

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== 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 @@
346 'product_binding_ids': fields.many2many('magento.product.product',346 'product_binding_ids': fields.many2many('magento.product.product',
347 string='Magento Products',347 string='Magento Products',
348 readonly=True),348 readonly=True),
349 'company_id': fields.many2one(
350 'res.company',
351 'Company',
352 help="Company to which objects imported from this store belong"),
349 }353 }
350354
351 _sql_constraints = [355 _sql_constraints = [
352356
=== 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 @@
64 of the new records to review64 of the new records to review
65 in the menu 'Connectors > Checkpoint'.65 in the menu 'Connectors > Checkpoint'.
66 </p>66 </p>
67 <p class="oe_grey oe_inline">
68 If you need to configure the import company
69 for websites in a multi-company environment,
70 you should first synchronize the metadata and
71 then configure the websites.
72 </p>
73 <group>
74 <label string="Update websites and stores" class="oe_inline"/>
75 <div>
76 <button name="update_website_stores"
77 type="object"
78 class="oe_highlight"
79 string="Update"/>
80 </div>
81 </group>
67 <group>82 <group>
68 <label string="Import all customer groups" class="oe_inline"/>83 <label string="Import all customer groups" class="oe_inline"/>
69 <div>84 <div>
@@ -189,6 +204,7 @@
189 <field name="sort_order"/>204 <field name="sort_order"/>
190 </group>205 </group>
191 <group string="Options" name="options">206 <group string="Options" name="options">
207 <field name="company_id" />
192 </group>208 </group>
193 <notebook>209 <notebook>
194 <page name="import" string="Imports">210 <page name="import" string="Imports">
195211
=== 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 @@
306 ('email', 'emailid'),306 ('email', 'emailid'),
307 ('taxvat', 'taxvat'),307 ('taxvat', 'taxvat'),
308 ('group_id', 'group_id'),308 ('group_id', 'group_id'),
309 ('company_id', 'company_id'),
309 ]310 ]
310311
311 @only_create312 @only_create
@@ -342,7 +343,16 @@
342 def website_id(self, record):343 def website_id(self, record):
343 binder = self.get_binder_for_model('magento.website')344 binder = self.get_binder_for_model('magento.website')
344 website_id = binder.to_openerp(record['website_id'])345 website_id = binder.to_openerp(record['website_id'])
345 return {'website_id': website_id}346 res = {'website_id': website_id}
347
348 company_id = binder.session.read(binder.model._name,
349 website_id,
350 ["company_id"])["company_id"]
351 if company_id:
352 # We received (id, name)
353 res['company_id'] = company_id[0]
354 return res
355
346356
347 @mapping357 @mapping
348 def lang(self, record):358 def lang(self, record):
349359
=== 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 @@
452 @mapping452 @mapping
453 def website_ids(self, record):453 def website_ids(self, record):
454 website_ids = []454 website_ids = []
455 company_ids = []
455 binder = self.get_binder_for_model('magento.website')456 binder = self.get_binder_for_model('magento.website')
456 for mag_website_id in record['websites']:457 for mag_website_id in record['websites']:
457 website_id = binder.to_openerp(mag_website_id)458 website_id = binder.to_openerp(mag_website_id)
458 website_ids.append((4, website_id))459 website_ids.append((4, website_id))
459 return {'website_ids': website_ids}460
461 company_id = binder.session.read(binder.model._name,
462 website_id,
463 ["company_id"])["company_id"]
464 if company_id:
465 company_ids.append(company_id)
466
467 res = {'website_ids': website_ids}
468
469 if company_ids:
470 if len(company_ids) > 1:
471 raise MappingError("The product with magento id %s cannot be "
472 "imported because it would belong to more "
473 "than one company, and we can't allow that." %
474 (record.get('product_id', "N/A"), ),
475 )
476
477 res['company_id'] = company_id[0]
478
479 # TODO Should we set this to False to get default otherwise?
480
481 return res
460482
461 @mapping483 @mapping
462 def categories(self, record):484 def categories(self, record):