Skip to content

Commit

Permalink
[MIG] connector_magento to v11
Browse files Browse the repository at this point in the history
  • Loading branch information
hugosantosred committed Mar 6, 2018
1 parent 8145a35 commit 5ff679d
Show file tree
Hide file tree
Showing 27 changed files with 193 additions and 150 deletions.
2 changes: 1 addition & 1 deletion connector_magento/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{'name': 'Magento Connector',
'version': '10.0.1.0.0',
'version': '11.0.1.0.0',
'category': 'Connector',
'depends': ['account',
'base_technical_user',
Expand Down
6 changes: 3 additions & 3 deletions connector_magento/components/backend_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import socket
import logging
import xmlrpclib
import xmlrpc.client

from odoo.addons.component.core import AbstractComponent
from odoo.addons.queue_job.exception import RetryableJobError
Expand Down Expand Up @@ -90,7 +90,7 @@ def call(self, method, arguments):
start = datetime.now()
try:
result = self.api.call(method, arguments)
except:
except Exception:
_logger.error("api.call('%s', %s) failed", method, arguments)
raise
else:
Expand All @@ -104,7 +104,7 @@ def call(self, method, arguments):
raise NetworkRetryableError(
'A network error caused the failure of the job: '
'%s' % err)
except xmlrpclib.ProtocolError as err:
except xmlrpc.client.ProtocolError as err:
if err.errcode in [502, # Bad gateway
503, # Service unavailable
504]: # Gateway timeout
Expand Down
6 changes: 3 additions & 3 deletions connector_magento/components/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def run(self, external_id, binding, mapper=None):

# find the translatable fields of the model
fields = self.model.fields_get()
translatable_fields = [field for field, attrs in fields.iteritems()
translatable_fields = [field for field, attrs in list(fields.items())
if attrs.get('translate')]

if mapper is None:
Expand All @@ -316,9 +316,9 @@ def run(self, external_id, binding, mapper=None):
for storeview in lang_storeviews:
lang_record = self._get_magento_data(storeview.external_id)
map_record = mapper.map_record(lang_record)
record = map_record.values()
record = list(map_record.values())

data = dict((field, value) for field, value in record.iteritems()
data = dict((field, value) for field, value in list(record.items())
if field in translatable_fields)

binding.with_context(connector_no_export=True,
Expand Down
12 changes: 6 additions & 6 deletions connector_magento/data/connector_magento_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field eval="False" name="doall"/>
<field eval="'magento.backend'" name="model"/>
<field ref="connector_magento.model_magento_backend" name="model_id"/>
<field eval="'_scheduler_import_sale_orders'" name="function"/>
<field eval="'()'" name="args"/>
</record>
Expand All @@ -26,7 +26,7 @@
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field eval="False" name="doall"/>
<field eval="'magento.backend'" name="model"/>
<field ref="connector_magento.model_magento_backend" name="model_id"/>
<field eval="'_scheduler_import_customer_groups'" name="function"/>
<field eval="'()'" name="args"/>
</record>
Expand All @@ -39,7 +39,7 @@
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field eval="False" name="doall"/>
<field eval="'magento.backend'" name="model"/>
<field ref="connector_magento.model_magento_backend" name="model_id"/>
<field eval="'_scheduler_import_partners'" name="function"/>
<field eval="'()'" name="args"/>
</record>
Expand All @@ -52,7 +52,7 @@
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field eval="False" name="doall"/>
<field eval="'magento.backend'" name="model"/>
<field ref="connector_magento.model_magento_backend" name="model_id"/>
<field eval="'_scheduler_import_product_categories'" name="function"/>
<field eval="'()'" name="args"/>
</record>
Expand All @@ -65,7 +65,7 @@
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field eval="False" name="doall"/>
<field eval="'magento.backend'" name="model"/>
<field ref="connector_magento.model_magento_backend" name="model_id"/>
<field eval="'_scheduler_import_product_product'" name="function"/>
<field eval="'()'" name="args"/>
</record>
Expand All @@ -78,7 +78,7 @@
<field name="interval_type">hours</field>
<field name="numbercall">-1</field>
<field eval="False" name="doall"/>
<field eval="'magento.backend'" name="model"/>
<field ref="connector_magento.model_magento_backend" name="model_id"/>
<field eval="'_scheduler_update_product_stock_qty'" name="function"/>
<field eval="'()'" name="args"/>
</record>
Expand Down
16 changes: 8 additions & 8 deletions connector_magento/doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ def add_path(*paths):
master_doc = 'index'

# General information about the project.
project = u'Odoo Magento Connector'
copyright = u'2013-2015, Odoo Community Association (OCA)'
project = 'Odoo Magento Connector'
copyright = '2013-2015, Odoo Community Association (OCA)'

# The version info for the project you're documenting, acts as
# replacement for |version| and |release|, also used in various other
Expand Down Expand Up @@ -320,8 +320,8 @@ def add_path(*paths):
# start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'odoo-magento-connector.tex',
u'Odoo Magento Connector Documentation',
u'Odoo Community Association (OCA)', 'manual'),
'Odoo Magento Connector Documentation',
'Odoo Community Association (OCA)', 'manual'),
]

# The name of an image file (relative to this directory) to place at the
Expand Down Expand Up @@ -351,8 +351,8 @@ def add_path(*paths):
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'odoo-magento-connector',
u'Odoo Magento Connector Documentation',
[u'Odoo Community Association (OCA)'], 1)
'Odoo Magento Connector Documentation',
['Odoo Community Association (OCA)'], 1)
]

