Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to integrate the magento connector in OpenERP(Odoo)?

    • 0
    • 3
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 657
    Comment on it

    Step-1 Install basic module like below:
    1-account_payment_extension
    2-base_external_mapping
    3- magento_connect
    4-product_attributes
    4-product_images_olbs
    6-product_m2mcategories
    7-sale_payment
    Step-2 After that we have to customised magento_connect module.
    Step-3 In below example, I have custmozied .py file. You can directly copy the below python code in magento_connect module.

    from osv import osv, fields
    from tools.translate import _
    
    import netsvc
    import time
    
    try:
        from magento import api
    except:
        raise osv.except_osv(_('vobject Import Error!'), _('Please install python-magento from https://github.com/zikzakmedia/magento'))
    
    from magento import *
    
    LOGGER = netsvc.Logger()
    MGN2OERP_TYPE_FIELDS = {
        'text':'char',
        'textarea':'text',
        'boolean':'boolean',
        'select':'selection',
        #~ 'multiselect':'many2many', #TODO
        'date':'datetime',
        'price':'float',
    }
    
    class magento_storeview(osv.osv):
        _name = 'magento.storeview'
        _description = 'Magento Store View'
    
    magento_storeview()
    
    class magento_app(osv.osv):
        _name = 'magento.app'
        _description = 'Magento Server - APP'
    
        _columns = {
            'name': fields.char('Name', size=256, required=True),
            'uri': fields.char('URI', size=256, required=True, help='URI Magento App. http://yourmagento.com/ (with / at end URI)'),
            'username': fields.char('Username', size=256, required=True),
            'password': fields.char('Password', size=256, required=True),
            'product_category_id': fields.many2one('product.category', 'Root product Category', required=True),
            'magento_website_ids': fields.one2many('magento.website', 'magento_app_id', 'Websites'),
            'payment_default_id': fields.many2one('account.payment.term', 'Payment Term', required=True, help='Default Payment Term'),
            'product_delivery_default_id': fields.many2one('product.product', 'Product Delivery', required=True, help='Default Product Delivery'),
            'product_discount_default_id': fields.many2one('product.product', 'Product Discount', required=True, help='Default Product Discount'),
            'warehouse_id': fields.many2one('stock.warehouse', 'Warehouse', required=True),
            'pricelist_id': fields.many2one('product.pricelist', 'Pricelist', required=True),
            'product_uom_id': fields.many2one('product.uom', 'Unit of Sale', required=True, help='Default Unit of Sale'),
            'from_import_products': fields.datetime('From Import Products', help='This date is last import. If you need import new products, you can modify this date (filter)'),
            'to_import_products': fields.datetime('To Import Products', help='This date is to import (filter)'),
            'last_export_product_category': fields.datetime('Last Export Categories', help='This date is to export (filter)'),
            'magento_default_storeview': fields.many2one('magento.storeview', 'Store View Default', help='Default language this shop. If not select, use lang user'),
            'from_import_customers': fields.datetime('From Import Customers', help='This date is last import. If you need import new partners, you can modify this date (filter)'),
            'to_import_customers': fields.datetime('To Import Customers', help='This date is to import (filter)'),
            'last_export_partners': fields.datetime('Last Export Partners', help='This date is last export. If you need export all partners, empty this field (long sync)'),
            'magento_country_ids': fields.many2many('res.country','magento_app_country_rel', 'magento_app_id','country_id','Country'),
            'magento_region_ids': fields.one2many('magento.region', 'magento_app_id', 'Region'),
            'inventory': fields.boolean('Force Inventory', help='When create new product, this force inventory available'),
            'options': fields.boolean('Product Options', help='Orders with product options. Split reference order line by -'),
        }
    
        def core_sync_test(self, cr, uid, ids, context):
            """
            def test connection OpenERP to Magento
            """
    
            for magento_app in self.browse(cr, uid, ids):
                status = {}
                try:
                    with API(magento_app.uri, magento_app.username, magento_app.password) as magento_api:
                        websites = magento_api.call('ol_websites.list', [])
                        if len(websites) > 0:
                            status =  {'title':_('Ok!'), 'message': _('Connection to server are successfully.')}
                        else:
                            status =  {'title':_('Warning!'), 'message': _('Connection to server are successfully but reconfigure your Magento.')}
                except:
                    status =  {'title':_('Error!'), 'message': _('Connection to server failed.')}
    
                raise osv.except_osv(status['title'], status['message'])
    
        def core_sync_store(self, cr, uid, ids, context):
            """
            Sync Store Magento to OpenERP
            - Websites
            - Store Group / OpenERP Sale Shop
            - Store View
            Only create new values if not exist; not update or delete
            :return True
            """
    
            magento_external_referential_obj = self.pool.get('magento.external.referential')
    
            for magento_app in self.browse(cr, uid, ids):
                with API(magento_app.uri, magento_app.username, magento_app.password) as magento_api:
    
                    """Websites"""
                    for website in magento_api.call('ol_websites.list', []):
                        web_site = magento_external_referential_obj.check_mgn2oerp(cr, uid, magento_app, 'magento.website', website['website_id'])
    
                        if not web_site: #create
                            values = {
                                'name': website['name'],
                                'code': website['code'],
                                'magento_app_id': magento_app.id,
                            }
                            website_oerp_id = self.pool.get('magento.website').create(cr, uid, values, context)
                            magento_external_referential_obj.create_external_referential(cr, uid, magento_app, 'magento.website', website_oerp_id, website['website_id'])
                            LOGGER.notifyChannel('Magento Sync API', netsvc.LOG_INFO, "Create Website: magento %s, magento website id %s." % (magento_app.name, website['website_id']))
                            """Sale Shop"""
                            values = {
                                'name': website['name'],
                                'payment_default_id': magento_app.payment_default_id.id,
                                'warehouse_id': magento_app.warehouse_id.id,
                                'pricelist_id': magento_app.pricelist_id.id,
                                'magento_shop': True,
                                'magento_website': website_oerp_id,
                                'magento_default_picking_policy': 'one',
                                'magento_default_order_policy': 'picking',
                                'magento_default_invoice_quantity': 'order',
                            }
                            saleshop_oerp_id = self.pool.get('sale.shop').create(cr, uid, values, context)
                            magento_external_referential_obj.create_external_referential(cr, uid, magento_app, 'sale.shop', saleshop_oerp_id, website['website_id'])
                            LOGGER.notifyChannel('Magento Sync API', netsvc.LOG_INFO, "Create Sale Shop: magento %s, Sale Shop id %s." % (magento_app.name, saleshop_oerp_id))
                        else:
                            LOGGER.notifyChannel('Magento Sync API', netsvc.LOG_ERROR, "Skip! Website exists: magento %s, magento website id %s. Not create" % (magento_app.name, website['website_id']))
    
                    """Store Group"""
                    for storegroup in magento_api.call('ol_groups.list', []):
                        store_group = magento_external_referential_obj.check_mgn2oerp(cr, uid, magento_app, 'magento.storegroup', storegroup['group_id'])
    
                        if not store_group: #create
                            magento_website_id = magento_external_referential_obj.check_mgn2oerp(cr, uid, magento_app, 'magento.website', storegroup['website_id'])
    
                            if magento_website_id:
                                external_referentials = magento_external_referential_obj.get_external_referential(cr, uid, [magento_website_id])
                                values = {
                                    'name': storegroup['name'],
                                    'magento_app_id': magento_app.id,
                                    'magento_website_id': external_referentials[0]['oerp_id'],
                                }
                                storegroup_oerp_id = self.pool.get('magento.storegroup').create(cr, uid, values, context)
                                magento_external_referential_obj.create_external_referential(cr, uid, magento_app, 'magento.storegroup', storegroup_oerp_id, storegroup['group_id'])
                                LOGGER.notifyChannel('Magento Sync API', netsvc.LOG_INFO, "Create Store Group: magento %s, magento store group id %s." % (magento_app.name, storegroup['group_id']))
                            else:
                                LOGGER.notifyChannel('Magento Sync API', netsvc.LOG_ERROR, "Failed to find magento.website with magento %s. Not create Store Group." % (magento_app.name))
                        else:
                            LOGGER.notifyChannel('Magento Sync API', netsvc.LOG_ERROR, "Skip! Store Group exists: magento %s, magento store group id %s. Not create" % (magento_app.name, storegroup['group_id']))
    
                    """Store View"""
                    for storeview in magento_api.call('ol_storeviews.list', []):
                        store_view = magento_external_referential_obj.check_mgn2oerp(cr, uid, magento_app, 'magento.storeview', storeview['store_id'])
    
                        if not store_view: #create
                            store_group = magento_external_referential_obj.check_mgn2oerp(cr, uid, magento_app, 'magento.storegroup', storeview['group_id'])
    
                            external_referentials = magento_external_referential_obj.get_external_referential(cr, uid, [store_group])
                            if len(external_referentials)>0:
                                values = {
                                    'name': storeview['name'],
                                    'code': storeview['code'],
                                    'magento_storegroup_id': external_referentials[0]['oerp_id'],
                                }
                                storeview_oerp_id = self.pool.get('magento.storeview').create(cr, uid, values, context)
                                magento_external_referential_obj.create_external_referential(cr, uid, magento_app, 'magento.storeview', storeview_oerp_id, storeview['store_id'])
                                LOGGER.notifyChannel('Magento Sync API', netsvc.LOG_INFO, "Create Store View: magento app id %s, magento store view id %s." % (storeview_oerp_id, storeview['store_id']))
                            else:
                                LOGGER.notifyChannel('Magento Sync API', netsvc.LOG_ERROR, "Failed to find magento.storegroup with magento %s and Magento ID %s. Not create Store Group." % (magento_app.name, storeview['group_id']))
                        else:
                            LOGGER.notifyChannel('Magento Sync API', netsvc.LOG_INFO, "Skip! Store Group exists: magento %s, magento store group id %s. Not create" % (magento_app.name, storeview['store_id']))
            return True
    
        def core_sync_regions(self, cr, uid, ids, context):
            """
            def sync Regions Magento to OpenERP
            Only create new values if not exist; not update or delete
            :ids list magento app
            :return True

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: