-
-
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 37664ea
Showing
12 changed files
with
356 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,17 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2017 Akretion | ||
# 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': [ | ||
# 'security/ir.model.access.csv', | ||
'views/magento_backend_views.xml', | ||
], | ||
'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,4 @@ | ||
# -*- coding: utf-8 -*- | ||
from . import configurable | ||
from . import inherits | ||
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,54 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2017 Akretion | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) | ||
|
||
import logging | ||
|
||
from odoo import models | ||
|
||
from odoo.addons.component.core import Component | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
class ConfigurableBatchImporter(Component): | ||
""" Import the Configurable Products. | ||
For every Configurable Product not yet converted from flat | ||
to templated product, creates a job | ||
""" | ||
_name = 'magento.product.configurable.batch.importer' | ||
_inherit = 'magento.delayed.batch.importer' | ||
_apply_on = ['magento.product.configurable'] | ||
|
||
def run(self, filters=None): | ||
""" Run the synchronization """ | ||
# from_date = filters.pop('from_date', None) | ||
# to_date = filters.pop('to_date', None) | ||
internal_ids = self.env['magento.product.product'].search( | ||
[('product_type', '=', 'configurable')] | ||
) | ||
_logger.info('search for configurable products %s returned %s', | ||
filters, internal_ids) | ||
for internal_id in internal_ids: | ||
self._import_record(internal_id) | ||
|
||
|
||
class ConfigurableImporter(Component): | ||
_name = 'magento.product.configurable.importer' | ||
_inherit = 'magento.importer' | ||
_apply_on = ['magento.product.configurable'] | ||
|
||
def run(self, magento_record, force=False): | ||
filters = {'sku': magento_record.default_code} | ||
self.env['magento.product.attribute'].import_batch( | ||
self.backend_record, | ||
filters, | ||
) | ||
|
||
|
||
class MagentoProductConfigurable(models.Model): | ||
_name = 'magento.product.configurable' | ||
_inherit = 'magento.binding' | ||
_inherits = {'product.product': 'odoo_id'} | ||
_description = 'Magento Product Configurable' |
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,52 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2017 Akretion | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) | ||
|
||
from odoo import models, fields, api | ||
|
||
from odoo.addons.component.core import Component | ||
|
||
|
||
class MagentoBackend(models.Model): | ||
_inherit = 'magento.backend' | ||
|
||
import_configurables_from_date = fields.Datetime( | ||
string='Import configurables from date', | ||
) | ||
|
||
@api.multi | ||
def import_product_configurable(self): | ||
self._import_from_date('magento.product.configurable', | ||
'import_configurables_from_date') | ||
return True | ||
|
||
@api.model | ||
def _scheduler_import_product_configurable(self, domain=None): | ||
self._magento_backend('import_product_configurable', domain=domain) | ||
|
||
|
||
class ProductImporter(Component): | ||
_inherit = 'magento.product.product.importer' | ||
|
||
""" | ||
Returns None if the product_type is configurable | ||
So that it is not skipped | ||
""" | ||
def _must_skip(self): | ||
res = super(ProductImporter, self)._must_skip() | ||
if self.magento_record['type_id'] != 'configurable': | ||
return res | ||
|
||
|
||
class MagentoProductProduct(models.Model): | ||
_inherit = 'magento.product.product' | ||
|
||
transformed_at = fields.Date( | ||
'Transformed At (from simple to templated product)' | ||
) | ||
|
||
|
||
class MagentoConfigurableModelBinder(Component): | ||
_name = 'magento.configurable.binder' | ||
_inherit = 'magento.binder' | ||
_apply_on = ['magento.product.attribute'] |
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 2017 Akretion | ||
# 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') | ||
|
||
|
||
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 == 101: | ||
raise IDMissingInBackend | ||
else: | ||
raise | ||
|
||
def list_attributes(self, sku, storeview_id=None, attributes=None): | ||
""" Returns the information of a record | ||
:rtype: dict | ||
""" | ||
return self._call('%s.listSuperAttributes' % self._magento_model, | ||
[sku, storeview_id, attributes]) |
59 changes: 59 additions & 0 deletions
59
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,59 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2017 Akretion | ||
# 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 | ||
|
||
|
||
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 """ | ||
sku = filters['sku'] | ||
updated_attributes = self.backend_adapter.list_attributes(sku) | ||
for attribute in updated_attributes: | ||
self._import_record(attribute) | ||
|
||
|
||
class ProductAttributeImporter(Component): | ||
_name = 'magento.product.attribute.importer' | ||
_inherit = 'magento.importer' | ||
_apply_on = ['magento.product.attribute'] | ||
|
||
def _get_magento_data(self, storeview_id=None): | ||
""" | ||
In this case, the external_id contains all the object to insert | ||
""" | ||
return self.external_id | ||
|
||
|
||
class ProductAttributeImportMapper(Component): | ||
_name = 'magento.product.attribute.import.mapper' | ||
_inherit = 'magento.import.mapper' | ||
_apply_on = 'magento.product.attribute' | ||
|
||
direct = [ | ||
('attribute_code', 'name'), | ||
('attribute_id', 'external_id'), | ||
('store_label', 'display_name'), | ||
] | ||
|
||
@mapping | ||
def backend_id(self, record): | ||
return {'backend_id': self.backend_record.id} |
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 @@ | ||
"access_magento_product_attribute","magento_product_attribute connector manager","model_magento_product_attribute","connector.group_connector_manager",1,1,1,1 | ||
"access_magento_product_attribute_user","magento_product_attribute user","model_magento_product_attribute","sales_team.group_sale_salesman",1,0,0,0 | ||
"access_magento_product_attribute_sale_manager","magento_product_attribute sale manager","model_magento_product_attribute","sales_team.group_sale_manager",1,1,1,1 |
24 changes: 24 additions & 0 deletions
24
connector_magento_configurable/views/magento_backend_views.xml
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,24 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
|
||
<record id="view_magento_backend_form" model="ir.ui.view"> | ||
<field name="model">magento.backend</field> | ||
<field name="inherit_id" ref="connector_magento.view_magento_backend_form"></field> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//page[@name='import']/group[4]" position="after"> | ||
<group> | ||
<div> | ||
<label string="Import configurables since" class="oe_inline"/> | ||
<field name="import_configurables_from_date" | ||
class="oe_inline" | ||
nolabel="1"/> | ||
</div> | ||
<button name="import_product_configurable" | ||
type="object" | ||
class="oe_highlight" | ||
string="Import in background"/> | ||
</group> | ||
</xpath> | ||
</field> | ||
</record> | ||
</odoo> |