Beispiel #1
0
    def _mage_call(self, credentials, method, arguments):
        try:
            with API(credentials['url'], credentials['username'],
                     credentials['password']) as mage_api:
                return mage_api.call(method, arguments)

        except (socket.gaierror, socket.error, socket.timeout) as err:
            raise osv.except_osv(
                _('Network/URL Config Error'),
                _('Either you entered the URL in wrong or you have no internet connectivity'
                  ))
        except xmlrpclib.ProtocolError as err:
            if err.errcode in [
                    502,  # Bad gateway
                    503,  # Service unavailable
                    504
            ]:  # Gateway timeout
                raise osv.except_osv(
                    _('Connection Error'),
                    _('Server Returned Error Code: %s') % err.errcode)
            else:
                raise osv.except_osv(_('Generic Connection Error'), _("Could Not Authenticate/Connect with Magento!\n" \
                 "Please verify that\n1. The Magento module is installed in the LOCAL folder on Magento.\n" \
                 "2. Your webservice user in Magento is setup with FULL Admin access.\n" \
                 "3. Verify your Odoo server can reach Magento.\n" \
                 "4. Verify that you have entered the correct Credentials"))

        except Exception, e:
            raise osv.except_osv(_('Magento Returned an Error'), _('%s') % e)
Beispiel #2
0
    def upsert_shell_product(self, cr, uid, credentials, shell_data, product, storeview):
        try:
            with API(credentials['url'], credentials['username'], credentials['password']) as product_api:
                external_id = product_api.call('oo_catalog_product.create', [product.mage_type, product.set.external_id, product.default_code, shell_data, storeview])
		self.pool.get('product.product').write(cr, uid, product.id, {'external_id': external_id, 'mage_last_sync_date': datetime.utcnow()})
        except Exception, e:
            raise osv.except_osv(_('Magento API Error!'),_(str(e)))
Beispiel #3
0
 def get_magento_region_id(self, cr, uid, credentials, country_id,
                           state_name):
     with API(credentials['url'], credentials['username'],
              credentials['password']) as mage_api:
         region_id = mage_api.call('sales_order.getregionid',
                                   [country_id, state_name])
         return region_id
Beispiel #4
0
 def push_magento_product_stock(self, cr, uid, credentials, product_data):
     print 'CALLING FUNCTION'
     try:
         pp(product_data)
         with API(credentials['url'], credentials['username'],
                  credentials['password']) as product_api:
             results = product_api.call(
                 'oo_catalog_product.updateproductstock', [product_data])
             print 'Results', results
     except Exception, e:
         raise osv.except_osv(_('Magento API Error!'), _(str(e)))
Beispiel #5
0
    def send_mage_cart_quote(self,
                             cr,
                             uid,
                             credentials,
                             quote_vals,
                             quote,
                             context=None):
        try:
            with API(credentials['url'], credentials['username'],
                     credentials['password']) as quote_api:
                response = quote_api.call('sales_order.createquote',
                                          [quote_vals])

            quote.name = response['quote_name']
            quote.mage_quote_id = response['quote_id']
        except Exception, e:
            raise osv.except_osv(_('Magento API Error!'), _(str(e)))
Beispiel #6
0
    def send_quote_proposal(self, cr, uid, ids, context=None):
        integrator_obj = self.pool.get('mage.integrator')
        credentials = integrator_obj.get_external_credentials(cr, uid)

        sale = self.browse(cr, uid, ids[0])
        if not sale.mage_quote_id or sale.mage_quote_id == 0:
            raise osv.except_osv(
                _('User Error!'),
                _('You must push the quote to Magento before you can send it to the customer!'
                  ))
        try:
            with API(credentials['url'], credentials['username'],
                     credentials['password']) as quote_api:
                quote_api.call('c2q_quotation.send_proposal',
                               [sale.mage_quote_id])

            sale.quote_status = '50'
        except Exception, e:
            raise osv.except_osv(_('Magento API Error!'), _(str(e)))
Beispiel #7
0
    def synchronize_magento_stock(self, cr, uid, job):
        integrator_obj = self.pool.get('mage.integrator')
        credentials = integrator_obj.get_external_credentials(cr, uid)

        product_obj = self.pool.get('product.product')
        product_ids = product_obj.search(cr, uid,
                                         [('sync_stock', '=', True),
                                          ('sync_to_mage', '=', True)])
        #	product_ids = [2389]
        product_data = {}
        for product in product_obj.browse(cr, uid, product_ids):
            if not product.external_id or product.external_id < 1:
                continue
            qty = product.qty_available
            always_in_stock = product.always_in_stock
            manage_stock = product.manage_stock
            use_config = product.use_config_manage_stock
            if always_in_stock:
                is_in_stock = 1
            elif qty > 1:
                is_in_stock = 1
            else:
                is_in_stock = 0

            product_data[str(product.external_id)] = {
                'is_in_stock': is_in_stock,
                'qty': int(qty),
                'manage_stock': 1 if manage_stock else 0,
                'config_manage_stock': 1 if use_config else 0,
            }

        try:
            pp(product_data)
            with API(credentials['url'], credentials['username'],
                     credentials['password']) as product_api:
                results = product_api.call(
                    'oo_catalog_product.updateproductstock', [product_data])
                print 'Results', results
        except Exception, e:
            raise osv.except_osv(_('Magento API Error!'), _(str(e)))
    def get_shipping_quotes(self, cr, uid, credentials, quote_id):
	with API(credentials['url'], credentials['username'], credentials['password']) as cart_api:
	    quotes = cart_api.call('cart_shipping.list', [quote_id])	
	    return quotes