You're right -- something's awry there.
It's possible that a more thorough solution would be to recalculate the tax based on the ratio of the deduction to the adjusted order total.
How about this:
Code:
function calculate_deductions($order_total) {
global $db, $order;
$od_amount = array();
$tax_address = zen_get_tax_locations();
$group_query = $db->Execute("select customers_group_pricing from " . TABLE_CUSTOMERS . " where customers_id = '" . (int)$_SESSION['customer_id'] . "'");
if ($group_query->fields['customers_group_pricing'] != '0') {
$group_discount = $db->Execute("select group_name, group_percentage from " . TABLE_GROUP_PRICING . " where
group_id = '" . (int)$group_query->fields['customers_group_pricing'] . "'");
$gift_vouchers = $_SESSION['cart']->gv_only();
$discount = ($order_total - $gift_vouchers) * $group_discount->fields['group_percentage'] / 100;
$od_amount['total'] = round($discount, 2);
/**
* when calculating the ratio add some insignificant values to stop divide by zero errors
*/
$ratio = ($od_amount['total'] + .000001)/($order_total - $gift_vouchers + .000001);
switch ($this->calculate_tax) {
case 'Standard':
reset($order->info['tax_groups']);
while (list($key, $value) = each($order->info['tax_groups'])) {
$tax_rate = zen_get_tax_rate_from_desc($key);
if ($tax_rate > 0) {
$od_amount[$key] = $tod_amount = round(($order->info['tax_groups'][$key]) * $ratio, 2) ;
$od_amount['tax'] += $tod_amount;
}
}
break;
case 'Credit Note':
reset($order->info['tax_groups']);
while (list($key, $value) = each($order->info['tax_groups'])) {
$tax_rate = zen_get_tax_rate_from_desc($order->info['tax_groups']);
if ($tax_rate > 0) {
$od_amount[$key] = $tod_amount = round(($order->info['tax_groups'][$key]) * $ratio, 2) ;
$od_amount['tax'] += $tod_amount;
}
}
break;
}
}
return $od_amount;
}