← Back to team overview

savoirfairelinux-openerp team mailing list archive

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

 

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

Diff comments:

> === 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"

What is that?

> +                                            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'),

Why is 'company_id' here?

>          ]
>  
>      @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,

self.session seems more natural than binder.session even if this is the same session

> +                                         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 "

Another possibility could be to share them globally when they belong to several companies but I am not sure what is the best

> +                                   "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?

If set to False, it will be shared globally. That's maybe what we want though.

> +
> +        return res
>  
>      @mapping
>      def categories(self, record):
> 


-- 
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.


References