-
-
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.
- switch to synchronous - problem : in magento, products created before a change in attribute prices don't change their price. In odoo they do -> can result in prices mismatch
- Loading branch information
1 parent
3224dc8
commit b2b7163
Showing
9 changed files
with
162 additions
and
41 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
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
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
3 changes: 3 additions & 0 deletions
3
connector_magento_configurable/models/product_attribute_price/__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 |
31 changes: 31 additions & 0 deletions
31
connector_magento_configurable/models/product_attribute_price/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,31 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2017 Akretion | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
import logging | ||
from odoo import models, fields | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
class MagentoProductAttributePrice(models.Model): | ||
_name = 'magento.product.attribute.price' | ||
_inherit = 'magento.binding' | ||
_inherits = {'product.attribute.price': 'odoo_id'} | ||
_description = 'Magento Product Attribute' | ||
|
||
odoo_id = fields.Many2one( | ||
comodel_name='product.attribute.price', | ||
string='Product Attribute', | ||
required=True, | ||
ondelete='cascade') | ||
|
||
|
||
class ProductAttributePrice(models.Model): | ||
_inherit = 'product.attribute.price' | ||
|
||
magento_bind_ids = fields.One2many( | ||
comodel_name='magento.product.attribute.price', | ||
inverse_name='odoo_id', | ||
string="Magento Bindings", | ||
) |
92 changes: 92 additions & 0 deletions
92
connector_magento_configurable/models/product_attribute_price/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,92 @@ | ||
# -*- 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 | ||
from odoo.addons.connector.exception import MappingError | ||
|
||
|
||
class ProductAttributePriceBatchImporter(Component): | ||
""" Import the Magento Product Attributes. | ||
""" | ||
_name = 'magento.product.attribute.price.batch.importer' | ||
_inherit = 'magento.direct.batch.importer' | ||
_apply_on = ['magento.product.attribute.price'] | ||
|
||
def run(self, filters=None): | ||
""" Run the synchronization """ | ||
price = filters['price'] | ||
price['product_id'] = filters['product_id'] | ||
price['magento_value'] = filters['magento_value'] | ||
price['external_id'] = price['value_index'] | ||
price['external_id'] += '_' + price['product_id'] | ||
self._import_record(price) | ||
|
||
|
||
class ProductAttributePriceImporter(Component): | ||
_name = 'magento.product.attribute.price.importer' | ||
_inherit = 'magento.importer' | ||
_apply_on = ['magento.product.attribute.price'] | ||
|
||
def _get_magento_data(self, storeview_id=None): | ||
""" | ||
In this case, the magento_record contains all the data to insert | ||
""" | ||
record = self.magento_record | ||
binder = self.binder_for('magento.product.product') | ||
product_binding = binder.to_internal(record['product_id']) | ||
|
||
if not product_binding: | ||
raise MappingError("The product with " | ||
"magento id %s is not imported." % | ||
record['product_id']) | ||
|
||
record['template'] = product_binding.product_tmpl_id | ||
return record | ||
|
||
def run(self, magento_record, force=False): | ||
self.magento_record = magento_record | ||
super(ProductAttributePriceImporter, self).run( | ||
magento_record['external_id'], | ||
force, | ||
) | ||
|
||
|
||
class ProductAttributePriceImportMapper(Component): | ||
_name = 'magento.product.attribute.price.import.mapper' | ||
_inherit = 'magento.import.mapper' | ||
_apply_on = 'magento.product.attribute.price' | ||
|
||
direct = [ | ||
('pricing_value', 'price_extra'), | ||
('external_id', 'external_id'), | ||
] | ||
|
||
@mapping | ||
def price_extra(self, record): | ||
price = record['pricing_value'] | ||
if record['is_percent'] == '1': | ||
price = (float(price)/100) * record['template'].list_price | ||
return {'price_extra': price} | ||
|
||
@mapping | ||
def backend_id(self, record): | ||
return {'backend_id': self.backend_record.id} | ||
|
||
@mapping | ||
def product_tmpl_id(self, record): | ||
return { | ||
'product_tmpl_id': record['template'].id, | ||
} | ||
|
||
@mapping | ||
def value_id(self, record): | ||
if not record.get('magento_value'): | ||
return | ||
|
||
value = record.get('magento_value').odoo_id | ||
return { | ||
'value_id': value.id, | ||
'magento_value_id': record.get('magento_value').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