def export_product_price(session, model_name, record_id, website_id=None):
    """ Export the price of a product. """
    product_bind = session.browse(model_name, record_id)
    backend_id = product_bind.backend_id.id
    env = get_environment(session, model_name, backend_id)
    price_exporter = env.get_connector_unit(ProductPriceExporter)
    return price_exporter.run(record_id, website_id=website_id)
Esempio n. 2
0
def export_product_configurable(session, model_name, record_id, fields=None):
    """ Export the configuration for the configurable product. """
    product = session.browse(model_name, record_id)
    backend_id = product.backend_id.id
    env = get_environment(session, model_name, backend_id)
    configurable_exporter = env.get_connector_unit(ProductConfigurableExporter)
    return configurable_exporter.run(record_id, fields)
Esempio n. 3
0
def export_product_price(session, model_name, record_id, website_id=None):
    """ Export the price of a product. """
    product_bind = session.browse(model_name, record_id)
    backend_id = product_bind.backend_id.id
    env = get_environment(session, model_name, backend_id)
    price_exporter = env.get_connector_unit(ProductPriceExporter)
    return price_exporter.run(record_id, website_id=website_id)
Esempio n. 4
0
def export_product_category_image(session, model_name, record_id, image_field):
    """ Export the image of a product category. """
    categ = session.browse(model_name, record_id)
    backend_id = categ.backend_id.id
    env = get_environment(session, model_name, backend_id)
    categ_image_exporter = env.get_connector_unit(ProductCategoryImageExporter)
    return categ_image_exporter.run(record_id, image_field)
Esempio n. 5
0
def import_record(session,
                  model_name,
                  backend_id,
                  magento_id,
                  force=False,
                  **kwargs):
    """ Import a record from Magento """
    env = get_environment(session, model_name, backend_id)
    importer = env.get_connector_unit(PricelistImport)
    importer.run(magento_id, force=force, **kwargs)
def export_dimension_value(session,
                           model_name,
                           magento_super_attr_id,
                           fields=None):
    """ Export dimension value. """
    mag_super_attr = session.browse(model_name, magento_super_attr_id)
    env = get_environment(session, model_name, mag_super_attr.backend_id.id)
    super_attribute_exporter = env.get_connector_unit(
        MagentoSuperAttributeExporter)
    return super_attribute_exporter._run(mag_super_attr.id)
Esempio n. 7
0
def pricelist_import_batch(session, model_name, backend_id, filters=None):
    """ Prepare the import of Pricelist modified on Magento """
    if filters is None:
        filters = {}
    assert 'magento_store_view_id' in filters, (
            'Missing information about Magento store view ID')
    session.context['store_view_id'] = filters.pop('store_view_id')
    session.context['magento_store_view_id'] = filters.get('magento_store_view_id')
    env = get_environment(session, model_name, backend_id)
    importer = env.get_connector_unit(PricelistBatchImport)
    importer.run(filters=filters)
def delay_magento_image_unlink(session, model_name, record_id):
    if session.context.get('connector_no_export'):
        return
    model = session.pool.get('magento.product.image')
    record = model.browse(session.cr,
                          session.uid,
                          record_id,
                          context=session.context)
    magento_keys = []
    env = get_environment(session, 'magento.product.image',
                          record.backend_id.id)
    binder = env.get_connector_unit(Binder)
    magento_keys.append(binder.to_backend(record_id))
    env = get_environment(session, 'magento.product.product',
                          record.backend_id.id)
    binder = env.get_connector_unit(Binder)
    magento_keys.append(
        binder.to_backend(record.openerp_id.product_id.id, wrap=True))
    if magento_keys:
        export_delete_record.delay(session, 'magento.product.image',
                                   record.backend_id.id, magento_keys)
Esempio n. 9
0
def pricelist_import_batch(session, model_name, backend_id, filters=None):
    """ Prepare the import of Pricelist modified on Magento """
    if filters is None:
        filters = {}
    assert 'magento_store_view_id' in filters, (
        'Missing information about Magento store view ID')
    session.context['store_view_id'] = filters.pop('store_view_id')
    session.context['magento_store_view_id'] = filters.get(
        'magento_store_view_id')
    env = get_environment(session, model_name, backend_id)
    importer = env.get_connector_unit(PricelistBatchImport)
    importer.run(filters=filters)
def delay_option_unlink(session, model_name, record_id):
    if session.context.get('connector_no_export'):
        return
    model = session.pool.get(model_name)
    record = model.browse(session.cr,
                          session.uid,
                          record_id,
                          context=session.context)

    option_env = get_environment(session, 'magento.attribute.option',
                                 record.backend_id.id)
    option_binder = option_env.get_connector_unit(Binder)

    mag_option_id = option_binder.to_backend(record.id)
    if mag_option_id:
        attr_env = get_environment(session, 'magento.product.attribute',
                                   record.backend_id.id)
        attr_binder = attr_env.get_connector_unit(Binder)

        mag_attr_id = attr_binder.to_backend(record.openerp_id.attribute_id.id,
                                             wrap=True)

        export_delete_record.delay(session, model_name, record.backend_id.id,
                                   (mag_attr_id, mag_option_id))
def partial_export(session, model_name, binding_id, vals):
    """ Partial export of a record on Magento """
    if model_name in ('magento.product.category', 'magento.product.product',
                      'magento.product.image'):
        if not session.search(model_name, [['id', '=', binding_id]]):
            return "The binding do not exist anymore, skip it"
    record = session.pool[model_name].browse(session.cr, session.uid,
                                             binding_id, session.context)
    backend_id = record.backend_id.id
    env = get_environment(session, model_name, backend_id)
    exporter = env.get_connector_unit(MagentoExporter)
    mapped_vals = exporter.mapper.map_record(record).values()
    partial_fields = session.pool[model_name]._get_mapped_partial_fields(
        session.cr, session.uid, session.context)
    partial_vals = {field: mapped_vals[field] for field in partial_fields}
    exporter.backend_adapter.write(record.magento_id, partial_vals)
    #sync date ?
    return record.write({'sync_state': 'done'},
                        context={'connector_no_export': True})
Esempio n. 12
0
def import_record(session, model_name, backend_id, magento_id, force=False, **kwargs):
    """ Import a record from Magento """
    env = get_environment(session, model_name, backend_id)
    importer = env.get_connector_unit(PricelistImport)
    importer.run(magento_id, force=force, **kwargs)
Esempio n. 13
0
def export_stock_levels(session, model_name, backend_id, product_id):
    env = get_environment(session, model_name, backend_id)
    inventory_exporter = env.get_connector_unit(ProductInventoryExport)
    return inventory_exporter.run(backend_id, product_id)
Esempio n. 14
0
def export_stock_levels(session, model_name, backend_id, product_id):
    env = get_environment(session, model_name, backend_id)
    inventory_exporter = env.get_connector_unit(ProductInventoryExport)
    return inventory_exporter.run(backend_id, product_id)