# If true, show URL addresses after external links.
Expand All @@ -366,8 +366,8 @@ def add_path(*paths):
# dir menu entry, description, category)
texinfo_documents = [
('index', 'Odoo Magento Connector',
u'Odoo Magento Connector Documentation',
u'Odoo Community Association (OCA)', 'Odoo Magento Connector',
'Odoo Magento Connector Documentation',
'Odoo Community Association (OCA)', 'Odoo Magento Connector',
'Connector between Odoo and Magento',
'Miscellaneous'),
]
Expand Down
4 changes: 2 additions & 2 deletions connector_magento/models/account_invoice/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

import logging
import xmlrpclib
import xmlrpc.client
from odoo import api, models, fields
from odoo.addons.component.core import Component
from odoo.addons.queue_job.job import job, related_action
Expand Down Expand Up @@ -70,7 +70,7 @@ class AccountInvoiceAdapter(Component):
def _call(self, method, arguments):
try:
return super(AccountInvoiceAdapter, self)._call(method, arguments)
except xmlrpclib.Fault as err:
except xmlrpc.client.Fault as err:
# this is the error in the Magento API
# when the invoice does not exist
if err.faultCode == 100:
Expand Down
4 changes: 2 additions & 2 deletions connector_magento/models/account_invoice/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import logging

import xmlrpclib
import xmlrpc.client

from odoo import _
from odoo.addons.component.core import Component
Expand Down Expand Up @@ -70,7 +70,7 @@ def run(self, binding):
external_id = self._export_invoice(magento_order.external_id,
lines_info,
mail_notification)
except xmlrpclib.Fault as err:
except xmlrpc.client.Fault as err:
# When the invoice is already created on Magento, it returns:
# <Fault 102: 'Cannot do invoice for order.'>
# We'll search the Magento invoice ID to store it in Odoo
Expand Down
11 changes: 6 additions & 5 deletions connector_magento/models/magento_backend/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from odoo import models, fields, api, _
from odoo.exceptions import UserError

from odoo.addons.connector.checkpoint import checkpoint
from odoo.addons.connector.models.checkpoint import add_checkpoint
from ...components.backend_adapter import MagentoLocation, MagentoAPI

_logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -42,6 +42,7 @@ def _get_stock_field_id(self):
limit=1)
return field

