def import_sale_order_by_number(self, increment_id):
        session = ConnectorSession(self.env.cr,
                                   self.env.uid,
                                   context=self.env.context)
        for storeview in self:
            if storeview.no_sales_order_sync:
                _logger.debug(
                    "The storeview '%s' is active in Magento "
                    "but is configured not to import the "
                    "sales orders", storeview.name)
                continue
            try:
                backend_id = storeview.backend_id.id
                self = SaleOrderBatchImport
                filters = {
                    'magento_storeview_id': storeview.magento_id,
                    'increment_id': increment_id
                }
                env = get_environment(session, 'magento.sale.order',
                                      backend_id)
                importer = env.get_connector_unit(SaleOrderBatchImport)
                importer.run(filters)
            except FailedJobError as error:
                raise ValidationError("Error While importing sale order " +
                                      "\n" + str(error))

        return True
 def _after_export(self):
     backend = self.binding_record.backend_id
     session = ConnectorSession(self.env.cr,
                                self.env.uid,
                                context=self.env.context)
     env = get_environment(session, 'magento.attribute.set', backend.id)
     importer = env.get_connector_unit(AttributeSetImporter)
     importer.run(self.magento_id)
Beispiel #3
0
def export_invoice(session, model_name, record_id):
    """ Export a validated or paid invoice. """
    invoice = session.env[model_name].browse(record_id)
    backend_id = invoice.backend_id.id
    env = get_environment(session, model_name, backend_id)
    invoice_exporter = env.get_connector_unit(MagentoInvoiceExporter)
    result = invoice_exporter.run(record_id)
    return result
Beispiel #4
0
def partner_import_batch(session, model_name, backend_id, filters=None):
    """ Prepare the import of partners modified on Magento """
    if filters is None:
        filters = {}
    assert 'magento_website_id' in filters, (
        'Missing information about Magento Website')
    env = get_environment(session, 'res.partner', backend_id)
    importer = env.get_connector_unit(PartnerBatchImporter)
    importer.run(filters=filters)
 def unlink(self):
     session = ConnectorSession(self.env.cr, self.env.uid, self.env.context)
     if self.backend_id.image_delete_on_magento:
         env = get_environment(session, 'magento.product.image',
                               self.backend_id.id)
         image_deleter = env.get_connector_unit(ProductImageAdapter)
         image_deleter.delete(self.magento_id,
                              self.magento_product_id.magento_sku)
     res = super(MagentoProductImage, self).unlink()
     return res
    def import_sale_orders(self):
        session = ConnectorSession(self.env.cr,
                                   self.env.uid,
                                   context=self.env.context)
        import_start_time = datetime.now()
        for storeview in self:
            if storeview.no_sales_order_sync:
                _logger.debug(
                    "The storeview '%s' is active in Magento "
                    "but is configured not to import the "
                    "sales orders", storeview.name)
                continue
            backend_id = storeview.backend_id.id
            if storeview.import_orders_from_date:
                from_string = fields.Datetime.from_string
                from_date = from_string(storeview.import_orders_from_date)
            else:
                from_date = None

            filters = {
                'magento_storeview_id': storeview.magento_id,
                'from_date': from_date,
                'to_date': import_start_time
            }

            if storeview.backend_id.allow_so_import_on_fly:
                try:
                    env = get_environment(session, 'magento.sale.order',
                                          backend_id)
                    importer = env.get_connector_unit(SaleOrderBatchImport)
                    importer.run(filters)
                except Exception as error:
                    raise ValidationError(
                        "Error While Preparing batch for sale order" + "\n" +
                        str(error))
            else:
                sale_order_import_batch.delay(session,
                                              'magento.sale.order',
                                              backend_id,
                                              filters,
                                              priority=1)
        # Records from Magento are imported based on their `created_at`
        # date.  This date is set on Magento at the beginning of a
        # transaction, so if the import is run between the beginning and
        # the end of a transaction, the import of a record may be
        # missed.  That's why we add a small buffer back in time where
        # the eventually missed records will be retrieved.  This also
        # means that we'll have jobs that import twice the same records,
        # but this is not a big deal because the sales orders will be
        # imported the first time and the jobs will be skipped on the
        # subsequent imports
        return True
Beispiel #7
0
def export_picking_done(session, model_name, record_id):
    """ Export a complete or partial delivery order. """
    # with_tracking is True to keep a backward compatibility (jobs that
    # are pending and miss this argument will behave the same, but
    # it should be called with True only if the carrier_tracking_ref
    # is True when the job is created.
    picking = session.env[model_name].browse(record_id)
    backend_id = picking.backend_id.id
    env = get_environment(session, model_name, backend_id)
    picking_exporter = env.get_connector_unit(MagentoPickingExporter)
    res = picking_exporter.run(record_id)
#     if picking.erp_id and picking.erp_id.sale_id :
#         picking.erp_id.sale_id.get_magento_order_status()
    return res
    def test_connection(self):
        self.ensure_one()
        try:
            context = self._context
            session = ConnectorSession(self._cr, self._uid, context=context)
            backend_id = self.id
            mage_env = get_environment(session, "magento.website", backend_id)
            adapter = mage_env.get_connector_unit(WebsiteAdapter)
            result = adapter.search()
        except NetworkRetryableError as e:
            raise UserError('A network error caused the failure of the job: '
                            '%s' % e)
        except FailedJobError as e:
            raise UserError(
                'Given Credentials is incorrect, please provide correct Credentials.'
            )
        except Exception as e:
            raise UserError(
                "Connection Test Failed! Here is what we got instead:\n \n%s" %
                ustr(e))

        raise UserError(
            "Connection Test Succeeded! Everything seems properly set up!")
Beispiel #9
0
def link(session, job, backend_id_pos=2, magento_id_pos=3):
    """ Open a Magento URL on the admin page to view/edit the record
    related to the job.
    """
    binding_model = job.args[0]
    # shift one to the left because session is not in job.args
    backend_id = job.args[backend_id_pos - 1]
    magento_id = job.args[magento_id_pos - 1]
    env = get_environment(session, binding_model, backend_id)
    adapter = env.get_connector_unit(GenericAdapter)
    try:
        url = adapter.admin_url(magento_id)
    except ValueError:
        raise exceptions.Warning(
            _('No admin URL configured on the backend or '
              'no admin path is defined for this record.'))

    action = {
        'type': 'ir.actions.act_url',
        'target': 'new',
        'url': url,
    }
    return action
Beispiel #10
0
def export_delete_record(session, model_name, backend_id, magento_id):
    """ Delete a record on Magento """
    env = get_environment(session, model_name, backend_id)
    deleter = env.get_connector_unit(MagentoDeleter)
    return deleter.run(magento_id)
Beispiel #11
0
def export_record(session, model_name, binding_id, fields=None):
    """ Export a record on Magento """
    record = session.env[model_name].browse(binding_id)
    env = get_environment(session, model_name, record.backend_id.id)
    exporter = env.get_connector_unit(MagentoExporter)
    return exporter.run(binding_id, fields=fields)