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
1=== modified file 'magentoerpconnect/magento_model.py'
2--- magentoerpconnect/magento_model.py 2014-05-26 10:57:10 +0000
3+++ magentoerpconnect/magento_model.py 2014-06-17 21:39:29 +0000
4@@ -346,6 +346,10 @@
5 'product_binding_ids': fields.many2many('magento.product.product',
6 string='Magento Products',
7 readonly=True),
8+ 'company_id': fields.many2one(
9+ 'res.company',
10+ 'Company',
11+ help="Company to which objects imported from this store belong"),
12 }
13
14 _sql_constraints = [
15
16=== modified file 'magentoerpconnect/magento_model_view.xml'
17--- magentoerpconnect/magento_model_view.xml 2014-05-26 09:37:00 +0000
18+++ magentoerpconnect/magento_model_view.xml 2014-06-17 21:39:29 +0000
19@@ -64,6 +64,21 @@
20 of the new records to review
21 in the menu 'Connectors > Checkpoint'.
22 </p>
23+ <p class="oe_grey oe_inline">
24+ If you need to configure the import company
25+ for websites in a multi-company environment,
26+ you should first synchronize the metadata and
27+ then configure the websites.
28+ </p>
29+ <group>
30+ <label string="Update websites and stores" class="oe_inline"/>
31+ <div>
32+ <button name="update_website_stores"
33+ type="object"
34+ class="oe_highlight"
35+ string="Update"/>
36+ </div>
37+ </group>
38 <group>
39 <label string="Import all customer groups" class="oe_inline"/>
40 <div>
41@@ -189,6 +204,7 @@
42 <field name="sort_order"/>
43 </group>
44 <group string="Options" name="options">
45+ <field name="company_id" />
46 </group>
47 <notebook>
48 <page name="import" string="Imports">
49
50=== modified file 'magentoerpconnect/partner.py'
51--- magentoerpconnect/partner.py 2014-05-26 09:37:00 +0000
52+++ magentoerpconnect/partner.py 2014-06-17 21:39:29 +0000
53@@ -306,6 +306,7 @@
54 ('email', 'emailid'),
55 ('taxvat', 'taxvat'),
56 ('group_id', 'group_id'),
57+ ('company_id', 'company_id'),
58 ]
59
60 @only_create
61@@ -342,7 +343,16 @@
62 def website_id(self, record):
63 binder = self.get_binder_for_model('magento.website')
64 website_id = binder.to_openerp(record['website_id'])
65- return {'website_id': website_id}
66+ res = {'website_id': website_id}
67+
68+ company_id = binder.session.read(binder.model._name,
69+ website_id,
70+ ["company_id"])["company_id"]
71+ if company_id:
72+ # We received (id, name)
73+ res['company_id'] = company_id[0]
74+ return res
75+
76
77 @mapping
78 def lang(self, record):
79
80=== modified file 'magentoerpconnect/product.py'
81--- magentoerpconnect/product.py 2014-06-14 20:30:26 +0000
82+++ magentoerpconnect/product.py 2014-06-17 21:39:29 +0000
83@@ -452,11 +452,33 @@
84 @mapping
85 def website_ids(self, record):
86 website_ids = []
87+ company_ids = []
88 binder = self.get_binder_for_model('magento.website')
89 for mag_website_id in record['websites']:
90 website_id = binder.to_openerp(mag_website_id)
91 website_ids.append((4, website_id))
92- return {'website_ids': website_ids}
93+
94+ company_id = binder.session.read(binder.model._name,
95+ website_id,
96+ ["company_id"])["company_id"]
97+ if company_id:
98+ company_ids.append(company_id)
99+
100+ res = {'website_ids': website_ids}
101+
102+ if company_ids:
103+ if len(company_ids) > 1:
104+ raise MappingError("The product with magento id %s cannot be "
105+ "imported because it would belong to more "
106+ "than one company, and we can't allow that." %
107+ (record.get('product_id', "N/A"), ),
108+ )
109+
110+ res['company_id'] = company_id[0]
111+
112+ # TODO Should we set this to False to get default otherwise?
113+
114+ return res
115
116 @mapping
117 def categories(self, record):