-
-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f02affb
commit ffe6c51
Showing
9 changed files
with
273 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg | ||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
:alt: License: AGPL-3 | ||
|
||
==================================================== | ||
Magento Connector - Configurable Product | ||
==================================================== | ||
|
||
This modules aims to create configurable products as Product templates and | ||
linked ProductProduct and not flat ProductProduct | ||
|
||
Installation | ||
============ | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
#Bugs are tracked on `GitHub Issues | ||
#<https://github.com/OCA/connector-magento/issues>`_. In case of trouble, please | ||
#check there if your issue has already been reported. If you spotted it first, | ||
#help us smashing it by providing a detailed and welcomed feedback. | ||
|
||
Credits | ||
======= | ||
|
||
Images | ||
------ | ||
|
||
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_. | ||
|
||
Contributors | ||
------------ | ||
|
||
|
||
Maintainer | ||
---------- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# -*- coding: utf-8 -*- | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2017 Camptocamp SA | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) | ||
|
||
{'name': 'Magento Connector - Configurable', | ||
'version': '10.0.1.0.0', | ||
'author': 'Akretion,Odoo Community Association (OCA)', | ||
'license': 'AGPL-3', | ||
'category': 'Hidden', | ||
'depends': ['connector_magento'], | ||
'data': [], | ||
'installable': True, | ||
'auto_install': True, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
from . import configurable | ||
from . import product_attribute |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2017 Camptocamp SA | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) | ||
|
||
from odoo.addons.component.core import Component | ||
# from odoo.addons.connector.components.mapper import mapping | ||
from odoo.addons.connector.exception import InvalidDataError | ||
|
||
|
||
class ConfigurableImporter(Component): | ||
_inherit = 'magento.product.configurable.importer' | ||
|
||
def run(self, binding, magento_record): | ||
super(ConfigurableImporter, self).run( | ||
binding, | ||
magento_record) | ||
|
||
# ne pas enlever pour dev | ||
raise InvalidDataError('THE END', magento_record) | ||
|
||
|
||
class ProductImporter(Component): | ||
_inherit = 'magento.product.product.importer' | ||
|
||
def _must_skip(self): | ||
res = super(ProductImporter, self)._must_skip() | ||
if self.magento_record['type_id'] != 'configurable': | ||
return res |
3 changes: 3 additions & 0 deletions
3
connector_magento_configurable/models/product_attribute/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
from . import common | ||
from . import importer |
64 changes: 64 additions & 0 deletions
64
connector_magento_configurable/models/product_attribute/common.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2013-2017 Camptocamp SA | ||
# © 2016 Sodexis | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
import logging | ||
import xmlrpclib | ||
from odoo import models, fields | ||
from odoo.addons.connector.exception import IDMissingInBackend | ||
from odoo.addons.component.core import Component | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
class MagentoProductAttribute(models.Model): | ||
_name = 'magento.product.attribute' | ||
_inherit = 'magento.binding' | ||
_inherits = {'product.attribute': 'odoo_id'} | ||
_description = 'Magento Product Attribute' | ||
|
||
odoo_id = fields.Many2one( | ||
comodel_name='product.attribute', | ||
string='Product Attribute', | ||
required=True, | ||
ondelete='cascade') | ||
name = fields.Text(translate=True) | ||
|
||
|
||
class ProductAttribute(models.Model): | ||
_inherit = 'product.attribute' | ||
|
||
magento_bind_ids = fields.One2many( | ||
comodel_name='magento.product.attribute', | ||
inverse_name='odoo_id', | ||
string="Magento Bindings", | ||
) | ||
|
||
|
||
class ProductAttributeAdapter(Component): | ||
_name = 'magento.product.attribute.adapter' | ||
_inherit = 'magento.adapter' | ||
_apply_on = 'magento.product.attribute' | ||
|
||
_magento_model = 'ol_catalog_product_link' | ||
_admin_path = '/{model}/index/' | ||
|
||
def _call(self, method, arguments): | ||
try: | ||
return super(ProductAttributeAdapter, self)._call(method, arguments) | ||
except xmlrpclib.Fault as err: | ||
# 101 is the error in the Magento API | ||
# when the attribute does not exist | ||
if err.faultCode == 102: | ||
raise IDMissingInBackend | ||
else: | ||
raise | ||
|
||
def list_attributes(self, id, storeview_id=None, attributes=None): | ||
""" Returns the information of a record | ||
:rtype: dict | ||
""" | ||
return self._call('%s.listSuperAttributes' % self._magento_model, | ||
[int(id), storeview_id, attributes]) |
78 changes: 78 additions & 0 deletions
78
connector_magento_configurable/models/product_attribute/importer.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2013-2017 Camptocamp SA | ||
# © 2016 Sodexis | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) | ||
|
||
from odoo.addons.component.core import Component | ||
from odoo.addons.connector.components.mapper import mapping | ||
# from odoo.addons.connector.exception import MappingError | ||
|
||
|
||
class ProductAttributeBatchImporter(Component): | ||
""" Import the Magento Product Attributes. | ||
For every product attribute in the list, a delayed job is created. | ||
A priority is set on the jobs according to their level to rise the | ||
chance to have the top level attributes imported first. | ||
""" | ||
_name = 'magento.product.attribute.batch.importer' | ||
_inherit = 'magento.delayed.batch.importer' | ||
_apply_on = ['magento.product.attribute'] | ||
|
||
def _import_record(self, external_id, job_options=None): | ||
""" Delay a job for the import """ | ||
super(ProductAttributeBatchImporter, self)._import_record( | ||
external_id, job_options=job_options | ||
) | ||
|
||
def run(self, filters=None): | ||
""" Run the synchronization """ | ||
updated_ids = self.backend_adapter.listSuperAttributes() | ||
|
||
base_priority = 10 | ||
|
||
def import_nodes(tree, level=0): | ||
for node_id, children in tree.iteritems(): | ||
# By changing the priority, the top level attribute has | ||
# more chance to be imported before the childrens. | ||
# However, importers have to ensure that their parent is | ||
# there and import it if it doesn't exist | ||
if updated_ids is None or node_id in updated_ids: | ||
job_options = { | ||
'priority': base_priority + level, | ||
} | ||
self._import_record( | ||
node_id, job_options=job_options) | ||
import_nodes(children, level=level + 1) | ||
tree = self.backend_adapter.tree() | ||
import_nodes(tree) | ||
|
||
|
||
class ProductAttributeImporter(Component): | ||
_name = 'magento.product.attribute.importer' | ||
_inherit = 'magento.importer' | ||
_apply_on = ['magento.product.attribute'] | ||
|
||
def _create(self, data): | ||
binding = super(ProductAttributeImporter, self)._create(data) | ||
self.backend_record.add_checkpoint(binding) | ||
return binding | ||
|
||
def _after_import(self, binding): | ||
""" Hook called at the end of the import """ | ||
translation_importer = self.component(usage='translation.importer') | ||
translation_importer.run(self.external_id, binding) | ||
|
||
|
||
class ProductAttributeImportMapper(Component): | ||
_name = 'magento.product.attribute.import.mapper' | ||
_inherit = 'magento.import.mapper' | ||
_apply_on = 'magento.product.attribute' | ||
|
||
direct = [ | ||
('name', 'name'), | ||
] | ||
|
||
@mapping | ||
def backend_id(self, record): | ||
return {'backend_id': self.backend_record.id} |