'Check if each cost line its valuation lines sum to the correct amount
and if the overall total amount is correct also'

def _check_sum(self):

    prec_digits = self.env['decimal.precision'].precision_get('Account')
    for landed_cost in self:
        total_amount = sum(landed_cost.valuation_adjustment_lines.mapped('additional_landed_cost'))
        if (not (tools.float_compare(total_amount, landed_cost.amount_total, precision_digits=prec_digits) == 0)):
            return False
        val_to_cost_lines = defaultdict((lambda : 0.0))
        for val_line in landed_cost.valuation_adjustment_lines:
            val_to_cost_lines[val_line.cost_line_id] += val_line.additional_landed_cost
        if any(((tools.float_compare(cost_line.price_unit, val_amount, precision_digits=prec_digits) != 0) for (cost_line, val_amount) in val_to_cost_lines.iteritems())):
            return False
    return True
