Comment 2 for bug 1003608

Revision history for this message
Kyle Waid (midwest) wrote :

I solve the error. 2 problems.

1. In account.py of base_sale_multichannels it uses an evaluation of type of tax == sale. However, it should be a list evaluation of either sale, all. If you have the correct tax defined but you choose all it will fail to match the tax and raise exception, also notably fails the order from import.

2. Magento tax precision is higher than OpenERP. The tax does not match exactly and can result in a few pennies discrepancy in the order. I sincerely hope this does not prevent reconciliation of orders. To solve this it should reconcile orders that are within 50 cents, or we should alter the tax amount field and allow greater precision as to match exactly the magento tax.

class account_tax_code(osv.osv):
    _inherit='account.tax'

    def get_tax_from_rate(self, cr, uid, rate, is_tax_included=False, context=None):
        #TODO improve, if tax are not correctly mapped the order should be in exception (integration with sale_execption)
        tax_ids = self.pool.get('account.tax').search(cr, uid, [('price_include', '=', is_tax_included),
                ('type_tax_use', '=', 'sale'), ('amount', '>=', rate - 0.001), ('amount', '<=', rate + 0.001)])
        if tax_ids and len(tax_ids) > 0:
            return tax_ids[0]
        else:
        #try to find a tax with less precision
            tax_ids = self.pool.get('account.tax').search(cr, uid, [('price_include', '=', is_tax_included),
                    ('type_tax_use', '=', 'sale'), ('amount', '>=', rate - 0.01), ('amount', '<=', rate + 0.01)])
            if tax_ids and len(tax_ids) > 0:
                return tax_ids[0]
        return False