name = fields.Char(string='Name', required=True)
version = fields.Selection(selection='select_versions', required=True)
location = fields.Char(
string='Location',
Expand Down Expand Up @@ -213,8 +214,8 @@ def work_on(self, model_name, **kwargs):
def add_checkpoint(self, record):
self.ensure_one()
record.ensure_one()
return checkpoint.add_checkpoint(self.env, record._name, record.id,
self._name, self.id)
return add_checkpoint(self.env, record._name, record.id,
self._name, self.id)

@api.multi
def synchronize_metadata(self):
Expand All @@ -231,8 +232,8 @@ def synchronize_metadata(self):
except Exception as e:
_logger.error(e.message, exc_info=True)
raise UserError(
_(u"Check your configuration, we can't get the data. "
u"Here is the error:\n%s") %
_("Check your configuration, we can't get the data. "
"Here is the error:\n%s") %
str(e).decode('utf-8', 'ignore'))

@api.multi
Expand Down
4 changes: 2 additions & 2 deletions connector_magento/models/partner/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import logging
import xmlrpclib
import xmlrpc.client
from odoo import models, fields, api
from odoo.addons.queue_job.job import job
from odoo.addons.component.core import Component
Expand Down Expand Up @@ -153,7 +153,7 @@ class PartnerAdapter(Component):
def _call(self, method, arguments):
try:
return super(PartnerAdapter, self)._call(method, arguments)
except xmlrpclib.Fault as err:
except xmlrpc.client.Fault as err:
# this is the error in the Magento API
# when the customer does not exist
if err.faultCode == 102:
Expand Down
3 changes: 1 addition & 2 deletions connector_magento/models/partner/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ class BaseAddressImportMapper(AbstractComponent):
direct = [('postcode', 'zip'),
('city', 'city'),
('telephone', 'phone'),
('fax', 'fax'),
('company', 'company'),
]

Expand Down Expand Up @@ -284,7 +283,7 @@ def street(self, record):
if len(lines) == 1:
result = {'street': lines[0], 'street2': False}
elif len(lines) >= 2:
result = {'street': lines[0], 'street2': u' - '.join(lines[1:])}
result = {'street': lines[0], 'street2': ' - '.join(lines[1:])}
else:
result = {}
return result
Expand Down
8 changes: 4 additions & 4 deletions connector_magento/models/product/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import logging
import xmlrpclib
import xmlrpc.client

from collections import defaultdict

Expand All @@ -19,7 +19,7 @@


def chunks(items, length):
for index in xrange(0, len(items), length):
for index in range(0, len(items), length):
yield items[index:index + length]


Expand Down Expand Up @@ -113,7 +113,7 @@ def recompute_magento_qty(self):
for product in self:
backends[product.backend_id].add(product.id)

for backend, product_ids in backends.iteritems():
for backend, product_ids in list(backends.items()):
self._recompute_magento_qty_backend(backend,
self.browse(product_ids))
return True
Expand Down Expand Up @@ -189,7 +189,7 @@ class ProductProductAdapter(Component):
def _call(self, method, arguments):
try:
return super(ProductProductAdapter, self)._call(method, arguments)
except xmlrpclib.Fault as err:
except xmlrpc.client.Fault as err:
# this is the error in the Magento API
# when the product does not exist
if err.faultCode == 101:
Expand Down
21 changes: 13 additions & 8 deletions connector_magento/models/product/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

import logging
import urllib2
import urllib.request
import urllib.error
import urllib.parse
import base64
import sys

Expand Down Expand Up @@ -78,17 +80,20 @@ def priority(image):
return sorted(images, key=priority)

def _get_binary_image(self, image_data):
url = image_data['url'].encode('utf8')
url = image_data['url']
try:
request = urllib2.Request(url)
request = urllib.request.Request(url)
if self.backend_record.auth_basic_username \
and self.backend_record.auth_basic_password:
base64string = base64.b64encode(
'%s:%s' % (self.backend_record.auth_basic_username,
self.backend_record.auth_basic_password))
request.add_header("Authorization", "Basic %s" % base64string)
binary = urllib2.urlopen(request)
except urllib2.HTTPError as err:
("%s:%s" % (self.backend_record.auth_basic_username,
self.backend_record.auth_basic_password)
).encode('utf-8')
)
request.add_header("Authorization", "Basic %s" % (
base64string.decode('utf-8')))
binary = urllib.request.urlopen(request)
except urllib.error.HTTPError as err:
if err.code == 404:
# the image is just missing, we skip it
return
Expand Down
4 changes: 2 additions & 2 deletions connector_magento/models/product_category/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import logging
import xmlrpclib
import xmlrpc.client
from odoo import models, fields
from odoo.addons.connector.exception import IDMissingInBackend
from odoo.addons.component.core import Component
Expand Down Expand Up @@ -57,7 +57,7 @@ class ProductCategoryAdapter(Component):
def _call(self, method, arguments):
try:
return super(ProductCategoryAdapter, self)._call(method, arguments)
except xmlrpclib.Fault as err:
except xmlrpc.client.Fault as err:
# 101 is the error in the Magento API
# when the category does not exist
if err.faultCode == 102:
Expand Down
2 changes: 1 addition & 1 deletion connector_magento/models/product_category/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def run(self, filters=None):
base_priority = 10

def import_nodes(tree, level=0):
for node_id, children in tree.iteritems():
for node_id, children in list(tree.items()):
# By changing the priority, the top level category has
# more chance to be imported before the childrens.
# However, importers have to ensure that their parent is
Expand Down
4 changes: 2 additions & 2 deletions connector_magento/models/sale_order/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import logging
import xmlrpclib
import xmlrpc.client

import odoo.addons.decimal_precision as dp

Expand Down Expand Up @@ -245,7 +245,7 @@ class SaleOrderAdapter(Component):
def _call(self, method, arguments):
try:
return super(SaleOrderAdapter, self)._call(method, arguments)
except xmlrpclib.Fault as err:
except xmlrpc.client.Fault as err:
# this is the error in the Magento API
# when the sales order does not exist
if err.faultCode == 100:
Expand Down
Loading

0 comments on commit 5ff679d

Please sign in to comment.