Blog

How-To

OpenERP / Odoo Magento Connector: Product import with taxes

Many countries have different tax rates for different kinds of goods and services. For ecommerce applications at least two software components have to know the right taxes for products: the online shop software and the backing ERP system. Once you have configured your products with tax rates correctly in your Magento online web shop, you don’t want to configure them in OpenERP/Odoo again when you have imported them with the OpenERP Magento Connector.
The product import of the connector does not import the taxes because there is no easy mapping between taxes in Magento and the complex tax and accounting functionality of OpenERP/Odoo. But such a mapping can easily be defined in a custom add-on that extends the connector.

Based on the value of tax_class_id-field of the Magento product, we want to fill all four relevant income/expense account and purchase/sale tax rate fields in OpenERP/Odoo that are shown in the following image.

Tax rate and tax account configuration of a product in OpenERP

Tax and account configuration of a product in OpenERP

For a German company with 19% and 7% tax rates, the mapping could be as shown below. If you have not customized your OpenERP Magento Connector yet, you can find a good tutorial at the official homepage of the connector.

@magento_myversion
class CustomProductImportMapper(ProductImportMapper):
    _model_name = 'magento.product.product'
 
    @mapping
    def tax_class_id(self, record):
        value = record.get('tax_class_id', '-1')
        if value == '1':
            sess = self.session
            tax_ids = sess.search('account.tax',
                [('description', '=', '19% USt'), ('type_tax_use', '=', 'sale'), ('parent_id', '=', False)])
            supplier_tax_ids = sess.search('account.tax',
                [('description', '=', '19% VSt'), ('type_tax_use', '=', 'purchase'), ('parent_id', '=', False)])
            account_income = sess.search('account.account',
                [('code', '=', '440000')])
            account_expense = sess.search('account.account',
                [('code', '=', '540000')])
            result = {'taxes_id': [(6, 0, [tax_ids[0]])],
                      'supplier_taxes_id': [(6, 0, [supplier_tax_ids[0]])],
                      'property_account_income': account_income[0],
                      'property_account_expense': account_expense[0],
                     }
        elif value == '2':
            sess = self.session
            tax_ids = sess.search('account.tax',
                [('description', '=', '7% USt'), ('type_tax_use', '=', 'sale'), ('parent_id', '=', False)])
            supplier_tax_ids = sess.search('account.tax',
                [('description', '=', '7% VSt'), ('type_tax_use', '=', 'purchase'), ('parent_id', '=', False)])
            account_income = sess.search('account.account',
                [('code', '=', '430000')])
            account_expense = sess.search('account.account',
                [('code', '=', '530000')])
            result = {'taxes_id': [(6, 0, [tax_ids[0]])],
                      'supplier_taxes_id': [(6, 0, [supplier_tax_ids[0]])],
                      'property_account_income': account_income[0],
                      'property_account_expense': account_expense[0],
                     }
        else:
            result = {}
        return result
zurück zur Übersicht